preferences_widgets.hpp 14.5 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * preferences_widgets.hpp : Widgets for preferences panels
 ****************************************************************************
4
 * Copyright (C) 2006-2007 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6
7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
dionoea's avatar
dionoea committed
8
 *          Antoine Cellerier <dionoea@videolan.org>
9
 *          Jean-Baptiste Kempf <jb@videolan.org>
zorglub's avatar
zorglub committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

26
27
#ifndef _PREFERENCESWIDGETS_H_
#define _PREFERENCESWIDGETS_H_
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
28

Christophe Mutricy's avatar
Christophe Mutricy committed
29
30
31
32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include <vlc_common.h>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
34
35
36
37

#include "qt4.hpp"
#include <assert.h>

zorglub's avatar
zorglub committed
38
#include <QWidget>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
39
40
41

#include <QCheckBox>
#include <QComboBox>
zorglub's avatar
zorglub committed
42
#include <QLineEdit>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
43
#include <QTreeWidget>
zorglub's avatar
zorglub committed
44
#include <QSpinBox>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
45
#include <QLabel>
46
#include <QDoubleSpinBox>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
47
#include <QPushButton>
48
#include <QVector>
49
50
#include <QDialog>

zorglub's avatar
zorglub committed
51

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
52
53
54
55
class QFile;
class QTreeWidget;
class QTreeWidgetItem;
class QGroupBox;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
56
class QGridLayout;
57
class QDialogButtonBox;
58
class QVBoxLayout;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
59

zorglub's avatar
zorglub committed
60
class ConfigControl : public QObject
zorglub's avatar
zorglub committed
61
{
62
    Q_OBJECT
zorglub's avatar
zorglub committed
63
public:
zorglub's avatar
zorglub committed
64
65
66
67
68
69
70
71
72
73
74
    ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
                   QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
    {
        widget = new QWidget( p );
    }
    ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
                            p_this (_p_this ), p_item( _p_conf )
    {
        widget = NULL;
    }
    virtual ~ConfigControl() {};
zorglub's avatar
zorglub committed
75
    virtual int getType() = 0;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
76
    const char * getName() { return  p_item->psz_name; }
zorglub's avatar
zorglub committed
77
78
    QWidget *getWidget() { assert( widget ); return widget; }
    bool isAdvanced() { return p_item->b_advanced; }
zorglub's avatar
zorglub committed
79
80
    virtual void hide() { getWidget()->hide(); };
    virtual void show() { getWidget()->show(); };
zorglub's avatar
zorglub committed
81
82

    static ConfigControl * createControl( vlc_object_t*,
zorglub's avatar
zorglub committed
83
                                          module_config_t*,QWidget* );
zorglub's avatar
zorglub committed
84
85
    static ConfigControl * createControl( vlc_object_t*,
                                          module_config_t*,QWidget*,
86
                                          QGridLayout *, int& );
zorglub's avatar
zorglub committed
87
    void doApply( intf_thread_t *);
zorglub's avatar
zorglub committed
88
89
protected:
    vlc_object_t *p_this;
zorglub's avatar
zorglub committed
90
    module_config_t *p_item;
zorglub's avatar
zorglub committed
91
    QString _name;
zorglub's avatar
zorglub committed
92
    QWidget *widget;
zorglub's avatar
zorglub committed
93
    bool _advanced;
94
95
#if 0
/* You shouldn't use that now..*/
zorglub's avatar
zorglub committed
96
97
signals:
    void Updated();
98
#endif
zorglub's avatar
zorglub committed
99
100
101
102
103
104
105
};

/*******************************************************
 * Integer-based controls
 *******************************************************/
class VIntConfigControl : public ConfigControl
{
106
Q_OBJECT
zorglub's avatar
zorglub committed
107
108
109
public:
    VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
            ConfigControl(a,b,c) {};
zorglub's avatar
zorglub committed
110
111
    VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
                ConfigControl(a,b) {};
zorglub's avatar
zorglub committed
112
113
    virtual ~VIntConfigControl() {};
    virtual int getValue() = 0;
114
    virtual int getType() { return CONFIG_ITEM_INTEGER; }
zorglub's avatar
zorglub committed
115
116
117
118
};

class IntegerConfigControl : public VIntConfigControl
{
119
Q_OBJECT
zorglub's avatar
zorglub committed
120
public:
zorglub's avatar
zorglub committed
121
    IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
122
                          QGridLayout *, int& );
