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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
33
34
35
#include "qt4.hpp"
#include <assert.h>

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
49
50
51
class QTreeWidget;
class QTreeWidgetItem;
class QGroupBox;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
52
class QGridLayout;
53
class QDialogButtonBox;
54
class QVBoxLayout;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
55

zorglub's avatar
zorglub committed
56
class ConfigControl : public QObject
zorglub's avatar
zorglub committed
57
{
58
    Q_OBJECT
zorglub's avatar
zorglub committed
59
public:
zorglub's avatar
zorglub committed
60
61
62
63
64
65
66
67
68
69
70
    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
71
    virtual int getType() = 0;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
72
    const char * getName() { return  p_item->psz_name; }
zorglub's avatar
zorglub committed
73
74
    QWidget *getWidget() { assert( widget ); return widget; }
    bool isAdvanced() { return p_item->b_advanced; }
zorglub's avatar
zorglub committed
75
76
    virtual void hide() { getWidget()->hide(); };
    virtual void show() { getWidget()->show(); };
zorglub's avatar
zorglub committed
77
78

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

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

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

protected:
zorglub's avatar
zorglub committed
129
    QSpinBox *spin;
130
private:
zorglub's avatar
zorglub committed
131
132
    QLabel *label;
    void finish();
zorglub's avatar
zorglub committed
133
134
};

135
136
137
138
class IntegerRangeConfigControl : public IntegerConfigControl
{
public:
    IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
139
                               QGridLayout *, int& );
140
141
142
143
144
145
    IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
                               QLabel*, QSpinBox* );
private:
    void finish();
};

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

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

dionoea's avatar
dionoea committed
179
180
};

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

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

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

protected:
    QDoubleSpinBox *spin;

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

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

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

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

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

302
303
304
305
306
class DirectoryConfigControl : public FileConfigControl
{
    Q_OBJECT;
public:
    DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
307
                            QGridLayout *, int& );
308
    DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
309
                            QLineEdit *, QPushButton * );
310
311
    virtual ~DirectoryConfigControl() {};
public slots:
312
    virtual void updateField();
313
};
314

315
#if 0
yoann's avatar
yoann committed
316
317
318
319
320
321
322
323
324
325
326
327
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();
};
328
#endif
yoann's avatar
yoann committed
329

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

347
348
349
350
351
struct checkBoxListItem {
    QCheckBox *checkBox;
    char *psz_module;
};

352
353
354
class ModuleListConfigControl : public VStringConfigControl
{
    Q_OBJECT;
355
    friend class ConfigControl;
356
357
358
359
360
361
362
363
364
365
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:
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
366
    void onUpdate();
367
368
private:
    void finish( bool );
369
    QVector<checkBoxListItem*> modules;
370
    QGroupBox *groupBox;
371
372
373
    QLineEdit *text;
};

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

dionoea's avatar
dionoea committed
393
};
394
395

void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
396
                        QComboBox *combo );
397

zorglub's avatar
zorglub committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#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

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

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

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