]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/prefs_dialog.cpp
Implement basic panel change
[vlc] / modules / gui / qt4 / dialogs / prefs_dialog.cpp
1 /*****************************************************************************
2  * prefs_dialog.cpp : Preferences
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
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 "components/simple_preferences.hpp"
29 #include "qt4.hpp"
30
31 #include <QHBoxLayout>
32 #include <QGroupBox>
33 #include <QRadioButton>
34 #include <QVBoxLayout>
35 #include <QPushButton>
36 #include <QCheckBox>
37 PrefsDialog *PrefsDialog::instance = NULL;
38
39 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
40 {
41      QGridLayout *main_layout = new QGridLayout(this);
42      setWindowTitle( qtr("Preferences" ) );
43      resize( 800, 450 );
44
45      tree_panel = new QWidget(0);
46      tree_panel_l = new QHBoxLayout;
47      tree_panel->setLayout( tree_panel_l );
48      main_panel = new QWidget(0);
49      main_panel_l = new QHBoxLayout;
50      main_panel->setLayout( main_panel_l );
51
52      // Choice for types
53      types = new QGroupBox( "Show settings" );
54      QHBoxLayout *tl = new QHBoxLayout(0);
55      tl->setSpacing( 3 ); tl->setMargin( 3 );
56      small = new QRadioButton( "Basic", types ); tl->addWidget( small );
57      all = new QRadioButton( "All", types ); tl->addWidget( all );
58      types->setLayout(tl);
59      all->setChecked( true );
60
61      adv_chk = new QCheckBox("Advanced options");
62
63      advanced_tree = NULL;
64      simple_tree = NULL;
65      simple_panel = NULL;
66      advanced_panel = NULL;
67
68      main_layout->addWidget( types, 0,0,1,1 );
69      main_layout->addWidget( tree_panel, 1,0,1,1 );
70      main_layout->addWidget( adv_chk , 2,0,1,1 );
71      main_layout->addWidget( main_panel, 0, 1, 3, 1 );
72
73      main_layout->setColumnMinimumWidth( 0, 200 );
74      main_layout->setColumnStretch( 0, 1 );
75      main_layout->setColumnStretch( 1,3 );
76
77      setSmall();
78
79      connect( adv_chk, SIGNAL( toggled(bool) ),
80               this, SLOT( setAdvanced( bool ) ) );
81      setLayout( main_layout );
82
83      connect( small, SIGNAL( clicked() ), this, SLOT( setSmall()) );
84      connect( all, SIGNAL( clicked() ), this, SLOT( setAll()) );
85 }
86
87 void PrefsDialog::setAdvanced( bool advanced )
88 {
89     if( advanced_panel )
90         advanced_panel->setAdvanced( advanced );
91 }
92
93 void PrefsDialog::setAll()
94 {
95     if( simple_tree )
96     {
97         tree_panel_l->removeWidget( simple_tree );
98         simple_tree->hide();
99     }
100
101     if( !advanced_tree )
102     {
103          advanced_tree = new PrefsTree( p_intf, tree_panel );
104          connect( advanced_tree,
105           SIGNAL( currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *) ),
106           this, SLOT( changePanel( QTreeWidgetItem * ) ) );
107     }
108     tree_panel_l->addWidget( advanced_tree );
109     advanced_tree->show();
110
111     if( simple_panel )
112     {
113         main_panel_l->removeWidget( simple_panel );
114         simple_panel->hide();
115     }
116     if( !advanced_panel )
117          advanced_panel = new PrefsPanel( main_panel );
118     main_panel_l->addWidget( advanced_panel );
119     advanced_panel->show();
120     adv_chk->show();
121 }
122
123 void PrefsDialog::setSmall()
124 {
125     if( advanced_tree )
126     {
127         tree_panel_l->removeWidget( advanced_tree );
128         advanced_tree->hide();
129     }
130     if( !simple_tree )
131     {
132          simple_tree = new SPrefsCatList( p_intf, tree_panel );
133          connect( simple_tree,
134           SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem *) ),
135           this, SLOT( changeSimplePanel( QListWidgetItem * ) ) );
136     }
137     tree_panel_l->addWidget( simple_tree );
138     simple_tree->show();
139
140     if( advanced_panel )
141     {
142         main_panel_l->removeWidget( advanced_panel );
143         advanced_panel->hide();
144     }
145     if( !simple_panel )
146         simple_panel = new SPrefsPanel( p_intf, main_panel, 0 );
147     main_panel_l->addWidget( simple_panel );
148     simple_panel->show();
149     adv_chk->hide();
150 }
151
152 PrefsDialog::~PrefsDialog()
153 {
154 }
155
156 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
157 {
158     int number = item->data( Qt::UserRole ).toInt();
159     if( simple_panel )
160     {
161         main_panel_l->removeWidget( simple_panel );
162         simple_panel->hide();
163         /* Don't do this once it works, you would loose all changes */
164         delete simple_panel;
165     }
166     simple_panel = new SPrefsPanel( p_intf, main_panel, number );
167     main_panel_l->addWidget( simple_panel );
168     simple_panel->show();
169 }
170
171 void PrefsDialog::changePanel( QTreeWidgetItem *item )
172 {
173     PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
174
175     if( advanced_panel )
176     {
177         main_panel_l->removeWidget( advanced_panel );
178         advanced_panel->hide();
179     }
180     if( !data->panel )
181     {
182         data->panel = new PrefsPanel( p_intf, main_panel , data,
183                                       adv_chk->isChecked() );
184     }
185     advanced_panel = data->panel;
186     main_panel_l->addWidget( advanced_panel );
187     advanced_panel->show();
188     setAdvanced( adv_chk->isChecked() );
189 }