]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt4 : SimplePrefs: various fixes, remove some widgets, uniformity, cleaning and hidin...
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <QListWidget>
26 #include <QListWidgetItem>
27 #include <QString>
28 #include <QFont>
29
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
32 #include "qt4.hpp"
33
34 #include <vlc_config_cat.h>
35 #include <assert.h>
36
37 #include "pixmaps/hotkeys_50x50.xpm"
38 #include "pixmaps/audio_50x50.xpm"
39 #include "pixmaps/input_and_codecs_50x50.xpm"
40 #include "pixmaps/interface_50x50.xpm"
41 //#include "pixmaps/playlist_50x50.xpm"
42 #include "pixmaps/subtitles_50x50.xpm"
43 #include "pixmaps/video_50x50.xpm"
44
45 #include "ui/sprefs_audio.h"
46 #include "ui/sprefs_input.h"
47 #include "ui/sprefs_video.h"
48 #include "ui/sprefs_subtitles.h"
49 #include "ui/sprefs_hotkeys.h"
50 //#include "ui/sprefs_playlist.h"
51 #include "ui/sprefs_interface.h"
52
53 #define ITEM_HEIGHT 50
54
55 /*********************************************************************
56  * The List of categories
57  *********************************************************************/
58 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
59                                   QListWidget( _parent ), p_intf( _p_intf )
60 {
61     setIconSize( QSize( ITEM_HEIGHT,ITEM_HEIGHT ) );
62     setAlternatingRowColors( true );
63
64 #define ADD_CATEGORY( id, label, icon )                             \
65     addItem( label );                                               \
66     item( id )->setIcon( QIcon( QPixmap( icon ) ) );                \
67     item( id )->setData( Qt::UserRole, qVariantFromValue( (int)id ) );
68
69     ADD_CATEGORY( SPrefsVideo, qtr("Video"), video_50x50_xpm );
70     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), audio_50x50_xpm );
71     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
72                   input_and_codecs_50x50_xpm );
73     ADD_CATEGORY( SPrefsInterface, qtr("Interface"), interface_50x50_xpm );
74     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"), subtitles_50x50_xpm );
75     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), hotkeys_50x50_xpm );
76
77     setCurrentRow( SPrefsInterface );
78 }
79
80 /*********************************************************************
81  * The Panels
82  *********************************************************************/
83 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
84                           int number ) : QWidget( _parent ), p_intf( _p_intf )
85 {
86     module_config_t *p_config;
87     ConfigControl *control;
88
89 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
90             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
91             if( p_config )                                                \
92             {                                                             \
93                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
94                            p_config, label, ui.qcontrol, false );         \
95                 controls.append( control );                               \
96             }
97
98 #define START_SPREFS_CAT( name , label )    \
99         case SPrefs ## name:                \
100         {                                   \
101             Ui::SPrefs ## name ui;          \
102             ui.setupUi( panel );            \
103             panel_label->setText( qtr( label ) );
104
105 #define END_SPREFS_CAT      \
106             break;          \
107         }
108
109     QVBoxLayout *panel_layout = new QVBoxLayout();
110     QWidget *panel = new QWidget();
111
112     // Title Label
113     QLabel *panel_label = new QLabel;
114     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
115     labelFont.setPointSize( labelFont.pointSize() + 4 );
116     labelFont.setBold( true );
117     panel_label->setFont( labelFont );
118
119     // Title <hr>
120     QFrame *title_line = new QFrame;
121     title_line->setFrameShape(QFrame::HLine);
122     title_line->setFrameShadow(QFrame::Sunken);
123
124     switch( number )
125     {
126         START_SPREFS_CAT( Video , "General video settings" );
127          #ifndef WIN32
128             ui.directXBox->setVisible( false );
129          #endif
130             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
131
132             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
133             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
134             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
135             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
136
137             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
138
139             CONFIG_GENERIC( "snapshot-path", String, NULL,
140             snapshotsDirectory ); /* FIXME -> use file instead of string */
141             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
142             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
143                             snapshotsSequentialNumbering );
144             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
145                             snapshotsFormat );
146
147         END_SPREFS_CAT;
148
149         START_SPREFS_CAT( Audio,  "General audio settings" );
150          #ifndef WIN32
151             ui.DirectXLabel->setVisible( false );
152             ui.DirectXDevice->setVisible( false );
153          #endif
154          #ifdef WIN32
155             ui.OSSBrowse->hide();
156             ui.OSSDevice->hide();
157             ui.OSSLabel->hide();
158             ui.alsaDevice->hide();
159             ui.alsaLabel->hide();
160          #endif
161             CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
162
163         END_SPREFS_CAT;
164
165         START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings"  );
166
167         END_SPREFS_CAT;
168
169         START_SPREFS_CAT( Interface, "Interfaces settings" );
170
171             CONFIG_GENERIC( "language", StringList, NULL, language );
172
173         END_SPREFS_CAT;
174
175         START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
176
177             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
178             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
179             CONFIG_GENERIC( "freetype-font", String, NULL, font ); /* FIXME -> use file instead of string */
180             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
181             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
182                             fontSize );
183             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
184
185         END_SPREFS_CAT;
186
187         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
188         END_SPREFS_CAT;
189         }
190
191     panel_layout->addWidget(panel_label);
192     panel_layout->addWidget(title_line);
193     panel_layout->addWidget( panel );
194     panel_layout->addStretch( 2 );
195
196     this->setLayout(panel_layout);
197 }
198
199 void SPrefsPanel::apply()
200 {
201     QList<ConfigControl *>::Iterator i;
202     for( i = controls.begin() ; i != controls.end() ; i++ )
203     {
204         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
205         c->doApply( p_intf );
206     }
207 }
208
209 void SPrefsPanel::clean()
210 {}