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