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