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