]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Hotkey selector widget. Save not implemented yet
[vlc] / modules / gui / qt4 / components / preferences_widgets.hpp
1 /*****************************************************************************
2  * preferences_widgets.hpp : Widgets for preferences panels
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef _INFOPANELS_H_
26 #define _INFOPANELS_H_
27 #include <vlc/vlc.h>
28 #include <QWidget>
29 #include <QTreeWidget>
30 #include <QLineEdit>
31 #include <QSpinBox>
32 #include <QDoubleSpinBox>
33 #include <QComboBox>
34 #include <QCheckBox>
35 #include <QVector>
36 #include <QDialog>
37
38 #include "ui/input_stats.h"
39 #include "qt4.hpp"
40 #include <assert.h>
41
42 class ConfigControl : public QObject
43 {
44     Q_OBJECT;
45 public:
46     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
47                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
48     {
49         widget = new QWidget( p );
50     }
51     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
52                             p_this (_p_this ), p_item( _p_conf )
53     {
54         widget = NULL;
55     }
56     virtual ~ConfigControl() {};
57     virtual int getType() = 0;
58     char * getName() { return  p_item->psz_name; }
59     QWidget *getWidget() { assert( widget ); return widget; }
60     bool isAdvanced() { return p_item->b_advanced; }
61     virtual void hide() { getWidget()->hide(); };
62     virtual void show() { getWidget()->show(); };
63
64     static ConfigControl * createControl( vlc_object_t*,
65                                           module_config_t*,QWidget* );
66     static ConfigControl * createControl( vlc_object_t*,
67                                           module_config_t*,QWidget*,
68                                           QGridLayout *, int& );
69     void doApply( intf_thread_t *);
70 protected:
71     vlc_object_t *p_this;
72     module_config_t *p_item;
73     QString _name;
74     QWidget *widget;
75     bool _advanced;
76 signals:
77     void Updated();
78 };
79
80 /*******************************************************
81  * Integer-based controls
82  *******************************************************/
83 class VIntConfigControl : public ConfigControl
84 {
85 public:
86     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
87             ConfigControl(a,b,c) {};
88     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
89                 ConfigControl(a,b) {};
90     virtual ~VIntConfigControl() {};
91     virtual int getValue() = 0;
92     virtual int getType() { return 1; }
93 };
94
95 class IntegerConfigControl : public VIntConfigControl
96 {
97 public:
98     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
99                           QGridLayout *, int& );
100     IntegerConfigControl( vlc_object_t *, module_config_t *,
101                           QLabel*, QSpinBox* );
102     virtual ~IntegerConfigControl() {};
103     virtual int getValue();
104     virtual void show() { spin->show(); label->show(); }
105     virtual void hide() { spin->hide(); label->hide(); }
106
107 protected:
108     QSpinBox *spin;
109
110 private:
111     QLabel *label;
112     void finish();
113 };
114
115 class IntegerRangeConfigControl : public IntegerConfigControl
116 {
117 public:
118     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
119                                QGridLayout *, int& );
120     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
121                                QLabel*, QSpinBox* );
122 private:
123     void finish();
124 };
125
126 class IntegerListConfigControl : public VIntConfigControl
127 {
128 public:
129     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
130                               bool, QGridLayout*, int& );
131     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
132                               QComboBox*, bool );
133     virtual ~IntegerListConfigControl() {};
134     virtual int getValue();
135     virtual void hide() { combo->hide(); label->hide(); }
136     virtual void show() { combo->show(); label->show(); }
137 private:
138     void finish( bool );
139     QLabel *label;
140     QComboBox *combo;
141 };
142
143 class BoolConfigControl : public VIntConfigControl
144 {
145 public:
146     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
147                        QGridLayout *, int& );
148     BoolConfigControl( vlc_object_t *, module_config_t *,
149                        QLabel *, QCheckBox*, bool );
150     virtual ~BoolConfigControl() {};
151     virtual int getValue();
152     virtual void show() { checkbox->show(); }
153     virtual void hide() { checkbox->hide(); }
154 private:
155     QCheckBox *checkbox;
156     void finish();
157 };
158
159 /*******************************************************
160  * Float-based controls
161  *******************************************************/
162 class VFloatConfigControl : public ConfigControl
163 {
164 public:
165     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
166                 ConfigControl(a,b,c) {};
167     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
168                 ConfigControl(a,b) {};
169     virtual ~VFloatConfigControl() {};
170     virtual float getValue() = 0;
171     virtual int getType() { return 2; }
172 };
173
174 class FloatConfigControl : public VFloatConfigControl
175 {
176 public:
177     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
178                         QGridLayout *, int& );
179     FloatConfigControl( vlc_object_t *, module_config_t *,
180                         QLabel*, QDoubleSpinBox* );
181     virtual ~FloatConfigControl() {};
182     virtual float getValue();
183     virtual void show() { spin->show(); label->show(); }
184     virtual void hide() { spin->hide(); label->hide(); }
185
186 protected:
187     QDoubleSpinBox *spin;
188
189 private:
190     QLabel *label;
191     void finish();
192 };
193
194 class FloatRangeConfigControl : public FloatConfigControl
195 {
196 public:
197     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
198                              QGridLayout *, int& );
199     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
200                              QLabel*, QDoubleSpinBox* );
201 private:
202     void finish();
203 };
204
205 /*******************************************************
206  * String-based controls
207  *******************************************************/
208 class VStringConfigControl : public ConfigControl
209 {
210 public:
211     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
212                 ConfigControl(a,b,c) {};
213     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
214                 ConfigControl(a,b) {};
215     virtual ~VStringConfigControl() {};
216     virtual QString getValue() = 0;
217     virtual int getType() { return 3; }
218 };
219
220 class StringConfigControl : public VStringConfigControl
221 {
222 public:
223     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
224                          QGridLayout *, int&,  bool pwd );
225     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
226                          QLineEdit*,  bool pwd );
227     virtual ~StringConfigControl() {};
228     virtual QString getValue() { return text->text(); };
229     virtual void show() { text->show(); label->show(); }
230     virtual void hide() { text->hide(); label->hide(); }
231 private:
232     void finish();
233     QLineEdit *text;
234     QLabel *label;
235 };
236
237 class ModuleConfigControl : public VStringConfigControl
238 {
239 public:
240     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
241                          QGridLayout*, int& );
242     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
243                          QComboBox*, bool );
244     virtual ~ModuleConfigControl() {};
245     virtual QString getValue();
246     virtual void hide() { combo->hide(); label->hide(); }
247     virtual void show() { combo->show(); label->show(); }
248 private:
249     void finish( bool );
250     QLabel *label;
251     QComboBox *combo;
252 };
253
254 class ModuleListConfigControl : public VStringConfigControl
255 {
256     Q_OBJECT;
257 public:
258     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
259                              bool, QGridLayout*, int& );
260 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
261 //                         QComboBox*, bool );
262     virtual ~ModuleListConfigControl();
263     virtual QString getValue();
264     virtual void hide();
265     virtual void show();
266 public slots:
267     void wakeUp_TheUserJustClickedOnSomething( int value );
268 private:
269     void finish( bool );
270     QVector<QCheckBox*> modules;
271     QLabel *label;
272     QLineEdit *text;
273 };
274
275 class StringListConfigControl : public VStringConfigControl
276 {
277 public:
278     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
279                              bool, QGridLayout*, int& );
280     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
281                              QComboBox*, bool );
282     virtual ~StringListConfigControl() {};
283     virtual QString getValue();
284     virtual void hide() { combo->hide(); label->hide(); }
285     virtual void show() { combo->show(); label->show(); }
286 private:
287     void finish( bool );
288     QLabel *label;
289     QComboBox *combo;
290 };
291 #if 0
292 struct ModuleCheckBox {
293     QCheckBox *checkbox;
294     QString module;
295 };
296
297 class ModuleListConfigControl : public ConfigControl
298 {
299 public:
300     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
301                          bycat );
302     virtual ~StringConfigControl();
303     virtual QString getValue();
304 private:
305     std::vector<ModuleCheckBox> checkboxes;
306     QLineEdit *text;
307 private slot:
308     void OnUpdate();
309 };
310 #endif
311
312 /**********************************************************************
313  * Key selector widget
314  **********************************************************************/
315 class KeyInputDialog : public QDialog
316 {
317 public:
318     KeyInputDialog( QList<module_config_t *> &, char * );
319     int keyValue;
320     bool conflicts;
321 private:
322     void keyPressEvent( QKeyEvent *);
323     QLabel *selected;
324     QLabel *warning;
325     char * keyToChange;
326     QList<module_config_t*> values;
327 };
328
329 class KeySelectorControl : public ConfigControl
330 {
331     Q_OBJECT;
332 public:
333     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
334                         QGridLayout*, int& );
335     virtual int getType() { return 4; }
336     virtual ~KeySelectorControl() {};
337     virtual void hide() { table->hide(); label->hide(); }
338     virtual void show() { table->show(); label->show(); }
339     void doApply();
340 private:
341     void finish();
342     QLabel *label;
343     QTreeWidget *table;
344     QList<module_config_t *> values;
345 private slots:
346     void selectKey( QTreeWidgetItem *);
347 };
348
349 #endif