]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4: Unneeded includes.
[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 QTreeWidget;
53 class QTreeWidgetItem;
54 class QGroupBox;
55 class QGridLayout;
56 class QDialogButtonBox;
57 class QVBoxLayout;
58
59 class ConfigControl : public QObject
60 {
61     Q_OBJECT
62 public:
63     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
64                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
65     {
66         widget = new QWidget( p );
67     }
68     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
69                             p_this (_p_this ), p_item( _p_conf )
70     {
71         widget = NULL;
72     }
73     virtual ~ConfigControl() {};
74     virtual int getType() = 0;
75     const char * getName() { return  p_item->psz_name; }
76     QWidget *getWidget() { assert( widget ); return widget; }
77     bool isAdvanced() { return p_item->b_advanced; }
78     virtual void hide() { getWidget()->hide(); };
79     virtual void show() { getWidget()->show(); };
80
81     static ConfigControl * createControl( vlc_object_t*,
82                                           module_config_t*,QWidget* );
83     static ConfigControl * createControl( vlc_object_t*,
84                                           module_config_t*,QWidget*,
85                                           QGridLayout *, int& );
86     void doApply( intf_thread_t *);
87 protected:
88     vlc_object_t *p_this;
89     module_config_t *p_item;
90     QString _name;
91     QWidget *widget;
92     bool _advanced;
93 #if 0
94 /* You shouldn't use that now..*/
95 signals:
96     void Updated();
97 #endif
98 };
99
100 /*******************************************************
101  * Integer-based controls
102  *******************************************************/
103 class VIntConfigControl : public ConfigControl
104 {
105 Q_OBJECT
106 public:
107     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
108             ConfigControl(a,b,c) {};
109     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
110                 ConfigControl(a,b) {};
111     virtual ~VIntConfigControl() {};
112     virtual int getValue() = 0;
113     virtual int getType() { return CONFIG_ITEM_INTEGER; }
114 };
115
116 class IntegerConfigControl : public VIntConfigControl
117 {
118 Q_OBJECT
119 public:
120     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
121                           QGridLayout *, int& );
122     IntegerConfigControl( vlc_object_t *, module_config_t *,
123                           QLabel*, QSpinBox* );
124     IntegerConfigControl( vlc_object_t *, module_config_t *,
125                           QLabel*, QSlider* );
126     virtual ~IntegerConfigControl() {};
127     virtual int getValue();
128     virtual void show() { spin->show(); if( label ) label->show(); }
129     virtual void hide() { spin->hide(); if( label ) label->hide(); }
130
131 protected:
132     QSpinBox *spin;
133 private:
134     QLabel *label;
135     void finish();
136 };
137
138 class IntegerRangeConfigControl : public IntegerConfigControl
139 {
140 public:
141     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
142                                QGridLayout *, int& );
143     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
144                                QLabel*, QSpinBox* );
145 private:
146     void finish();
147 };
148
149 class IntegerRangeSliderConfigControl : public VIntConfigControl
150 {
151 public:
152     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
153                                 QLabel *, QSlider * );
154     virtual ~IntegerRangeSliderConfigControl() {};
155     virtual int getValue();
156 protected:
157          QSlider *slider;
158 private:
159          QLabel *label;
160          void finish();
161 };
162
163 class IntegerListConfigControl : public VIntConfigControl
164 {
165 Q_OBJECT
166 public:
167     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
168                               bool, QGridLayout*, int& );
169     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
170                               QComboBox*, bool );
171     virtual ~IntegerListConfigControl() {};
172     virtual int getValue();
173     virtual void hide() { combo->hide(); if( label ) label->hide(); }
174     virtual void show() { combo->show(); if( label ) label->show(); }
175 private:
176     void finish(module_config_t *, bool );
177     QLabel *label;
178     QComboBox *combo;
179 private slots:
180     void actionRequested( int );
181
182 };
183
184 class BoolConfigControl : public VIntConfigControl
185 {
186 public:
187     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
188                        QGridLayout *, int& );
189     BoolConfigControl( vlc_object_t *, module_config_t *,
190                        QLabel *, QCheckBox*, bool );
191     virtual ~BoolConfigControl() {};
192     virtual int getValue();
193     virtual void show() { checkbox->show(); }
194     virtual void hide() { checkbox->hide(); }
195     virtual int getType() { return CONFIG_ITEM_BOOL; }
196 private:
197     QCheckBox *checkbox;
198     void finish();
199 };
200
201 /*******************************************************
202  * Float-based controls
203  *******************************************************/
204 class VFloatConfigControl : public ConfigControl
205 {
206     Q_OBJECT
207 public:
208     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
209                 ConfigControl(a,b,c) {};
210     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
211                 ConfigControl(a,b) {};
212     virtual ~VFloatConfigControl() {};
213     virtual float getValue() = 0;
214     virtual int getType() { return CONFIG_ITEM_FLOAT; }
215 };
216
217 class FloatConfigControl : public VFloatConfigControl
218 {
219     Q_OBJECT
220 public:
221     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
222                         QGridLayout *, int& );
223     FloatConfigControl( vlc_object_t *, module_config_t *,
224                         QLabel*, QDoubleSpinBox* );
225     virtual ~FloatConfigControl() {};
226     virtual float getValue();
227     virtual void show() { spin->show(); if( label ) label->show(); }
228     virtual void hide() { spin->hide(); if( label ) label->hide(); }
229
230 protected:
231     QDoubleSpinBox *spin;
232
233 private:
234     QLabel *label;
235     void finish();
236 };
237
238 class FloatRangeConfigControl : public FloatConfigControl
239 {
240     Q_OBJECT
241 public:
242     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
243                              QGridLayout *, int& );
244     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
245                              QLabel*, QDoubleSpinBox* );
246 private:
247     void finish();
248 };
249
250 /*******************************************************
251  * String-based controls
252  *******************************************************/
253 class VStringConfigControl : public ConfigControl
254 {
255     Q_OBJECT
256 public:
257     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
258                 ConfigControl(a,b,c) {};
259     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
260                 ConfigControl(a,b) {};
261     virtual ~VStringConfigControl() {};
262     virtual QString getValue() = 0;
263     virtual int getType() { return CONFIG_ITEM_STRING; }
264 };
265
266 class StringConfigControl : public VStringConfigControl
267 {
268     Q_OBJECT
269 public:
270     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
271                          QGridLayout *, int&,  bool pwd );
272     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
273                          QLineEdit*,  bool pwd );
274     virtual ~StringConfigControl() {};
275     virtual QString getValue() { return text->text(); };
276     virtual void show() { text->show(); if( label ) label->show(); }
277     virtual void hide() { text->hide(); if( label ) label->hide(); }
278 private:
279     void finish();
280     QLineEdit *text;
281     QLabel *label;
282 };
283
284 class FileConfigControl : public VStringConfigControl
285 {
286     Q_OBJECT;
287 public:
288     FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
289                        QGridLayout *, int&, bool pwd );
290     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
291                        QLineEdit *, QPushButton *, bool pwd );
292     virtual ~FileConfigControl() {};
293     virtual QString getValue() { return text->text(); };
294     virtual void show() { text->show(); if( label ) label->show(); browse->show(); }
295     virtual void hide() { text->hide(); if( label ) label->hide(); browse->hide(); }
296 public slots:
297     virtual void updateField();
298 protected:
299     void finish();
300     QLineEdit *text;
301     QLabel *label;
302     QPushButton *browse;
303 };
304
305 class DirectoryConfigControl : public FileConfigControl
306 {
307     Q_OBJECT;
308 public:
309     DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
310                             QGridLayout *, int&, bool pwd );
311     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
312                             QLineEdit *, QPushButton *, bool pwd );
313     virtual ~DirectoryConfigControl() {};
314 public slots:
315     virtual void updateField();
316 };
317
318 #if 0
319 class FontConfigControl : public FileConfigControl
320 {
321     Q_OBJECT;
322 public:
323     FontConfigControl( vlc_object_t *, module_config_t *, QWidget *,
324                        QGridLayout *, int&, bool pwd );
325     FontConfigControl( vlc_object_t *, module_config_t *, QLabel *,
326                        QLineEdit *, QPushButton *, bool pwd );
327     virtual ~FontConfigControl() {};
328 public slots:
329     virtual void updateField();
330 };
331 #endif
332
333 class ModuleConfigControl : public VStringConfigControl
334 {
335 public:
336     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
337                          QGridLayout*, int& );
338     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
339                          QComboBox*, bool );
340     virtual ~ModuleConfigControl() {};
341     virtual QString getValue();
342     virtual void hide() { combo->hide(); if( label ) label->hide(); }
343     virtual void show() { combo->show(); if( label ) label->show(); }
344 private:
345     void finish( bool );
346     QLabel *label;
347     QComboBox *combo;
348 };
349
350 struct checkBoxListItem {
351     QCheckBox *checkBox;
352     char *psz_module;
353 };
354
355 class ModuleListConfigControl : public VStringConfigControl
356 {
357     Q_OBJECT;
358     friend class ConfigControl;
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();
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