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