zorglub's avatar
zorglub committed
123
124
    IntegerConfigControl( vlc_object_t *, module_config_t *,
                          QLabel*, QSpinBox* );
125
126
    IntegerConfigControl( vlc_object_t *, module_config_t *,
                          QLabel*, QSlider* );
zorglub's avatar
zorglub committed
127
    virtual ~IntegerConfigControl() {};
zorglub's avatar
zorglub committed
128
    virtual int getValue();
129
130
    virtual void show() { spin->show(); if( label ) label->show(); }
    virtual void hide() { spin->hide(); if( label ) label->hide(); }
131
132

protected:
zorglub's avatar
zorglub committed
133
    QSpinBox *spin;
134
private:
zorglub's avatar
zorglub committed
135
136
    QLabel *label;
    void finish();
zorglub's avatar
zorglub committed
137
138
};

139
140
141
142
class IntegerRangeConfigControl : public IntegerConfigControl
{
public:
    IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
143
                               QGridLayout *, int& );
144
145
146
147
148
149
    IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
                               QLabel*, QSpinBox* );
private:
    void finish();
};

150
151
152
153
class IntegerRangeSliderConfigControl : public VIntConfigControl
{
public:
    IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
154
                                QLabel *, QSlider * );
155
156
157
158
159
160
161
162
163
    virtual ~IntegerRangeSliderConfigControl() {};
    virtual int getValue();
protected:
         QSlider *slider;
private:
         QLabel *label;
         void finish();
};

dionoea's avatar
dionoea committed
164
165
class IntegerListConfigControl : public VIntConfigControl
{
166
Q_OBJECT
dionoea's avatar
dionoea committed
167
168
public:
    IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
169
                              bool, QGridLayout*, int& );
dionoea's avatar
dionoea committed
170
171
172
173
    IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                              QComboBox*, bool );
    virtual ~IntegerListConfigControl() {};
    virtual int getValue();
174
175
    virtual void hide() { combo->hide(); if( label ) label->hide(); }
    virtual void show() { combo->show(); if( label ) label->show(); }
dionoea's avatar
dionoea committed
176
private:
177
    void finish(module_config_t *, bool );
dionoea's avatar
dionoea committed
178
179
    QLabel *label;
    QComboBox *combo;
180
181
182
private slots:
    void actionRequested( int );

dionoea's avatar
dionoea committed
183
184
};

zorglub's avatar
zorglub committed
185
186
187
class BoolConfigControl : public VIntConfigControl
{
public:
188
    BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
189
                       QGridLayout *, int& );
190
191
192
    BoolConfigControl( vlc_object_t *, module_config_t *,
                       QLabel *, QCheckBox*, bool );
    virtual ~BoolConfigControl() {};
zorglub's avatar
zorglub committed
193
    virtual int getValue();
194
195
    virtual void show() { checkbox->show(); }
    virtual void hide() { checkbox->hide(); }
196
    virtual int getType() { return CONFIG_ITEM_BOOL; }
zorglub's avatar
zorglub committed
197
private:
198
199
    QCheckBox *checkbox;
    void finish();
zorglub's avatar
zorglub committed
200
201
202
203
204
205
206
};

/*******************************************************
 * Float-based controls
 *******************************************************/
class VFloatConfigControl : public ConfigControl
{
207
    Q_OBJECT
zorglub's avatar
zorglub committed
208
209
210
public:
    VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
                ConfigControl(a,b,c) {};
zorglub's avatar
zorglub committed
211
212
    VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
                ConfigControl(a,b) {};
zorglub's avatar
zorglub committed
213
214
    virtual ~VFloatConfigControl() {};
    virtual float getValue() = 0;
215
    virtual int getType() { return CONFIG_ITEM_FLOAT; }
zorglub's avatar
zorglub committed
216
217
};

218
219
class FloatConfigControl : public VFloatConfigControl
{
220
    Q_OBJECT
221
222
public:
    FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
223
                        QGridLayout *, int& );
224
225
226
227
    FloatConfigControl( vlc_object_t *, module_config_t *,
                        QLabel*, QDoubleSpinBox* );
    virtual ~FloatConfigControl() {};
    virtual float getValue();
228
229
    virtual void show() { spin->show(); if( label ) label->show(); }
    virtual void hide() { spin->hide(); if( label ) label->hide(); }
230
231
232
233
234
235
236
237
238
239
240

