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