PreferenceWidget.cpp 2.94 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * PreferenceWidget.cpp: Abstract class that will be used to save load / preferences
 * values.
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
5
 * Copyright (C) 2008-2010 VideoLAN
6
7
 *
 * Authors: Clement CHAVANCE <kinder@vlmc.org>
8
 *          Hugo Beauzée-Luyssen <hugo@vlmc.org>
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * 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.
 *****************************************************************************/

25
26
27
#include "ISettingsCategorieWidget.h"
#include "PreferenceWidget.h"
#include "SettingsManager.h"
28

29
30
31
#include "BoolWidget.h"
#include "DoubleWidget.h"
#include "IntWidget.h"
32
#include "KeyboardShortcut.h"
33
#include "LanguageWidget.h"
34
#include "StringWidget.h"
35
36

#include <QFormLayout>
37
#include <QtDebug>
38
#include <QWidget>
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <QLabel>

PreferenceWidget::PreferenceWidget( const QString &categorie, SettingsManager::Type type,
                                    QWidget *parent ) :
    QWidget( parent ),
    m_categorie( categorie )
{
    SettingsManager::SettingHash    settings =
            SettingsManager::getInstance()->group( categorie, type );
    QFormLayout *layout = new QFormLayout( this );
    foreach ( SettingValue* s, settings.values() )
    {
        ISettingsCategorieWidget    *widget = widgetFactory( s );
52
53
54
55
        QLabel                      *label = new QLabel( s->name(), this );
        label->setToolTip( s->description() );
        widget->widget()->setToolTip( s->description() );
        layout->addRow( label, widget->widget() );
56
    }
57

58
59
60
61
62
    setLayout( layout );
}

ISettingsCategorieWidget*
PreferenceWidget::widgetFactory( SettingValue *s )
63
{
64
65
66
67
    switch ( s->type() )
    {
    case SettingValue::KeyboardShortcut:
        return new KeyboardShortcut( s, this );
68
69
    case SettingValue::Language:
        return new LanguageWidget( s, this );
70
71
    case SettingValue::String:
        return new StringWidget( s, this );
72
73
    case SettingValue::Int:
        return new IntWidget( s, this );
74
75
    case SettingValue::Double:
        return new DoubleWidget( s, this );
76
77
    case SettingValue::Bool:
        return new BoolWidget( s, this );
78
    }
79
}
Clement CHAVANCE's avatar
Clement CHAVANCE committed
80

81
82
83
84
void
PreferenceWidget::load()
{
}
85

86
void
87
PreferenceWidget::save()
88
{
89
90
    foreach ( ISettingsCategorieWidget* w, m_settings )
        w->save();
91
}