]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/prefs_dialog.cpp
qt4/*: buildsytem fix + cosmetic+ copyright dates + svn Id
[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 "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( "Basic", 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
64      all->setChecked( true );
65
66      main_layout->addLayout( layout );
67      adv_chk = new QCheckBox("Advanced options");
68      main_layout->addWidget( adv_chk );
69
70      setAll();
71
72      connect( adv_chk, SIGNAL( toggled(bool) ),
73               this, SLOT( setAdvanced( bool ) ) );
74      setLayout( main_layout );
75
76      connect( small, SIGNAL( clicked() ), this, SLOT( setSmall()) );
77      connect( all, SIGNAL( clicked() ), this, SLOT( setAll()) );
78 }
79
80 void PrefsDialog::setAdvanced( bool advanced )
81 {
82     if( advanced_panel )
83         advanced_panel->setAdvanced( advanced );
84 }
85
86 void PrefsDialog::setAll()
87 {
88     while( (vertical->takeAt(0)) != 0  ) {}
89     if( simple_tree )
90         simple_tree->hide();
91
92     if( !advanced_tree )
93     {
94          advanced_tree = new PrefsTree( p_intf, this );
95          connect( advanced_tree,
96           SIGNAL( currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *) ),
97           this, 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 }