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