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