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