]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Preferences
[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 <QLineEdit>
30 #include <QSpinBox>
31 #include <QDoubleSpinBox>
32 #include <QComboBox>
33 #include <QCheckBox>
34 #include "ui/input_stats.h"
35 #include "qt4.hpp"
36 #include <assert.h>
37
38 class ConfigControl : public QObject
39 {
40     Q_OBJECT;
41 public:
42     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
43                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
44     {
45         widget = new QWidget( p );
46     }
47     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
48                             p_this (_p_this ), p_item( _p_conf )
49     {
50         widget = NULL;
51     }
52     virtual ~ConfigControl() {};
53     virtual int getType() = 0;
54     char * getName() { return  p_item->psz_name; }
55     QWidget *getWidget() { assert( widget ); return widget; }
56     bool isAdvanced() { return p_item->b_advanced; }
57     virtual void hide() { getWidget()->hide(); };
58     virtual void show() { getWidget()->show(); };
59
60     static ConfigControl * createControl( vlc_object_t*,
61                                           module_config_t*,QWidget* );
62     static ConfigControl * createControl( vlc_object_t*,
63                                           module_config_t*,QWidget*,
64                                           QGridLayout *, int);
65 protected:
66     vlc_object_t *p_this;
67     module_config_t *p_item;
68     QString _name;
69     QWidget *widget;
70     bool _advanced;
71 signals:
72     void Updated();
73 };
74
75 /*******************************************************
76  * Integer-based controls
77  *******************************************************/
78 class VIntConfigControl : public ConfigControl
79 {
80 public:
81     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
82             ConfigControl(a,b,c) {};
83     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
84                 ConfigControl(a,b) {};
85     virtual ~VIntConfigControl() {};
86     virtual int getValue() = 0;
87     virtual int getType() { return 1; }
88 };
89
90 class IntegerConfigControl : public VIntConfigControl
91 {
92 public:
93     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
94                           QGridLayout *, int );
95     IntegerConfigControl( vlc_object_t *, module_config_t *,
96                           QLabel*, QSpinBox* );
97     virtual ~IntegerConfigControl() {};
98     virtual int getValue();
99     virtual void show() { spin->show(); label->show(); }
100     virtual void hide() { spin->hide(); label->hide(); }
101
102 protected:
103     QSpinBox *spin;
104
105 private:
106     QLabel *label;
107     void finish();
108 };
109
110 class IntegerRangeConfigControl : public IntegerConfigControl
111 {
112 public:
113     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
114                                QGridLayout *, int );
115     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
116                                QLabel*, QSpinBox* );
117 private:
118     void finish();
119 };
120
121 class IntegerListConfigControl : public VIntConfigControl
122 {
123 public:
124     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
125                               bool, QGridLayout*, int );
126     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
127                               QComboBox*, bool );
128     virtual ~IntegerListConfigControl() {};
129     virtual int getValue();
130     virtual void hide() { combo->hide(); label->hide(); }
131     virtual void show() { combo->show(); label->show(); }
132 private:
133     void finish( bool );
134     QLabel *label;
135     QComboBox *combo;
136 };
137
138 class BoolConfigControl : public VIntConfigControl
139 {
140 public:
141     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
142                        QGridLayout *, int );
143     BoolConfigControl( vlc_object_t *, module_config_t *,
144                        QLabel *, QCheckBox*, bool );
145     virtual ~BoolConfigControl() {};
146     virtual int getValue();
147     virtual void show() { checkbox->show(); }
148     virtual void hide() { checkbox->hide(); }
149 private:
150     QCheckBox *checkbox;
151     void finish();
152 };
153
154 /*******************************************************
155  * Float-based controls
156  *******************************************************/
157 class VFloatConfigControl : public ConfigControl
158 {
159 public:
160     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
161                 ConfigControl(a,b,c) {};
162     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
163                 ConfigControl(a,b) {};
164     virtual ~VFloatConfigControl() {};
165     virtual float getValue() = 0;
166     virtual int getType() { return 2; }
167 };
168
169 class FloatConfigControl : public VFloatConfigControl
170 {
171 public:
172     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
173                         QGridLayout *, int );
174     FloatConfigControl( vlc_object_t *, module_config_t *,
175                         QLabel*, QDoubleSpinBox* );
176     virtual ~FloatConfigControl() {};
177     virtual float getValue();
178     virtual void show() { spin->show(); label->show(); }
179     virtual void hide() { spin->hide(); label->hide(); }
180
181 protected:
182     QDoubleSpinBox *spin;
183
184 private:
185     QLabel *label;
186     void finish();
187 };
188
189 class FloatRangeConfigControl : public FloatConfigControl
190 {
191 public:
192     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
193                              QGridLayout *, int );
194     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
195                              QLabel*, QDoubleSpinBox* );
196 private:
197     void finish();
198 };
199 #if 0
200 class FloatConfigControl : public VFloatConfigControl
201 {
202 public:
203     FloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
204                 ConfigControl(a,b,c) {};
205     virtual ~FloatConfigControl() {};
206     virtual float getValue();
207 private:
208     QDoubleSpinBox *spin;
209 };
210 #endif
211
212 /*******************************************************
213  * String-based controls
214  *******************************************************/
215 class VStringConfigControl : public ConfigControl
216 {
217 public:
218     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
219                 ConfigControl(a,b,c) {};
220     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
221                 ConfigControl(a,b) {};
222     virtual ~VStringConfigControl() {};
223     virtual QString getValue() = 0;
224     virtual int getType() { return 3; }
225 };
226
227 class StringConfigControl : public VStringConfigControl
228 {
229 public:
230     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
231                          QGridLayout *, int,  bool pwd );
232     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
233                          QLineEdit*,  bool pwd );
234     virtual ~StringConfigControl() {};
235     virtual QString getValue() { return text->text(); };
236     virtual void show() { text->show(); label->show(); }
237     virtual void hide() { text->hide(); label->hide(); }
238 private:
239     void finish();
240     QLineEdit *text;
241     QLabel *label;
242 };
243
244 class ModuleConfigControl : public VStringConfigControl
245 {
246 public:
247     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
248                          QGridLayout*, int );
249     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
250                          QComboBox*, bool );
251     virtual ~ModuleConfigControl() {};
252     virtual QString getValue();
253     virtual void hide() { combo->hide(); label->hide(); }
254     virtual void show() { combo->show(); label->show(); }
255 private:
256     void finish( bool );
257     QLabel *label;
258     QComboBox *combo;
259 };
260
261 class StringListConfigControl : public VStringConfigControl
262 {
263 public:
264     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
265                              bool, QGridLayout*, int );
266     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
267                              QComboBox*, bool );
268     virtual ~StringListConfigControl() {};
269     virtual QString getValue();
270     virtual void hide() { combo->hide(); label->hide(); }
271     virtual void show() { combo->show(); label->show(); }
272 private:
273     void finish( bool );
274     QLabel *label;
275     QComboBox *combo;
276 };
277 #if 0
278 struct ModuleCheckBox {
279     QCheckBox *checkbox;
280     QString module;
281 };
282
283 class ModuleListConfigControl : public ConfigControl
284 {
285 public:
286     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
287                          bycat );
288     virtual ~StringConfigControl();
289     virtual QString getValue();
290 private:
291     std::vector<ModuleCheckBox> checkboxes;
292     QLineEdit *text;
293 private slot:
294     void OnUpdate();
295 };
296 #endif
297
298 #endif