1 /*****************************************************************************
2 * preferences_widgets.hpp : Widgets for preferences panels
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
26 #ifndef _PREFERENCESWIDGETS_H_
27 #define _PREFERENCESWIDGETS_H_
33 #include <vlc_common.h>
43 #include <QTreeWidget>
46 #include <QDoubleSpinBox>
47 #include <QPushButton>
53 class QTreeWidgetItem;
56 class QDialogButtonBox;
59 class ConfigControl : public QObject
63 ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
64 QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
66 widget = new QWidget( p );
68 ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
69 p_this (_p_this ), p_item( _p_conf )
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(); };
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 *);
89 module_config_t *p_item;
94 /* You shouldn't use that now..*/
100 /*******************************************************
101 * Integer-based controls
102 *******************************************************/
103 class VIntConfigControl : public ConfigControl
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; }
116 class IntegerConfigControl : public VIntConfigControl
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 *,
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(); }
138 class IntegerRangeConfigControl : public IntegerConfigControl
141 IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
142 QGridLayout *, int& );
143 IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
144 QLabel*, QSpinBox* );
149 class IntegerRangeSliderConfigControl : public VIntConfigControl
152 IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
153 QLabel *, QSlider * );
154 virtual ~IntegerRangeSliderConfigControl() {};
155 virtual int getValue();
163 class IntegerListConfigControl : public VIntConfigControl
167 IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
168 bool, QGridLayout*, int& );
169 IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
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(); }
176 void finish(module_config_t *, bool );
180 void actionRequested( int );
184 class BoolConfigControl : public VIntConfigControl
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; }
201 /*******************************************************
202 * Float-based controls
203 *******************************************************/
204 class VFloatConfigControl : public ConfigControl
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; }
217 class FloatConfigControl : public VFloatConfigControl
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(); }
231 QDoubleSpinBox *spin;
238 class FloatRangeConfigControl : public FloatConfigControl
242 FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
243 QGridLayout *, int& );
244 FloatRangeConfigControl( vlc_object_t *, module_config_t *,
245 QLabel*, QDoubleSpinBox* );
250 /*******************************************************
251 * String-based controls
252 *******************************************************/
253 class VStringConfigControl : public ConfigControl
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; }
266 class StringConfigControl : public VStringConfigControl
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(); }
284 class FileConfigControl : public VStringConfigControl
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(); }
297 virtual void updateField();
305 class DirectoryConfigControl : public FileConfigControl
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() {};
315 virtual void updateField();
319 class FontConfigControl : public FileConfigControl
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() {};
329 virtual void updateField();
333 class ModuleConfigControl : public VStringConfigControl
336 ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
337 QGridLayout*, int& );
338 ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
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(); }
350 struct checkBoxListItem {
355 class ModuleListConfigControl : public VStringConfigControl
358 friend class ConfigControl;
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();
369 void onUpdate( int value );
372 QVector<checkBoxListItem*> modules;
377 class StringListConfigControl : public VStringConfigControl
381 StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
382 bool, QGridLayout*, int& );
383 StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
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(); }
391 void finish(module_config_t *, bool );
394 void actionRequested( int );
398 void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
399 QComboBox *combo, QWidget *parent = 0 );
402 struct ModuleCheckBox {
407 class ModuleListConfigControl : public ConfigControl
410 StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
412 virtual ~StringConfigControl();
413 virtual QString getValue();
415 std::vector<ModuleCheckBox> checkboxes;
422 /**********************************************************************
423 * Key selector widget
424 **********************************************************************/
425 class KeyShortcutEdit: public QLineEdit
429 void setValue( int _value ){ value = _value; }
430 int getValue() const { return value; }
432 virtual void clear(void) { value = 0; QLineEdit::clear(); }
435 virtual void mousePressEvent( QMouseEvent *event );
440 class KeySelectorControl : public ConfigControl
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(); }
455 KeyShortcutEdit *shortcutValue;
456 QList<module_config_t *> values;
459 void selectKey( QTreeWidgetItem * = NULL );
463 class KeyInputDialog : public QDialog
466 KeyInputDialog( QTreeWidget *, QString, QWidget * );
471 void checkForConflicts( int i_vlckey );
472 void keyPressEvent( QKeyEvent *);
473 void wheelEvent( QWheelEvent *);
475 QVBoxLayout *vLayout;
476 QDialogButtonBox *buttonBox;