protected:
    QDoubleSpinBox *spin;

private:
    QLabel *label;
    void finish();
};

class FloatRangeConfigControl : public FloatConfigControl
{
241
    Q_OBJECT
242
243
public:
    FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
244
                             QGridLayout *, int& );
245
246
247
248
249
    FloatRangeConfigControl( vlc_object_t *, module_config_t *,
                             QLabel*, QDoubleSpinBox* );
private:
    void finish();
};
zorglub's avatar
zorglub committed
250
251
252
253
254
255

/*******************************************************
 * String-based controls
 *******************************************************/
class VStringConfigControl : public ConfigControl
{
256
    Q_OBJECT
zorglub's avatar
zorglub committed
257
public:
zorglub's avatar
zorglub committed
258
    VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
zorglub's avatar
zorglub committed
259
                ConfigControl(a,b,c) {};
zorglub's avatar
zorglub committed
260
261
    VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
                ConfigControl(a,b) {};
zorglub's avatar
zorglub committed
262
263
    virtual ~VStringConfigControl() {};
    virtual QString getValue() = 0;
264
    virtual int getType() { return CONFIG_ITEM_STRING; }
zorglub's avatar
zorglub committed
265
266
267
268
};

class StringConfigControl : public VStringConfigControl
{
269
    Q_OBJECT
zorglub's avatar
zorglub committed
270
271
public:
    StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
272
                         QGridLayout *, int&,  bool pwd );
zorglub's avatar
zorglub committed
273
274
275
276
    StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                         QLineEdit*,  bool pwd );
    virtual ~StringConfigControl() {};
    virtual QString getValue() { return text->text(); };
277
278
    virtual void show() { text->show(); if( label ) label->show(); }
    virtual void hide() { text->hide(); if( label ) label->hide(); }
zorglub's avatar
zorglub committed
279
private:
zorglub's avatar
zorglub committed
280
    void finish();
zorglub's avatar
zorglub committed
281
    QLineEdit *text;
zorglub's avatar
zorglub committed
282
    QLabel *label;
zorglub's avatar
zorglub committed
283
284
};

285
286
287
288
289
class FileConfigControl : public VStringConfigControl
{
    Q_OBJECT;
public:
    FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
yoann's avatar
yoann committed
290
                       QGridLayout *, int&, bool pwd );
291
    FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
yoann's avatar
yoann committed
292
                       QLineEdit *, QPushButton *, bool pwd );
293
294
    virtual ~FileConfigControl() {};
    virtual QString getValue() { return text->text(); };
295
296
    virtual void show() { text->show(); if( label ) label->show(); browse->show(); }
    virtual void hide() { text->hide(); if( label ) label->hide(); browse->hide(); }
297
public slots:
298
    virtual void updateField();
299
protected:
300
301
302
303
304
305
    void finish();
    QLineEdit *text;
    QLabel *label;
    QPushButton *browse;
};

306
307
308
309
310
class DirectoryConfigControl : public FileConfigControl
{
    Q_OBJECT;
public:
    DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
yoann's avatar
yoann committed
311
                            QGridLayout *, int&, bool pwd );
312
    DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
yoann's avatar
yoann committed
313
                            QLineEdit *, QPushButton *, bool pwd );
314
315
    virtual ~DirectoryConfigControl() {};
public slots:
316
    virtual void updateField();
317
};
318

319
#if 0
yoann's avatar
yoann committed
320
321
322
323
324
325
326
327
328
329
330
331
class FontConfigControl : public FileConfigControl
{
    Q_OBJECT;
public:
    FontConfigControl( vlc_object_t *, module_config_t *, QWidget *,
                       QGridLayout *, int&, bool pwd );
    FontConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                       QLineEdit *, QPushButton *, bool pwd );
    virtual ~FontConfigControl() {};
public slots:
    virtual void updateField();
};
332
#endif
yoann's avatar
yoann committed
333

zorglub's avatar
zorglub committed
334
335
336
class ModuleConfigControl : public VStringConfigControl
{
public:
zorglub's avatar
zorglub committed
337
    ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
338
                         QGridLayout*, int& );
zorglub's avatar
zorglub committed
339
340
    ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                         QComboBox*, bool );
zorglub's avatar
zorglub committed
341
    virtual ~ModuleConfigControl() {};
zorglub's avatar
zorglub committed
342
    virtual QString getValue();
