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