]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4: use config_GetPszChoices() for module items
[vlc] / modules / gui / qt4 / components / preferences_widgets.hpp
1 /*****************************************************************************
2  * preferences_widgets.hpp : Widgets for preferences panels
3  ****************************************************************************
4  * Copyright (C) 2006-2011 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 _PREFERENCESWIDGETS_H_
27 #define _PREFERENCESWIDGETS_H_
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include "qt4.hpp"
34 #include <assert.h>
35
36 #include <QWidget>
37
38 #include <QCheckBox>
39 #include <QComboBox>
40 #include <QLineEdit>
41 #include <QTreeWidget>
42 #include <QSpinBox>
43 #include <QLabel>
44 #include <QDoubleSpinBox>
45 #include <QPushButton>
46 #include <QDialog>
47 #include <QFontComboBox>
48
49 class QTreeWidget;
50 class QTreeWidgetItem;
51 class QGroupBox;
52 class QGridLayout;
53 class QDialogButtonBox;
54 class QVBoxLayout;
55 class QBoxLayout;
56 class SearchLineEdit;
57
58 /*******************************************************
59  * Simple widgets
60  *******************************************************/
61
62 class InterfacePreviewWidget : public QLabel
63 {
64     Q_OBJECT
65 public:
66     InterfacePreviewWidget( QWidget * );
67     enum enum_style {
68                  COMPLETE, // aka MPC
69                  MINIMAL,  // aka WMP12 minimal
70                  SKINS };
71 public slots:
72     void setPreview( enum_style );
73     void setNormalPreview( bool b_minimal );
74 };
75
76 /*******************************************************
77  * Variable controls
78  *******************************************************/
79
80 class ConfigControl : public QObject
81 {
82     Q_OBJECT
83 public:
84     virtual int getType() const = 0;
85     const char * getName() const { return  p_item->psz_name; }
86     bool isAdvanced() const { return p_item->b_advanced; }
87     void hide() { changeVisibility( false ); }
88     void show() { changeVisibility( true ); }
89     /* ConfigControl factory */
90     static ConfigControl * createControl( vlc_object_t*,
91                                           module_config_t*,QWidget*,
92                                           QGridLayout *, int line = 0 );
93     /* Inserts control into another layout block, using a sublayout */
94     void insertInto( QBoxLayout * );
95     /* Inserts control into an existing grid layout */
96     void insertIntoExistingGrid( QGridLayout*, int );
97     virtual void doApply() = 0;
98 protected:
99     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
100                             p_this (_p_this ), p_item( _p_conf ) {}
101     virtual void changeVisibility( bool b ) { Q_UNUSED(b); };
102     vlc_object_t *p_this;
103     module_config_t *p_item;
104     virtual void fillGrid( QGridLayout*, int ) {};
105 signals:
106     void changed();
107 #if 0
108 /* You shouldn't use that now..*/
109     void Updated();
110 #endif
111 };
112
113 /*******************************************************
114  * Integer-based controls
115  *******************************************************/
116 class VIntConfigControl : public ConfigControl
117 {
118 Q_OBJECT
119 public:
120     virtual int getValue() const = 0;
121     virtual int getType() const;
122     virtual void doApply();
123 protected:
124     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
125                 ConfigControl(a,b) {};
126 };
127
128 class IntegerConfigControl : public VIntConfigControl
129 {
130 Q_OBJECT
131 public:
132     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget * );
133     IntegerConfigControl( vlc_object_t *, module_config_t *,
134                           QLabel*, QSpinBox* );
135     virtual int getValue() const;
136 protected:
137     QSpinBox *spin;
138     virtual void changeVisibility( bool b )
139     {
140         spin->setVisible( b );
141         if ( label ) label->setVisible( b );
142     }
143     virtual void fillGrid( QGridLayout*, int );
144 private:
145     QLabel *label;
146     void finish();
147 };
148
149 class IntegerRangeConfigControl : public IntegerConfigControl
150 {
151 public:
152     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget * );
153     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
154                                QLabel*, QSpinBox* );
155     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
156                                QLabel*, QSlider* );
157 private:
158     void finish();
159 };
160
161 class IntegerRangeSliderConfigControl : public VIntConfigControl
162 {
163 public:
164     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
165                                 QLabel *, QSlider * );
166     virtual int getValue() const;
167 protected:
168     QSlider *slider;
169     virtual void changeVisibility( bool b )
170     {
171         slider->setVisible( b );
172         if ( label ) label->setVisible( b );
173     }
174 private:
175     QLabel *label;
176     void finish();
177 };
178
179 class IntegerListConfigControl : public VIntConfigControl
180 {
181 Q_OBJECT
182 public:
183     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool );
184     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
185                               QComboBox*, bool );
186     virtual int getValue() const;
187 protected:
188     virtual void changeVisibility( bool b )
189     {
190         combo->setVisible( b );
191         if ( label ) label->setVisible( b );
192     }
193     virtual void fillGrid( QGridLayout*, int );
194 private:
195     void finish(module_config_t * );
196     QLabel *label;
197     QComboBox *combo;
198     QList<QPushButton *> buttons;
199 };
200
201 class BoolConfigControl : public VIntConfigControl
202 {
203 public:
204     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget * );
205     BoolConfigControl( vlc_object_t *, module_config_t *,
206                        QLabel *, QAbstractButton* );
207     virtual int getValue() const;
208     virtual int getType() const;
209 protected:
210     virtual void changeVisibility( bool b )
211     {
212         checkbox->setVisible( b );
213     }
214     virtual void fillGrid( QGridLayout*, int );
215 private:
216     QAbstractButton *checkbox;
217     void finish();
218 };
219
220 class ColorConfigControl : public VIntConfigControl
221 {
222 Q_OBJECT
223 public:
224     ColorConfigControl( vlc_object_t *, module_config_t *, QWidget * );
225     ColorConfigControl( vlc_object_t *, module_config_t *,
226                         QLabel *, QAbstractButton* );
227     virtual ~ColorConfigControl() { delete color_px; }
228     virtual int getValue() const;
229 protected:
230     virtual void changeVisibility( bool b )
231     {
232         color_but->setVisible( b );
233         if ( label ) label->setVisible( b );
234     }
235     virtual void fillGrid( QGridLayout*, int );
236 private:
237     QLabel *label;
238     QAbstractButton *color_but;
239     QPixmap *color_px;
240     int i_color;
241     void finish();
242 private slots:
243     void selectColor();
244 };
245
246 /*******************************************************
247  * Float-based controls
248  *******************************************************/
249 class VFloatConfigControl : public ConfigControl
250 {
251     Q_OBJECT
252 public:
253     virtual float getValue() const = 0;
254     virtual int getType() const;
255     virtual void doApply();
256 protected:
257     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
258                 ConfigControl(a,b) {};
259 };
260
261 class FloatConfigControl : public VFloatConfigControl
262 {
263     Q_OBJECT
264 public:
265     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget * );
266     FloatConfigControl( vlc_object_t *, module_config_t *,
267                         QLabel*, QDoubleSpinBox* );
268     virtual float getValue() const;
269
270 protected:
271     virtual void changeVisibility( bool b )
272     {
273         spin->setVisible( b );
274         if ( label ) label->setVisible( b );
275     }
276     virtual void fillGrid( QGridLayout*, int );
277     QDoubleSpinBox *spin;
278
279 private:
280     QLabel *label;
281     void finish();
282 };
283
284 class FloatRangeConfigControl : public FloatConfigControl
285 {
286     Q_OBJECT
287 public:
288     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget * );
289     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
290                              QLabel*, QDoubleSpinBox* );
291 private:
292     void finish();
293 };
294
295 /*******************************************************
296  * String-based controls
297  *******************************************************/
298 class VStringConfigControl : public ConfigControl
299 {
300     Q_OBJECT
301 public:
302     virtual QString getValue() const = 0;
303     virtual int getType() const;
304     virtual void doApply();
305 protected:
306     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
307                 ConfigControl(a,b) {};
308 };
309
310 class StringConfigControl : public VStringConfigControl
311 {
312     Q_OBJECT
313 public:
314     StringConfigControl( vlc_object_t *, module_config_t *,
315                          QWidget *, bool pwd );
316     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
317                          QLineEdit*,  bool pwd );
318     virtual QString getValue() const { return text->text(); };
319 protected:
320     virtual void changeVisibility( bool b )
321     {
322         text->setVisible( b );
323         if ( label ) label->setVisible( b );
324     }
325     virtual void fillGrid( QGridLayout*, int );
326 private:
327     void finish();
328     QLineEdit *text;
329     QLabel *label;
330 };
331
332 class FileConfigControl : public VStringConfigControl
333 {
334     Q_OBJECT
335 public:
336     FileConfigControl( vlc_object_t *, module_config_t *, QWidget * );
337     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
338                        QLineEdit *, QPushButton * );
339     virtual QString getValue() const { return text->text(); };
340 public slots:
341     virtual void updateField();
342 protected:
343     virtual void changeVisibility( bool b )
344     {
345         text->setVisible( b );
346         browse->setVisible( b );
347         if ( label ) label->setVisible( b );
348     }
349     virtual void fillGrid( QGridLayout*, int );
350     void finish();
351     QLineEdit *text;
352     QLabel *label;
353     QPushButton *browse;
354 };
355
356 class DirectoryConfigControl : public FileConfigControl
357 {
358     Q_OBJECT
359 public:
360     DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget * );
361     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
362                             QLineEdit *, QPushButton * );
363 public slots:
364     virtual void updateField();
365 };
366
367 class FontConfigControl : public VStringConfigControl
368 {
369     Q_OBJECT
370 public:
371     FontConfigControl( vlc_object_t *, module_config_t *, QWidget * );
372     FontConfigControl( vlc_object_t *, module_config_t *, QLabel *,
373                        QFontComboBox *);
374     virtual QString getValue() const { return font->currentFont().family(); }
375 protected:
376     virtual void changeVisibility( bool b )
377     {
378         font->setVisible( b );
379         if ( label ) label->setVisible( b );
380     }
381     virtual void fillGrid( QGridLayout*, int );
382     QLabel *label;
383     QFontComboBox *font;
384 };
385
386 class ModuleConfigControl : public VStringConfigControl
387 {
388 public:
389     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget * );
390     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
391                          QComboBox* );
392     virtual QString getValue() const;
393 protected:
394     virtual void changeVisibility( bool b )
395     {
396         combo->setVisible( b );
397         if ( label ) label->setVisible( b );
398     }
399     virtual void fillGrid( QGridLayout*, int );
400 private:
401     void finish( );
402     QLabel *label;
403     QComboBox *combo;
404 };
405
406 struct checkBoxListItem {
407     QCheckBox *checkBox;
408     char *psz_module;
409 };
410
411 class ModuleListConfigControl : public VStringConfigControl
412 {
413     Q_OBJECT
414     friend class ConfigControl;
415 public:
416     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool );
417 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
418 //                         QComboBox*, bool );
419     virtual ~ModuleListConfigControl();
420     virtual QString getValue() const;
421 public slots:
422     void onUpdate();
423 protected:
424     virtual void changeVisibility( bool );
425     virtual void fillGrid( QGridLayout*, int );
426 private:
427     void finish( bool );
428     void checkbox_lists(module_t*);
429     void checkbox_lists( QString, QString, const char* );
430     QList<checkBoxListItem*> modules;
431     QGroupBox *groupBox;
432     QLineEdit *text;
433 };
434
435 class StringListConfigControl : public VStringConfigControl
436 {
437     Q_OBJECT
438 public:
439     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget * );
440     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
441                              QComboBox*, bool );
442     virtual QString getValue() const;
443 protected:
444     virtual void changeVisibility( bool b )
445     {
446         combo->setVisible( b );
447         if ( label ) label->setVisible( b );
448     }
449     virtual void fillGrid( QGridLayout*, int );
450     QComboBox *combo;
451 private:
452     void finish(module_config_t * );
453     QLabel *label;
454     QList<QPushButton *> buttons;
455 private slots:
456     void comboIndexChanged( int );
457 };
458
459 void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
460                         QComboBox *combo );
461
462 #if 0
463 struct ModuleCheckBox {
464     QCheckBox *checkbox;
465     QString module;
466 };
467
468 class ModuleListConfigControl : public ConfigControl
469 {
470 public:
471     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
472                          bycat );
473     virtual ~StringConfigControl();
474     virtual QString getValue();
475 private:
476     QVector<ModuleCheckBox> checkboxes;
477     QLineEdit *text;
478 private slot:
479     void OnUpdate();
480 };
481 #endif
482
483 /**********************************************************************
484  * Key selector widget
485  **********************************************************************/
486 class KeySelectorControl : public ConfigControl
487 {
488     Q_OBJECT
489 public:
490     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget * );
491     virtual int getType() const;
492     virtual void doApply();
493 protected:
494     virtual bool eventFilter( QObject *, QEvent * );
495     virtual void changeVisibility( bool b )
496     {
497         table->setVisible( b );
498         if ( label ) label->setVisible( b );
499     }
500     virtual void fillGrid( QGridLayout*, int );
501 private:
502     void finish();
503     QLabel *label;
504     QLabel *searchLabel;
505     SearchLineEdit *actionSearch;
506     QTreeWidget *table;
507     QList<module_config_t *> values;
508 private slots:
509     void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
510     void filter( const QString & );
511 };
512
513 class KeyInputDialog : public QDialog
514 {
515 public:
516     KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
517     int keyValue;
518     bool conflicts;
519
520 private:
521     QTreeWidget *table;
522     QLabel *selected, *warning;
523     QDialogButtonBox *buttonBox;
524
525     void checkForConflicts( int i_vlckey );
526     void keyPressEvent( QKeyEvent *);
527     void wheelEvent( QWheelEvent *);
528     bool b_global;
529 };
530 #endif