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