]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4 : Simple Preferences. Add a slider widget to pref_widget, because it is nicer...
[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 #include <QLabel>
38
39 #include "qt4.hpp"
40 #include <assert.h>
41
42 class QGridLayout;
43
44 class ConfigControl : public QObject
45 {
46     Q_OBJECT;
47 public:
48     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
49                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
50     {
51         widget = new QWidget( p );
52     }
53     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
54                             p_this (_p_this ), p_item( _p_conf )
55     {
56         widget = NULL;
57     }
58     virtual ~ConfigControl() {};
59     virtual int getType() = 0;
60     const char * getName() { return  p_item->psz_name; }
61     QWidget *getWidget() { assert( widget ); return widget; }
62     bool isAdvanced() { return p_item->b_advanced; }
63     virtual void hide() { getWidget()->hide(); };
64     virtual void show() { getWidget()->show(); };
65
66     static ConfigControl * createControl( vlc_object_t*,
67                                           module_config_t*,QWidget* );
68     static ConfigControl * createControl( vlc_object_t*,
69                                           module_config_t*,QWidget*,
70                                           QGridLayout *, int& );
71     void doApply( intf_thread_t *);
72 protected:
73     vlc_object_t *p_this;
74     module_config_t *p_item;
75     QString _name;
76     QWidget *widget;
77     bool _advanced;
78 signals:
79     void Updated();
80 };
81
82 /*******************************************************
83  * Integer-based controls
84  *******************************************************/
85 class VIntConfigControl : public ConfigControl
86 {
87 public:
88     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
89             ConfigControl(a,b,c) {};
90     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
91                 ConfigControl(a,b) {};
92     virtual ~VIntConfigControl() {};
93     virtual int getValue() = 0;
94     virtual int getType() { return 1; }
95 };
96
97 class IntegerConfigControl : public VIntConfigControl
98 {
99 public:
100     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
101                           QGridLayout *, int& );
102     IntegerConfigControl( vlc_object_t *, module_config_t *,
103                           QLabel*, QSpinBox* );
104     IntegerConfigControl( vlc_object_t *, module_config_t *,
105                           QLabel*, QSlider* );
106     virtual ~IntegerConfigControl() {};
107     virtual int getValue();
108     virtual void show() { spin->show(); label->show(); }
109     virtual void hide() { spin->hide(); label->hide(); }
110
111 protected:
112     QSpinBox *spin;
113 private:
114     QLabel *label;
115     void finish();
116 };
117
118 class IntegerRangeConfigControl : public IntegerConfigControl
119 {
120 public:
121     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
122                                QGridLayout *, int& );
123     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
124                                QLabel*, QSpinBox* );
125 private:
126     void finish();
127 };
128
129 class IntegerRangeSliderConfigControl : public VIntConfigControl
130 {
131 public:
132     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
133                                 QLabel *, QSlider *, bool * );
134     virtual ~IntegerRangeSliderConfigControl() {};
135     virtual int getValue();
136 protected:
137          QSlider *slider;
138 private:
139          QLabel *label;
140          void finish();
141 };
142
143 class IntegerListConfigControl : public VIntConfigControl
144 {
145 public:
146     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
147                               bool, QGridLayout*, int& );
148     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
149                               QComboBox*, bool );
150     virtual ~IntegerListConfigControl() {};
151     virtual int getValue();
152     virtual void hide() { combo->hide(); label->hide(); }
153     virtual void show() { combo->show(); label->show(); }
154 private:
155     void finish( bool );
156     QLabel *label;
157     QComboBox *combo;
158 };
159
160 class BoolConfigControl : public VIntConfigControl
161 {
162 public:
163     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
164                        QGridLayout *, int& );
165     BoolConfigControl( vlc_object_t *, module_config_t *,
166                        QLabel *, QCheckBox*, bool );
167     virtual ~BoolConfigControl() {};
168     virtual int getValue();
169     virtual void show() { checkbox->show(); }
170     virtual void hide() { checkbox->hide(); }
171 private:
172     QCheckBox *checkbox;
173     void finish();
174 };
175
176 /*******************************************************
177  * Float-based controls
178  *******************************************************/
179 class VFloatConfigControl : public ConfigControl
180 {
181 public:
182     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
183                 ConfigControl(a,b,c) {};
184     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
185                 ConfigControl(a,b) {};
186     virtual ~VFloatConfigControl() {};
187     virtual float getValue() = 0;
188     virtual int getType() { return 2; }
189 };
190
191 class FloatConfigControl : public VFloatConfigControl
192 {
193 public:
194     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
195                         QGridLayout *, int& );
196     FloatConfigControl( vlc_object_t *, module_config_t *,
197                         QLabel*, QDoubleSpinBox* );
198     virtual ~FloatConfigControl() {};
199     virtual float getValue();
200     virtual void show() { spin->show(); label->show(); }
201     virtual void hide() { spin->hide(); label->hide(); }
202
203 protected:
204     QDoubleSpinBox *spin;
205
206 private:
207     QLabel *label;
208     void finish();
209 };
210
211 class FloatRangeConfigControl : public FloatConfigControl
212 {
213 public:
214     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
215                              QGridLayout *, int& );
216     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
217                              QLabel*, QDoubleSpinBox* );
218 private:
219     void finish();
220 };
221
222 /*******************************************************
223  * String-based controls
224  *******************************************************/
225 class VStringConfigControl : public ConfigControl
226 {
227 public:
228     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
229                 ConfigControl(a,b,c) {};
230     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
231                 ConfigControl(a,b) {};
232     virtual ~VStringConfigControl() {};
233     virtual QString getValue() = 0;
234     virtual int getType() { return 3; }
235 };
236
237 class StringConfigControl : public VStringConfigControl
238 {
239 public:
240     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
241                          QGridLayout *, int&,  bool pwd );
242     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
243                          QLineEdit*,  bool pwd );
244     virtual ~StringConfigControl() {};
245     virtual QString getValue() { return text->text(); };
246     virtual void show() { text->show(); label->show(); }
247     virtual void hide() { text->hide(); label->hide(); }
248 private:
249     void finish();
250     QLineEdit *text;
251     QLabel *label;
252 };
253
254 class ModuleConfigControl : public VStringConfigControl
255 {
256 public:
257     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
258                          QGridLayout*, int& );
259     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
260                          QComboBox*, bool );
261     virtual ~ModuleConfigControl() {};
262     virtual QString getValue();
263     virtual void hide() { combo->hide(); label->hide(); }
264     virtual void show() { combo->show(); label->show(); }
265 private:
266     void finish( bool );
267     QLabel *label;
268     QComboBox *combo;
269 };
270
271 class ModuleListConfigControl : public VStringConfigControl
272 {
273     Q_OBJECT;
274 public:
275     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
276                              bool, QGridLayout*, int& );
277 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
278 //                         QComboBox*, bool );
279     virtual ~ModuleListConfigControl();
280     virtual QString getValue();
281     virtual void hide();
282     virtual void show();
283 public slots:
284     void wakeUp_TheUserJustClickedOnSomething( int value );
285 private:
286     void finish( bool );
287     QVector<QCheckBox*> modules;
288     QLabel *label;
289     QLineEdit *text;
290 };
291
292 class StringListConfigControl : public VStringConfigControl
293 {
294 public:
295     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
296                              bool, QGridLayout*, int& );
297     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
298                              QComboBox*, bool );
299     virtual ~StringListConfigControl() {};
300     virtual QString getValue();
301     virtual void hide() { combo->hide(); label->hide(); }
302     virtual void show() { combo->show(); label->show(); }
303 private:
304     void finish( bool );
305     QLabel *label;
306     QComboBox *combo;
307 };
308 #if 0
309 struct ModuleCheckBox {
310     QCheckBox *checkbox;
311     QString module;
312 };
313
314 class ModuleListConfigControl : public ConfigControl
315 {
316 public:
317     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
318                          bycat );
319     virtual ~StringConfigControl();
320     virtual QString getValue();
321 private:
322     std::vector<ModuleCheckBox> checkboxes;
323     QLineEdit *text;
324 private slot:
325     void OnUpdate();
326 };
327 #endif
328
329 /**********************************************************************
330  * Key selector widget
331  **********************************************************************/
332 class KeyInputDialog : public QDialog
333 {
334 public:
335     KeyInputDialog( QList<module_config_t *> &, const char * );
336     int keyValue;
337     bool conflicts;
338 private:
339     void keyPressEvent( QKeyEvent *);
340     QLabel *selected;
341     QLabel *warning;
342     const char * keyToChange;
343     QList<module_config_t*> values;
344 };
345
346 class KeySelectorControl : public ConfigControl
347 {
348     Q_OBJECT;
349 public:
350     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
351                         QGridLayout*, int& );
352     virtual int getType() { return 4; }
353     virtual ~KeySelectorControl() {};
354     virtual void hide() { table->hide(); label->hide(); }
355     virtual void show() { table->show(); label->show(); }
356     void doApply();
357 private:
358     void finish();
359     QLabel *label;
360     QTreeWidget *table;
361     QList<module_config_t *> values;
362 private slots:
363     void selectKey( QTreeWidgetItem *);
364 };
365
366 #endif