]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
QT4: enable fontdialog for choosing freetype-font family
[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 class FontConfigControl : public FileConfigControl
333 {
334     Q_OBJECT;
335 public:
336     FontConfigControl( vlc_object_t *, module_config_t *, QWidget *,
337                        QGridLayout *, int&);
338     FontConfigControl( vlc_object_t *, module_config_t *, QLabel *,
339                        QLineEdit *, QPushButton *);
340     virtual ~FontConfigControl() {};
341 public slots:
342     virtual void updateField();
343 };
344
345 class ModuleConfigControl : public VStringConfigControl
346 {
347 public:
348     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
349                          QGridLayout*, int& );
350     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
351                          QComboBox*, bool );
352     virtual ~ModuleConfigControl() {};
353     virtual QString getValue();
354     virtual void hide() { combo->hide(); if( label ) label->hide(); }
355     virtual void show() { combo->show(); if( label ) label->show(); }
356 private:
357     void finish( bool );
358     QLabel *label;
359     QComboBox *combo;
360 };
361
362 struct checkBoxListItem {
363     QCheckBox *checkBox;
364     char *psz_module;
365 };
366
367 class ModuleListConfigControl : public VStringConfigControl
368 {
369     Q_OBJECT;
370     friend class ConfigControl;
371 public:
372     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
373                              bool, QGridLayout*, int& );
374 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
375 //                         QComboBox*, bool );
376     virtual ~ModuleListConfigControl();
377     virtual QString getValue();
378     virtual void hide();
379     virtual void show();
380 public slots:
381     void onUpdate();
382 private:
383     void finish( bool );
384     QVector<checkBoxListItem*> modules;
385     QGroupBox *groupBox;
386     QLineEdit *text;
387 };
388
389 class StringListConfigControl : public VStringConfigControl
390 {
391     Q_OBJECT;
392 public:
393     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
394                              bool, QGridLayout*, int& );
395     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
396                              QComboBox*, bool );
397     virtual ~StringListConfigControl() {};
398     virtual QString getValue();
399     virtual void hide() { combo->hide(); if( label ) label->hide(); }
400     virtual void show() { combo->show(); if( label ) label->show(); }
401     QComboBox *combo;
402 private:
403     void finish(module_config_t *, bool );
404     QLabel *label;
405 private slots:
406     void actionRequested( int );
407
408 };
409
410 void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
411                         QComboBox *combo );
412
413 #if 0
414 struct ModuleCheckBox {
415     QCheckBox *checkbox;
416     QString module;
417 };
418
419 class ModuleListConfigControl : public ConfigControl
420 {
421 public:
422     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
423                          bycat );
424     virtual ~StringConfigControl();
425     virtual QString getValue();
426 private:
427     std::vector<ModuleCheckBox> checkboxes;
428     QLineEdit *text;
429 private slot:
430     void OnUpdate();
431 };
432 #endif
433
434 /**********************************************************************
435  * Key selector widget
436  **********************************************************************/
437 class KeyShortcutEdit: public QLineEdit
438 {
439     Q_OBJECT;
440 public:
441     void setValue( int _value ){ value = _value; }
442     int getValue() const { return value; }
443
444     void setGlobal( bool _value ) { b_global = _value; }
445     bool getGlobal()  const { return b_global; }
446 public slots:
447     virtual void clear(void) { value = 0; QLineEdit::clear(); b_global = false;}
448 private:
449     int value;
450     bool b_global;
451     virtual void mousePressEvent( QMouseEvent *event );
452 signals:
453     void pressed();
454 };
455
456 class SearchLineEdit;
457 class KeySelectorControl : public ConfigControl
458 {
459     Q_OBJECT;
460 public:
461     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
462                         QGridLayout*, int& );
463     virtual int getType() { return CONFIG_ITEM_KEY; }
464     virtual ~KeySelectorControl() {};
465     virtual void hide() { table->hide(); if( label ) label->hide(); }
466     virtual void show() { table->show(); if( label ) label->show(); }
467     void doApply();
468 private:
469     void finish();
470     QLabel *label;
471     QTreeWidget *table;
472     KeyShortcutEdit *shortcutValue;
473     QList<module_config_t *> values;
474     SearchLineEdit *actionSearch;
475 private slots:
476     void setTheKey();
477     void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
478     void select1Key();
479     void filter( const QString & );
480 };
481
482 class KeyInputDialog : public QDialog
483 {
484 public:
485     KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
486     int keyValue;
487     bool conflicts;
488 private:
489     QTreeWidget *table;
490     void checkForConflicts( int i_vlckey );
491     void keyPressEvent( QKeyEvent *);
492     void wheelEvent( QWheelEvent *);
493     QLabel *selected, *warning;
494     QVBoxLayout *vLayout;
495     QDialogButtonBox *buttonBox;
496     bool b_global;
497 };
498 #endif