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