]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4 - Complete preferences. Make ModuleList Clearer than it is now... Align SpinBox...
[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  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef _INFOPANELS_H_
27 #define _INFOPANELS_H_
28 #include <vlc/vlc.h>
29 #include <QWidget>
30 #include <QTreeWidget>
31 #include <QLineEdit>
32 #include <QSpinBox>
33 #include <QDoubleSpinBox>
34 #include <QComboBox>
35 #include <QCheckBox>
36 #include <QVector>
37 #include <QDialog>
38 #include <QLabel>
39 #include <QFile>
40 #include <QPushButton>
41 #include <QGroupBox>
42
43 #include "qt4.hpp"
44 #include <assert.h>
45
46 class QGridLayout;
47
48 class ConfigControl : public QObject
49 {
50     Q_OBJECT
51 public:
52     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
53                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
54     {
55         widget = new QWidget( p );
56     }
57     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
58                             p_this (_p_this ), p_item( _p_conf )
59     {
60         widget = NULL;
61     }
62     virtual ~ConfigControl() {};
63     virtual int getType() = 0;
64     const char * getName() { return  p_item->psz_name; }
65     QWidget *getWidget() { assert( widget ); return widget; }
66     bool isAdvanced() { return p_item->b_advanced; }
67     virtual void hide() { getWidget()->hide(); };
68     virtual void show() { getWidget()->show(); };
69
70     static ConfigControl * createControl( vlc_object_t*,
71                                           module_config_t*,QWidget* );
72     static ConfigControl * createControl( vlc_object_t*,
73                                           module_config_t*,QWidget*,
74                                           QGridLayout *, int& );
75     void doApply( intf_thread_t *);
76 protected:
77     vlc_object_t *p_this;
78     module_config_t *p_item;
79     QString _name;
80     QWidget *widget;
81     bool _advanced;
82 signals:
83     void Updated();
84 };
85
86 /*******************************************************
87  * Integer-based controls
88  *******************************************************/
89 class VIntConfigControl : public ConfigControl
90 {
91 Q_OBJECT
92 public:
93     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
94             ConfigControl(a,b,c) {};
95     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
96                 ConfigControl(a,b) {};
97     virtual ~VIntConfigControl() {};
98     virtual int getValue() = 0;
99     virtual int getType() { return 1; }
100 };
101
102 class IntegerConfigControl : public VIntConfigControl
103 {
104 Q_OBJECT
105 public:
106     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
107                           QGridLayout *, int& );
108     IntegerConfigControl( vlc_object_t *, module_config_t *,
109                           QLabel*, QSpinBox* );
110     IntegerConfigControl( vlc_object_t *, module_config_t *,
111                           QLabel*, QSlider* );
112     virtual ~IntegerConfigControl() {};
113     virtual int getValue();
114     virtual void show() { spin->show(); label->show(); }
115     virtual void hide() { spin->hide(); label->hide(); }
116
117 protected:
118     QSpinBox *spin;
119 private:
120     QLabel *label;
121     void finish();
122 };
123
124 class IntegerRangeConfigControl : public IntegerConfigControl
125 {
126 public:
127     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
128                                QGridLayout *, int& );
129     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
130                                QLabel*, QSpinBox* );
131 private:
132     void finish();
133 };
134
135 class IntegerRangeSliderConfigControl : public VIntConfigControl
136 {
137 public:
138     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
139                                 QLabel *, QSlider * );
140     virtual ~IntegerRangeSliderConfigControl() {};
141     virtual int getValue();
142 protected:
143          QSlider *slider;
144 private:
145          QLabel *label;
146          void finish();
147 };
148
149 class IntegerListConfigControl : public VIntConfigControl
150 {
151 public:
152     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
153                               bool, QGridLayout*, int& );
154     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
155                               QComboBox*, bool );
156     virtual ~IntegerListConfigControl() {};
157     virtual int getValue();
158     virtual void hide() { combo->hide(); label->hide(); }
159     virtual void show() { combo->show(); label->show(); }
160 private:
161     void finish( bool );
162     QLabel *label;
163     QComboBox *combo;
164 };
165
166 class BoolConfigControl : public VIntConfigControl
167 {
168 public:
169     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
170                        QGridLayout *, int& );
171     BoolConfigControl( vlc_object_t *, module_config_t *,
172                        QLabel *, QCheckBox*, bool );
173     virtual ~BoolConfigControl() {};
174     virtual int getValue();
175     virtual void show() { checkbox->show(); }
176     virtual void hide() { checkbox->hide(); }
177 private:
178     QCheckBox *checkbox;
179     void finish();
180 };
181
182 /*******************************************************
183  * Float-based controls
184  *******************************************************/
185 class VFloatConfigControl : public ConfigControl
186 {
187     Q_OBJECT
188 public:
189     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
190                 ConfigControl(a,b,c) {};
191     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
192                 ConfigControl(a,b) {};
193     virtual ~VFloatConfigControl() {};
194     virtual float getValue() = 0;
195     virtual int getType() { return 2; }
196 };
197
198 class FloatConfigControl : public VFloatConfigControl
199 {
200     Q_OBJECT
201 public:
202     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
203                         QGridLayout *, int& );
204     FloatConfigControl( vlc_object_t *, module_config_t *,
205                         QLabel*, QDoubleSpinBox* );
206     virtual ~FloatConfigControl() {};
207     virtual float getValue();
208     virtual void show() { spin->show(); label->show(); }
209     virtual void hide() { spin->hide(); label->hide(); }
210
211 protected:
212     QDoubleSpinBox *spin;
213
214 private:
215     QLabel *label;
216     void finish();
217 };
218
219 class FloatRangeConfigControl : public FloatConfigControl
220 {
221     Q_OBJECT
222 public:
223     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
224                              QGridLayout *, int& );
225     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
226                              QLabel*, QDoubleSpinBox* );
227 private:
228     void finish();
229 };
230
231 /*******************************************************
232  * String-based controls
233  *******************************************************/
234 class VStringConfigControl : public ConfigControl
235 {
236     Q_OBJECT
237 public:
238     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
239                 ConfigControl(a,b,c) {};
240     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
241                 ConfigControl(a,b) {};
242     virtual ~VStringConfigControl() {};
243     virtual QString getValue() = 0;
244     virtual int getType() { return 3; }
245 };
246
247 class StringConfigControl : public VStringConfigControl
248 {
249     Q_OBJECT
250 public:
251     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
252                          QGridLayout *, int&,  bool pwd );
253     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
254                          QLineEdit*,  bool pwd );
255     virtual ~StringConfigControl() {};
256     virtual QString getValue() { return text->text(); };
257     virtual void show() { text->show(); label->show(); }
258     virtual void hide() { text->hide(); label->hide(); }
259 private:
260     void finish();
261     QLineEdit *text;
262     QLabel *label;
263 };
264
265 class FileConfigControl : public VStringConfigControl
266 {
267     Q_OBJECT;
268 public:
269     FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
270                        QGridLayout *, int&, bool pwd );
271     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
272                        QLineEdit *, QPushButton *, bool pwd );
273     virtual ~FileConfigControl() {};
274     virtual QString getValue() { return text->text(); };
275     virtual void show() { text->show(); label->show(); browse->show(); }
276     virtual void hide() { text->hide(); label->hide(); browse->hide(); }
277 public slots:
278     virtual void updateField();
279 protected:
280     void finish();
281     QLineEdit *text;
282     QLabel *label;
283     QPushButton *browse;
284 };
285
286 class DirectoryConfigControl : public FileConfigControl
287 {
288     Q_OBJECT;
289 public:
290     DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
291                             QGridLayout *, int&, bool pwd );
292     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
293                             QLineEdit *, QPushButton *, bool pwd );
294     virtual ~DirectoryConfigControl() {};
295 public slots:
296     virtual void updateField();
297 };
298
299 class FontConfigControl : public FileConfigControl
300 {
301     Q_OBJECT;
302 public:
303     FontConfigControl( vlc_object_t *, module_config_t *, QWidget *,
304                        QGridLayout *, int&, bool pwd );
305     FontConfigControl( vlc_object_t *, module_config_t *, QLabel *,
306                        QLineEdit *, QPushButton *, bool pwd );
307     virtual ~FontConfigControl() {};
308 public slots:
309     virtual void updateField();
310 };
311
312 class ModuleConfigControl : public VStringConfigControl
313 {
314 public:
315     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
316                          QGridLayout*, int& );
317     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
318                          QComboBox*, bool );
319     virtual ~ModuleConfigControl() {};
320     virtual QString getValue();
321     virtual void hide() { combo->hide(); label->hide(); }
322     virtual void show() { combo->show(); label->show(); }
323 private:
324     void finish( bool );
325     QLabel *label;
326     QComboBox *combo;
327 };
328
329 class ModuleListConfigControl : public VStringConfigControl
330 {
331     Q_OBJECT;
332 public:
333     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
334                              bool, QGridLayout*, int& );
335 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
336 //                         QComboBox*, bool );
337     virtual ~ModuleListConfigControl();
338     virtual QString getValue();
339     virtual void hide();
340     virtual void show();
341 public slots:
342     void wakeUp_TheUserJustClickedOnSomething( int value );
343 private:
344     void finish( bool );
345     QVector<QCheckBox*> modules;
346     QGroupBox *groupBox;
347     QLineEdit *text;
348 };
349
350 class StringListConfigControl : public VStringConfigControl
351 {
352 public:
353     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
354                              bool, QGridLayout*, int& );
355     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
356                              QComboBox*, bool );
357     virtual ~StringListConfigControl() {};
358     virtual QString getValue();
359     virtual void hide() { combo->hide(); label->hide(); }
360     virtual void show() { combo->show(); label->show(); }
361 private:
362     void finish( bool );
363     QLabel *label;
364     QComboBox *combo;
365 };
366 #if 0
367 struct ModuleCheckBox {
368     QCheckBox *checkbox;
369     QString module;
370 };
371
372 class ModuleListConfigControl : public ConfigControl
373 {
374 public:
375     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
376                          bycat );
377     virtual ~StringConfigControl();
378     virtual QString getValue();
379 private:
380     std::vector<ModuleCheckBox> checkboxes;
381     QLineEdit *text;
382 private slot:
383     void OnUpdate();
384 };
385 #endif
386
387 /**********************************************************************
388  * Key selector widget
389  **********************************************************************/
390 class KeyInputDialog : public QDialog
391 {
392 public:
393     KeyInputDialog( QList<module_config_t *> &, const char * );
394     int keyValue;
395     bool conflicts;
396 private:
397     void checkForConflicts( int i_vlckey );
398     void keyPressEvent( QKeyEvent *);
399     void wheelEvent( QWheelEvent *);
400     QLabel *selected;
401     QLabel *warning;
402     const char * keyToChange;
403     QList<module_config_t*> values;
404 };
405
406 class KeySelectorControl : public ConfigControl
407 {
408     Q_OBJECT;
409 public:
410     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
411                         QGridLayout*, int& );
412     virtual int getType() { return 4; }
413     virtual ~KeySelectorControl() {};
414     virtual void hide() { table->hide(); label->hide(); }
415     virtual void show() { table->show(); label->show(); }
416     void doApply();
417 private:
418     void finish();
419     QLabel *label;
420     QTreeWidget *table;
421     QList<module_config_t *> values;
422 private slots:
423     void selectKey( QTreeWidgetItem *);
424 };
425
426 #endif