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