]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4 - Remove QFontDialog Dependency... We don't have some CONFIG_ITEM_FONT yet.....
[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 <vlc/vlc.h>
34
35 #include "qt4.hpp"
36 #include <assert.h>
37
38 #include <QWidget>
39
40 #include <QCheckBox>
41 #include <QComboBox>
42 #include <QLineEdit>
43 #include <QTreeWidget>
44 #include <QSpinBox>
45 #include <QLabel>
46 #include <QDoubleSpinBox>
47 #include <QPushButton>
48 #include <QVector>
49 #include <QDialog>
50
51
52 class QFile;
53 class QTreeWidget;
54 class QTreeWidgetItem;
55 class QGroupBox;
56 class QGridLayout;
57 class QDialogButtonBox;
58 class QVBoxLayout;
59
60 class ConfigControl : public QObject
61 {
62     Q_OBJECT
63 public:
64     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
65                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
66     {
67         widget = new QWidget( p );
68     }
69     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
70                             p_this (_p_this ), p_item( _p_conf )
71     {
72         widget = NULL;
73     }
74     virtual ~ConfigControl() {};
75     virtual int getType() = 0;
76     const char * getName() { return  p_item->psz_name; }
77     QWidget *getWidget() { assert( widget ); return widget; }
78     bool isAdvanced() { return p_item->b_advanced; }
79     virtual void hide() { getWidget()->hide(); };
80     virtual void show() { getWidget()->show(); };
81
82     static ConfigControl * createControl( vlc_object_t*,
83                                           module_config_t*,QWidget* );
84     static ConfigControl * createControl( vlc_object_t*,
85                                           module_config_t*,QWidget*,
86                                           QGridLayout *, int& );
87     void doApply( intf_thread_t *);
88 protected:
89     vlc_object_t *p_this;
90     module_config_t *p_item;
91     QString _name;
92     QWidget *widget;
93     bool _advanced;
94 #if 0
95 /* You shouldn't use that now..*/
96 signals:
97     void Updated();
98 #endif
99 };
100
101 /*******************************************************
102  * Integer-based controls
103  *******************************************************/
104 class VIntConfigControl : public ConfigControl
105 {
106 Q_OBJECT
107 public:
108     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
109             ConfigControl(a,b,c) {};
110     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
111                 ConfigControl(a,b) {};
112     virtual ~VIntConfigControl() {};
113     virtual int getValue() = 0;
114     virtual int getType() { return CONFIG_ITEM_INTEGER; }
115 };
116
117 class IntegerConfigControl : public VIntConfigControl
118 {
119 Q_OBJECT
120 public:
121     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
122                           QGridLayout *, int& );
123     IntegerConfigControl( vlc_object_t *, module_config_t *,
124                           QLabel*, QSpinBox* );
125     IntegerConfigControl( vlc_object_t *, module_config_t *,
126                           QLabel*, QSlider* );
127     virtual ~IntegerConfigControl() {};
128     virtual int getValue();
129     virtual void show() { spin->show(); if( label ) label->show(); }
130     virtual void hide() { spin->hide(); if( label ) label->hide(); }
131
132 protected:
133     QSpinBox *spin;
134 private:
135     QLabel *label;
136     void finish();
137 };
138
139 class IntegerRangeConfigControl : public IntegerConfigControl
140 {
141 public:
142     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
143                                QGridLayout *, int& );
144     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
145                                QLabel*, QSpinBox* );
146 private:
147     void finish();
148 };
149
150 class IntegerRangeSliderConfigControl : public VIntConfigControl
151 {
152 public:
153     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
154                                 QLabel *, QSlider * );
155     virtual ~IntegerRangeSliderConfigControl() {};
156     virtual int getValue();
157 protected:
158          QSlider *slider;
159 private:
160          QLabel *label;
161          void finish();
162 };
163
164 class IntegerListConfigControl : public VIntConfigControl
165 {
166 public:
167     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
168                               bool, QGridLayout*, int& );
169     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
170                               QComboBox*, bool );
171     virtual ~IntegerListConfigControl() {};
172     virtual int getValue();
173     virtual void hide() { combo->hide(); if( label ) label->hide(); }
174     virtual void show() { combo->show(); if( label ) label->show(); }
175 private:
176     void finish( bool );
177     QLabel *label;
178     QComboBox *combo;
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&, bool pwd );
287     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
288                        QLineEdit *, QPushButton *, bool pwd );
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&, bool pwd );
308     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
309                             QLineEdit *, QPushButton *, bool pwd );
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 public:
356     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
357                              bool, QGridLayout*, int& );
358 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
359 //                         QComboBox*, bool );
360     virtual ~ModuleListConfigControl();
361     virtual QString getValue();
362     virtual void hide();
363     virtual void show();
364 public slots:
365     void onUpdate( int value );
366 private:
367     void finish( bool );
368     QVector<checkBoxListItem*> modules;
369     QGroupBox *groupBox;
370     QLineEdit *text;
371 };
372
373 class StringListConfigControl : public VStringConfigControl
374 {
375     Q_OBJECT;
376 public:
377     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
378                              bool, QGridLayout*, int& );
379     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
380                              QComboBox*, bool );
381     virtual ~StringListConfigControl() {};
382     virtual QString getValue();
383     virtual void hide() { combo->hide(); if( label ) label->hide(); }
384     virtual void show() { combo->show(); if( label ) label->show(); }
385         QComboBox *combo;
386 private:
387     void finish( bool );
388     QLabel *label;
389 private slots:
390     void actionRequested( int );
391
392 };
393
394 void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
395                         QComboBox *combo, QWidget *parent = 0 );
396
397 #if 0
398 struct ModuleCheckBox {
399     QCheckBox *checkbox;
400     QString module;
401 };
402
403 class ModuleListConfigControl : public ConfigControl
404 {
405 public:
406     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
407                          bycat );
408     virtual ~StringConfigControl();
409     virtual QString getValue();
410 private:
411     std::vector<ModuleCheckBox> checkboxes;
412     QLineEdit *text;
413 private slot:
414     void OnUpdate();
415 };
416 #endif
417
418 /**********************************************************************
419  * Key selector widget
420  **********************************************************************/
421 class KeyShortcutEdit: public QLineEdit
422 {
423     Q_OBJECT
424 public:
425     void setValue( int _value ){ value = _value; }
426     int getValue(){ return value; }
427 private:
428     int value;
429     virtual void mousePressEvent( QMouseEvent *event );
430 signals:
431     void pressed();
432 };
433
434 class KeySelectorControl : public ConfigControl
435 {
436     Q_OBJECT;
437 public:
438     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
439                         QGridLayout*, int& );
440     virtual int getType() { return CONFIG_ITEM_KEY; }
441     virtual ~KeySelectorControl() {};
442     virtual void hide() { table->hide(); if( label ) label->hide(); }
443     virtual void show() { table->show(); if( label ) label->show(); }
444     void doApply();
445 private:
446     void finish();
447     QLabel *label;
448     QTreeWidget *table;
449     KeyShortcutEdit *shortcutValue;
450     QList<module_config_t *> values;
451 private slots:
452     void setTheKey();
453     void selectKey( QTreeWidgetItem * = NULL );
454     void select1Key( QTreeWidgetItem *);
455 };
456
457 class KeyInputDialog : public QDialog
458 {
459 public:
460     KeyInputDialog( QTreeWidget *, QString, QWidget * );
461     int keyValue;
462     bool conflicts;
463 private:
464     QTreeWidget *table;
465     void checkForConflicts( int i_vlckey );
466     void keyPressEvent( QKeyEvent *);
467     void wheelEvent( QWheelEvent *);
468     QLabel *selected;
469     QVBoxLayout *vLayout;
470     QDialogButtonBox *buttonBox;
471 };
472 #endif