]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/prefs_dialog.cpp
Preferences
[vlc] / modules / gui / qt4 / dialogs / prefs_dialog.cpp
1 /*****************************************************************************
2  * prefs_dialog.cpp : Preferences
3  ****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
22
23 #include "dialogs/prefs_dialog.hpp"
24 #include "dialogs_provider.hpp"
25 #include "util/qvlcframe.hpp"
26
27 #include "components/preferences.hpp"
28 #include "qt4.hpp"
29
30 #include <QHBoxLayout>
31 #include <QGroupBox>
32 #include <QRadioButton>
33 #include <QVBoxLayout>
34 #include <QPushButton>
35 #include <QCheckBox>
36 PrefsDialog *PrefsDialog::instance = NULL;
37
38 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
39 {
40      layout = new QHBoxLayout();
41      QVBoxLayout * main_layout = new QVBoxLayout();
42      setWindowTitle( _("Preferences" ) );
43      resize( 800, 450 );
44
45      advanced_tree = NULL;
46      simple_tree = NULL;
47      simple_panel = NULL;
48      advanced_panel = NULL;
49
50      vertical = new QVBoxLayout();
51
52      // Choice for types
53      types = new QGroupBox( "Show settings" );
54      QHBoxLayout *tl = new QHBoxLayout();
55      tl->setSpacing( 3 );
56      small = new QRadioButton( "Common", types );
57      all = new QRadioButton( "All", types );
58      tl->addWidget( small );
59      tl->addWidget( all );
60      types->setLayout(tl );
61
62      layout->addLayout( vertical, 1 );
63      setAll();
64
65      all->setChecked( true );
66
67      main_layout->addLayout( layout );
68      adv_chk = new QCheckBox("Advanced options");
69      main_layout->addWidget( adv_chk );
70
71      QObject::connect( adv_chk, SIGNAL( toggled(bool) ), this,
72                        SLOT( setAdvanced( bool ) ) );
73      setLayout( main_layout );
74
75      QObject::connect( small, SIGNAL( clicked() ), this, SLOT( setSmall()) );
76      QObject::connect( all, SIGNAL( clicked() ), this, SLOT( setAll()) );
77 }
78
79 void PrefsDialog::setAdvanced( bool advanced )
80 {
81     if( advanced_panel )
82         advanced_panel->setAdvanced( advanced );
83 }
84
85 void PrefsDialog::setAll()
86 {
87     while( (vertical->takeAt(0)) != 0  ) {}
88     if( simple_tree )
89         simple_tree->hide();
90
91     if( !advanced_tree )
92     {
93          advanced_tree = new PrefsTree( p_intf, this );
94          QObject::connect( advanced_tree,
95                            SIGNAL( currentItemChanged( QTreeWidgetItem *,
96                                    QTreeWidgetItem *) ), this,
97                            SLOT( changePanel( QTreeWidgetItem * ) ) );
98     }
99     advanced_tree->show();
100     setAdvanced( adv_chk->isChecked() );
101     vertical->addWidget( types );
102     vertical->addWidget( advanced_tree );
103
104      if( layout->count() == 2 )
105          layout->takeAt(1);
106
107      if( !advanced_panel )
108          advanced_panel = new PrefsPanel( this );
109      layout->addWidget( advanced_panel, 3 ) ;
110 }
111
112 void PrefsDialog::setSmall()
113 {
114     while( (vertical->takeAt(0)) != 0  ) {}
115     if( advanced_tree )
116         advanced_tree->hide();
117
118     if( !simple_tree )
119          simple_tree = new QTreeWidget();
120     simple_tree->show();
121     vertical->addWidget( types );
122     vertical->addWidget( simple_tree );
123
124     if( layout->count() == 2 )
125         layout->takeAt(1);
126
127     if( !simple_panel )
128         simple_panel = new QWidget();
129     layout->addWidget( simple_panel, 3 ) ;
130 }
131
132
133 void PrefsDialog::init()
134 {
135 }
136
137 PrefsDialog::~PrefsDialog()
138 {
139 }
140
141 void PrefsDialog::changePanel( QTreeWidgetItem *item )
142 {
143     PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
144
145     if( advanced_panel )
146     {
147         layout->removeWidget( advanced_panel );
148         advanced_panel->hide();
149     }
150     if( !data->panel )
151     {
152         data->panel = new PrefsPanel( p_intf, this, data );
153     }
154     advanced_panel = data->panel;
155     advanced_panel->show();
156     setAdvanced( adv_chk->isChecked() );
157     layout->addWidget( advanced_panel, 3 );
158
159 }