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