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