1 /*****************************************************************************
2 * prefs_dialog.cpp : Preferences
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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. *****************************************************************************/
23 #include "dialogs/prefs_dialog.hpp"
24 #include "dialogs_provider.hpp"
25 #include "util/qvlcframe.hpp"
27 #include "components/preferences.hpp"
28 #include "components/simple_preferences.hpp"
31 #include <QHBoxLayout>
33 #include <QRadioButton>
34 #include <QVBoxLayout>
35 #include <QPushButton>
37 PrefsDialog *PrefsDialog::instance = NULL;
39 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
41 QGridLayout *main_layout = new QGridLayout(this);
42 setWindowTitle( qtr("Preferences" ) );
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 );
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 );
59 all->setChecked( true );
61 adv_chk = new QCheckBox("Advanced options");
66 advanced_panel = NULL;
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 );
73 main_layout->setColumnMinimumWidth( 0, 200 );
74 main_layout->setColumnStretch( 0, 1 );
75 main_layout->setColumnStretch( 1,3 );
79 connect( adv_chk, SIGNAL( toggled(bool) ),
80 this, SLOT( setAdvanced( bool ) ) );
81 setLayout( main_layout );
83 connect( small, SIGNAL( clicked() ), this, SLOT( setSmall()) );
84 connect( all, SIGNAL( clicked() ), this, SLOT( setAll()) );
87 void PrefsDialog::setAdvanced( bool advanced )
90 advanced_panel->setAdvanced( advanced );
93 void PrefsDialog::setAll()
97 tree_panel_l->removeWidget( simple_tree );
103 advanced_tree = new PrefsTree( p_intf, tree_panel );
104 connect( advanced_tree,
105 SIGNAL( currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *) ),
106 this, SLOT( changePanel( QTreeWidgetItem * ) ) );
108 tree_panel_l->addWidget( advanced_tree );
109 advanced_tree->show();
113 main_panel_l->removeWidget( simple_panel );
114 simple_panel->hide();
116 if( !advanced_panel )
117 advanced_panel = new PrefsPanel( main_panel );
118 main_panel_l->addWidget( advanced_panel );
119 advanced_panel->show();
122 void PrefsDialog::setSmall()
126 tree_panel_l->removeWidget( advanced_tree );
127 advanced_tree->hide();
131 simple_tree = new SPrefsCatList( p_intf, tree_panel );
132 connect( simple_tree,
133 SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem *) ),
134 this, SLOT( changeSimplePanel( QListWidgetItem * ) ) );
137 tree_panel_l->addWidget( simple_tree );
142 main_panel_l->removeWidget( advanced_panel );
143 advanced_panel->hide();
146 simple_panel = new SPrefsPanel( p_intf, main_panel, 0 );
147 main_panel_l->addWidget( simple_panel );
148 simple_panel->show();
151 PrefsDialog::~PrefsDialog()
155 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
159 main_panel_l->removeWidget( simple_panel );
160 simple_panel->hide();
161 /* Don't do this once it works, you would loose all changes */
164 simple_panel = new SPrefsPanel( p_intf, main_panel, 0 );
165 main_panel_l->addWidget( simple_panel );
166 simple_panel->show();
169 void PrefsDialog::changePanel( QTreeWidgetItem *item )
171 PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
175 main_panel_l->removeWidget( advanced_panel );
176 advanced_panel->hide();
180 data->panel = new PrefsPanel( p_intf, main_panel , data,
181 adv_chk->isChecked() );
183 advanced_panel = data->panel;
184 main_panel_l->addWidget( advanced_panel );
185 advanced_panel->show();
186 setAdvanced( adv_chk->isChecked() );