]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/preferences.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / qt4 / dialogs / preferences.cpp
index 1b9a9968bde02ad53a03498b6203da9cfbc02be0..204ad43aae50c2f48f80acc1cf60e26c12447886 100644 (file)
 #include <QCheckBox>
 #include <QScrollArea>
 #include <QMessageBox>
-
+#include <QDialogButtonBox>
 
 PrefsDialog *PrefsDialog::instance = NULL;
 
 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 {
-     QGridLayout *main_layout = new QGridLayout( this );
-     setWindowTitle( qtr( "Preferences" ) );
-     resize( 700, 650 );
-     setMaximumHeight( 650 );
-     setMaximumWidth( 700 );
-
-     tree_panel = new QWidget( 0 );
-     tree_panel_l = new QHBoxLayout;
-     tree_panel->setLayout( tree_panel_l );
-     main_panel = new QWidget( 0 );
-     main_panel_l = new QHBoxLayout;
-     main_panel->setLayout( main_panel_l );
-
-     // Choice for types
-     types = new QGroupBox( "Show settings" );
-     types->setAlignment( Qt::AlignHCenter );
-     QHBoxLayout *types_l = new QHBoxLayout(0);
-     types_l->setSpacing( 3 ); types_l->setMargin( 3 );
-     small = new QRadioButton( "Basic", types ); types_l->addWidget( small );
-     all = new QRadioButton( "All", types ); types_l->addWidget( all );
-     types->setLayout( types_l );
-     small->setChecked( true );
-
-     advanced_tree = NULL;
-     simple_tree = NULL;
-     simple_panel = NULL;
-     advanced_panel = NULL;
-
-     main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
-     main_layout->addWidget( types, 3, 0, 1, 1 );
-
-     main_layout->addWidget( main_panel, 0, 1, 4, 1 );
-
-     main_layout->setColumnMinimumWidth( 0, 150 );
-     main_layout->setColumnStretch( 0, 1 );
-     main_layout->setColumnStretch( 1,3 );
-
-     main_layout->setRowStretch( 2, 4);
-
-     setSmall();
-
-     QPushButton *save, *cancel, *reset;
-     QHBoxLayout *buttonsLayout = QVLCFrame::doButtons( this, NULL,
-                                      &save, _("Save"),
-                                      &cancel, _("Cancel"),
-                                      &reset, _( "Reset Preferences" ) );
-     main_layout->addLayout( buttonsLayout, 4, 0, 1 ,3 );
-     setLayout( main_layout );
-
-
-     BUTTONACT( save, save() );
-     BUTTONACT( cancel, cancel() );
-     BUTTONACT( reset, reset() );
-     BUTTONACT( small, setSmall() );
-     BUTTONACT( all, setAll() );
-
-     for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
+    QGridLayout *main_layout = new QGridLayout( this );
+    setWindowTitle( qtr( "Preferences" ) );
+    resize( 750, 550 );
+
+    /* Create Panels */
+    tree_panel = new QWidget( 0 );
+    tree_panel_l = new QHBoxLayout;
+    tree_panel->setLayout( tree_panel_l );
+    main_panel = new QWidget( 0 );
+    main_panel_l = new QHBoxLayout;
+    main_panel->setLayout( main_panel_l );
+
+    /* Choice for types */
+    types = new QGroupBox( "Show settings" );
+    types->setAlignment( Qt::AlignHCenter );
+    QHBoxLayout *types_l = new QHBoxLayout(0);
+    types_l->setSpacing( 3 ); types_l->setMargin( 3 );
+    small = new QRadioButton( qtr("Basic"), types );
+    types_l->addWidget( small );
+    all = new QRadioButton( qtr("All"), types ); types_l->addWidget( all );
+    types->setLayout( types_l );
+    small->setChecked( true );
+
+    /* Tree and panel initialisations */
+    advanced_tree = NULL;
+    simple_tree = NULL;
+    simple_panel = NULL;
+    advanced_panel = NULL;
+
+    /* Buttons */
+    QDialogButtonBox *buttonsBox = new QDialogButtonBox();
+    QPushButton *save = new QPushButton( qtr( "&Save" ) );
+    QPushButton *cancel = new QPushButton( qtr( "&Cancel" ) );
+    QPushButton *reset = new QPushButton( qtr( "&Reset Preferences" ) );
+
+    buttonsBox->addButton( save, QDialogButtonBox::AcceptRole );
+    buttonsBox->addButton( cancel, QDialogButtonBox::RejectRole );
+    buttonsBox->addButton( reset, QDialogButtonBox::ActionRole );
+
+    /* Layout  */
+    main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
+    main_layout->addWidget( types, 3, 0, 2, 1 );
+    main_layout->addWidget( main_panel, 0, 1, 4, 1 );
+    main_layout->addWidget( buttonsBox, 4, 1, 1 ,2 );
+
+    main_layout->setColumnMinimumWidth( 0, 150 );
+    main_layout->setColumnStretch( 0, 1 );
+    main_layout->setColumnStretch( 1, 3 );
+
+    main_layout->setRowStretch( 2, 4);
+
+    setLayout( main_layout );
+
+    /* Margins */
+    tree_panel_l->setMargin( 1 );
+    main_panel_l->setMargin( 3 );
+
+    if( config_GetInt( p_intf, "qt-advanced-pref") == 1 )
+    {
+        setAll();
+    }
+    else
+    {
+        setSmall();
+    }
+
+    BUTTONACT( save, save() );
+    BUTTONACT( cancel, cancel() );
+    BUTTONACT( reset, reset() );
+    BUTTONACT( small, setSmall() );
+    BUTTONACT( all, setAll() );
+
+    for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
 }
 
 void PrefsDialog::setAll()
@@ -129,6 +145,7 @@ void PrefsDialog::setAll()
     if( !advanced_panel )
          advanced_panel = new PrefsPanel( main_panel );
     main_panel_l->addWidget( advanced_panel );
+    all->setChecked( true );
     advanced_panel->show();
 }
 
@@ -157,6 +174,7 @@ void PrefsDialog::setSmall()
     if( !simple_panel )
         simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
     main_panel_l->addWidget( simple_panel );
+    small->setChecked( true );
     simple_panel->show();
 }
 
@@ -226,6 +244,12 @@ void PrefsDialog::showModulePrefs( char *psz_module )
 }
 
 void PrefsDialog::save()
+{
+    apply();
+    hide();
+}
+
+void PrefsDialog::apply()
 {
     if( small->isChecked() && simple_tree )
     {
@@ -235,7 +259,19 @@ void PrefsDialog::save()
     else if( all->isChecked() && advanced_tree )
         advanced_tree->applyAll();
     config_SaveConfigFile( p_intf, NULL );
-    hide();
+
+    /* Delete the other panel in order to force its reload after clicking
+       on apply - UGLY but will work for now. */
+    if( simple_panel && simple_panel->isVisible() && advanced_panel )
+    {
+        delete advanced_panel;
+        advanced_panel = NULL;
+    }
+    if( advanced_panel && advanced_panel->isVisible() && simple_panel )
+    {
+        delete simple_panel;
+        simple_panel = NULL;
+    }
 }
 
 void PrefsDialog::cancel()
@@ -263,7 +299,6 @@ void PrefsDialog::reset()
     if ( ret == QMessageBox::Ok )
     {
         config_ResetAll( p_intf );
-        // TODO reset changes ?
         config_SaveConfigFile( p_intf, NULL );
     }
 }