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