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