343
344
    virtual void hide() { combo->hide(); if( label ) label->hide(); }
    virtual void show() { combo->show(); if( label ) label->show(); }
zorglub's avatar
zorglub committed
345
private:
zorglub's avatar
zorglub committed
346
347
    void finish( bool );
    QLabel *label;
zorglub's avatar
zorglub committed
348
349
    QComboBox *combo;
};
dionoea's avatar
dionoea committed
350

351
352
353
354
355
struct checkBoxListItem {
    QCheckBox *checkBox;
    char *psz_module;
};

356
357
358
359
360
361
362
363
364
365
366
367
368
class ModuleListConfigControl : public VStringConfigControl
{
    Q_OBJECT;
public:
    ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
                             bool, QGridLayout*, int& );
//    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
//                         QComboBox*, bool );
    virtual ~ModuleListConfigControl();
    virtual QString getValue();
    virtual void hide();
    virtual void show();
public slots:
369
    void onUpdate( int value );
370
371
private:
    void finish( bool );
372
    QVector<checkBoxListItem*> modules;
373
    QGroupBox *groupBox;
374
375
376
    QLineEdit *text;
};

dionoea's avatar
dionoea committed
377
378
class StringListConfigControl : public VStringConfigControl
{
379
    Q_OBJECT;
dionoea's avatar
dionoea committed
380
381
public:
    StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
382
                             bool, QGridLayout*, int& );
dionoea's avatar
dionoea committed
383
384
385
386
    StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                             QComboBox*, bool );
    virtual ~StringListConfigControl() {};
    virtual QString getValue();
387
388
    virtual void hide() { combo->hide(); if( label ) label->hide(); }
    virtual void show() { combo->show(); if( label ) label->show(); }
389
	QComboBox *combo;
dionoea's avatar
dionoea committed
390
private:
391
    void finish(module_config_t *, bool );
dionoea's avatar
dionoea committed
392
    QLabel *label;
393
394
395
private slots:
    void actionRequested( int );

dionoea's avatar
dionoea committed
396
};
397
398
399
400

void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
                        QComboBox *combo, QWidget *parent = 0 );

zorglub's avatar
zorglub committed
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#if 0
struct ModuleCheckBox {
    QCheckBox *checkbox;
    QString module;
};

class ModuleListConfigControl : public ConfigControl
{
public:
    StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
                         bycat );
    virtual ~StringConfigControl();
    virtual QString getValue();
private:
    std::vector<ModuleCheckBox> checkboxes;
    QLineEdit *text;
private slot:
    void OnUpdate();
};
#endif

422
423
424
/**********************************************************************
 * Key selector widget
 **********************************************************************/
425
426
427
class KeyShortcutEdit: public QLineEdit
{
    Q_OBJECT
428
429
public:
    void setValue( int _value ){ value = _value; }
430
431
432
    int getValue() const { return value; }
public slots:
    virtual void clear(void) { value = 0; QLineEdit::clear(); }
433
private:
434
    int value;
435
436
437
438
439
    virtual void mousePressEvent( QMouseEvent *event );
signals:
    void pressed();
};

440
441
442
443
444
445
class KeySelectorControl : public ConfigControl
{
    Q_OBJECT;
public:
    KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
                        QGridLayout*, int& );
446
    virtual int getType() { return CONFIG_ITEM_KEY; }
447
    virtual ~KeySelectorControl() {};
448
449
    virtual void hide() { table->hide(); if( label ) label->hide(); }
    virtual void show() { table->show(); if( label ) label->show(); }
450
451
452
453
454
    void doApply();
private:
    void finish();
    QLabel *label;
    QTreeWidget *table;
455
    KeyShortcutEdit *shortcutValue;
456
457
    QList<module_config_t *> values;
private slots:
458
459
460
    void setTheKey();
    void selectKey( QTreeWidgetItem * = NULL );
    void select1Key( QTreeWidgetItem *);
461
462
};

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
class KeyInputDialog : public QDialog
{
public:
    KeyInputDialog( QTreeWidget *, QString, QWidget * );
    int keyValue;
    bool conflicts;
private:
    QTreeWidget *table;
    void checkForConflicts( int i_vlckey );
    void keyPressEvent( QKeyEvent *);
    void wheelEvent( QWheelEvent *);
    QLabel *selected;
    QVBoxLayout *vLayout;
    QDialogButtonBox *buttonBox;
};
zorglub's avatar
zorglub committed
478
#endif