]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Constify and relocatablify EQ presets
[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 <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 /*******************************************************
213  * Float-based controls
214  *******************************************************/
215 class VFloatConfigControl : public ConfigControl
216 {
217     Q_OBJECT
218 public:
219     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
220                 ConfigControl(a,b,c) {};
221     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
222                 ConfigControl(a,b) {};
223     virtual float getValue() const = 0;
224     virtual int getType() const { return CONFIG_ITEM_FLOAT; }
225     virtual void doApply();
226 };
227
228 class FloatConfigControl : public VFloatConfigControl
229 {
230     Q_OBJECT
231 public:
232     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
233                         QGridLayout *, int );
234     FloatConfigControl( vlc_object_t *, module_config_t *,
235                         QLabel*, QDoubleSpinBox* );
236     virtual float getValue() const;
237     virtual void show() { spin->show(); if( label ) label->show(); }
238     virtual void hide() { spin->hide(); if( label ) label->hide(); }
239
240 protected:
241     QDoubleSpinBox *spin;
242
243 private:
244     QLabel *label;
245     void finish();
246 };
247
248 class FloatRangeConfigControl : public FloatConfigControl
249 {
250     Q_OBJECT
251 public:
252     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
253                              QGridLayout *, int );
254     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
255                              QLabel*, QDoubleSpinBox* );
256 private:
257     void finish();
258 };
259
260 /*******************************************************
261  * String-based controls
262  *******************************************************/
263 class VStringConfigControl : public ConfigControl
264 {
265     Q_OBJECT
266 public:
267     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
268                 ConfigControl(a,b,c) {};
269     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
270                 ConfigControl(a,b) {};
271     virtual QString getValue() const = 0;
272     virtual int getType() const { return CONFIG_ITEM_STRING; }
273     virtual void doApply();
274 };
275
276 class StringConfigControl : public VStringConfigControl
277 {
278     Q_OBJECT
279 public:
280     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
281                          QGridLayout *, int,  bool pwd );
282     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
283                          QLineEdit*,  bool pwd );
284     virtual QString getValue() const { return text->text(); };
285     virtual void show() { text->show(); if( label ) label->show(); }
286     virtual void hide() { text->hide(); if( label ) label->hide(); }
287 private:
288     void finish();
289     QLineEdit *text;
290     QLabel *label;
291 };
292
293 class FileConfigControl : public VStringConfigControl
294 {
295     Q_OBJECT
296 public:
297     FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
298                        QGridLayout *, int );
299     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
300                        QLineEdit *, QPushButton * );
301     virtual QString getValue() const { return text->text(); };
302     virtual void show() { text->show(); if( label ) label->show(); browse->show(); }
303     virtual void hide() { text->hide(); if( label ) label->hide(); browse->hide(); }
304 public slots:
305     virtual void updateField();
306 protected:
307     void finish();
308     QLineEdit *text;
309     QLabel *label;
310     QPushButton *browse;
311 };
312
313 class DirectoryConfigControl : public FileConfigControl
314 {
315     Q_OBJECT
316 public:
317     DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
318                             QGridLayout *, int );
319     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
320                             QLineEdit *, QPushButton * );
321 public slots:
322     virtual void updateField();
323 };
324
325 class FontConfigControl : public VStringConfigControl
326 {
327     Q_OBJECT
328 public:
329     FontConfigControl( vlc_object_t *, module_config_t *, QWidget *,
330                        QGridLayout *, int);
331     FontConfigControl( vlc_object_t *, module_config_t *, QLabel *,
332                        QFontComboBox *);
333     virtual QString getValue() const { return font->currentFont().family(); }
334 protected:
335     QLabel *label;
336     QFontComboBox *font;
337 };
338
339 class ModuleConfigControl : public VStringConfigControl
340 {
341 public:
342     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
343                          QGridLayout*, int );
344     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
345                          QComboBox*, bool );
346     virtual QString getValue() const;
347     virtual void hide() { combo->hide(); if( label ) label->hide(); }
348     virtual void show() { combo->show(); if( label ) label->show(); }
349 private:
350     void finish( bool );
351     QLabel *label;
352     QComboBox *combo;
353 };
354
355 struct checkBoxListItem {
356     QCheckBox *checkBox;
357     char *psz_module;
358 };
359
360 class ModuleListConfigControl : public VStringConfigControl
361 {
362     Q_OBJECT
363     friend class ConfigControl;
364 public:
365     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
366                              bool, QGridLayout*, int );
367 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
368 //                         QComboBox*, bool );
369     virtual ~ModuleListConfigControl();
370     virtual QString getValue() const;
371     virtual void hide();
372     virtual void show();
373 public slots:
374     void onUpdate();
375 private:
376     void finish( bool );
377     QList<checkBoxListItem*> modules;
378     QGroupBox *groupBox;
379     QLineEdit *text;
380 };
381
382 class StringListConfigControl : public VStringConfigControl
383 {
384     Q_OBJECT
385 public:
386     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
387                              QGridLayout*, int );
388     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
389                              QComboBox*, bool );
390     virtual QString getValue() const;
391     virtual void hide() { combo->hide(); if( label ) label->hide(); }
392     virtual void show() { combo->show(); if( label ) label->show(); }
393     QComboBox *combo;
394 private:
395     void finish(module_config_t * );
396     QLabel *label;
397 private slots:
398     void actionRequested( int );
399
400 };
401
402 void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
403                         QComboBox *combo );
404
405 #if 0
406 struct ModuleCheckBox {
407     QCheckBox *checkbox;
408     QString module;
409 };
410
411 class ModuleListConfigControl : public ConfigControl
412 {
413 public:
414     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
415                          bycat );
416     virtual ~StringConfigControl();
417     virtual QString getValue();
418 private:
419     std::vector<ModuleCheckBox> checkboxes;
420     QLineEdit *text;
421 private slot:
422     void OnUpdate();
423 };
424 #endif
425
426 /**********************************************************************
427  * Key selector widget
428  **********************************************************************/
429 class KeyShortcutEdit: public QLineEdit
430 {
431     Q_OBJECT
432 public:
433     void setValue( const QString& value ){ this->value = value; }
434     QString getValue() const { return value; }
435
436     void setGlobal( bool _value ) { b_global = _value; }
437     bool getGlobal() const { return b_global; }
438 public slots:
439     virtual void clear(void) { value = qfu(""); QLineEdit::clear(); }
440 private:
441     QString value;
442     bool b_global;
443     virtual void mousePressEvent( QMouseEvent *event );
444 signals:
445     void pressed();
446 };
447
448 class SearchLineEdit;
449 class KeySelectorControl : public ConfigControl
450 {
451     Q_OBJECT
452 public:
453     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
454                         QGridLayout*, int );
455     virtual int getType() const { return CONFIG_ITEM_KEY; }
456     virtual void hide() { table->hide(); if( label ) label->hide(); }
457     virtual void show() { table->show(); if( label ) label->show(); }
458     virtual void doApply();
459 private:
460     void finish();
461     QLabel *label;
462     QTreeWidget *table;
463     KeyShortcutEdit *shortcutValue;
464     QList<module_config_t *> values;
465     SearchLineEdit *actionSearch;
466 private slots:
467     void setTheKey();
468     void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
469     void select( QTreeWidgetItem * = NULL, int column = 1 );
470     void select1Key();
471     void filter( const QString & );
472 };
473
474 class KeyInputDialog : public QDialog
475 {
476 public:
477     KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
478     int keyValue;
479     bool conflicts;
480 private:
481     QTreeWidget *table;
482     void checkForConflicts( int i_vlckey );
483     void keyPressEvent( QKeyEvent *);
484     void wheelEvent( QWheelEvent *);
485     QLabel *selected, *warning;
486     QVBoxLayout *vLayout;
487     QDialogButtonBox *buttonBox;
488     bool b_global;
489 };
490 #endif