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