[vlc-devel] [PATCH] UI: Alternative QT Styles. QT style chooser dialog.

Francois Cartegnie fcvlcdev at free.fr
Thu Jun 4 21:07:30 CEST 2009


---
 modules/gui/qt4/dialogs/toolbar.cpp |   88 ++++++++++++++++++++++++++++------
 modules/gui/qt4/dialogs/toolbar.hpp |    3 +-
 modules/gui/qt4/qt4.cpp             |    7 ++-
 3 files changed, 80 insertions(+), 18 deletions(-)

diff --git a/modules/gui/qt4/dialogs/toolbar.cpp b/modules/gui/qt4/dialogs/toolbar.cpp
index 2ca4f79..fd5dd3c 100644
--- a/modules/gui/qt4/dialogs/toolbar.cpp
+++ b/modules/gui/qt4/dialogs/toolbar.cpp
@@ -37,20 +37,33 @@
 #include <QComboBox>
 #include <QListWidget>
 
+#include <QStyleFactory>
+
 #include <QDragEnterEvent>
 #include <QDialogButtonBox>
 #include <QInputDialog>
 
+
 ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
                   : QVLCDialog( _w,  _p_intf )
 {
-    setWindowTitle( qtr( "Toolbars Editor" ) );
-    QGridLayout *mainLayout = new QGridLayout( this );
-    setMinimumWidth( 600 );
+    setWindowTitle( qtr( "Interface customization" ) );    
     setAttribute( Qt::WA_DeleteOnClose );
 
+    QVBoxLayout *windowlayout = new QVBoxLayout( this );
+    QTabWidget *tabsWidget = new QTabWidget( this );
+    windowlayout->addWidget( tabsWidget );
+
+    /* Toolbar tab */
+    QWidget *firstTab = new QWidget( tabsWidget );
+    firstTab->setMinimumWidth( 600 );
+    firstTab->setSizePolicy( QSizePolicy::Preferred,
+                              QSizePolicy::MinimumExpanding );
+    QGridLayout *firstTabLayout = new QGridLayout( firstTab );
+    firstTab->setLayout( firstTabLayout );
+
     /* main GroupBox */
-    QGroupBox *widgetBox = new QGroupBox( qtr( "Toolbar Elements") , this );
+    QGroupBox *widgetBox = new QGroupBox( qtr( "Toolbar Elements") , firstTab );
     widgetBox->setSizePolicy( QSizePolicy::Preferred,
                               QSizePolicy::MinimumExpanding );
     QGridLayout *boxLayout = new QGridLayout( widgetBox );
@@ -65,11 +78,11 @@ ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
     boxLayout->addWidget( flatBox, 1, 1 );
     boxLayout->addWidget( bigBox, 1, 2 );
     boxLayout->addWidget( shinyBox, 2, 1 );
-    mainLayout->addWidget( widgetBox, 0, 0, 5, 1 );
+    firstTabLayout->addWidget( widgetBox, 0, 0, 5, 1 );
 
 
     /* Main ToolBar */
-    QGroupBox *mainToolbarBox = new QGroupBox( qtr( "Main Toolbar" ), this );
+    QGroupBox *mainToolbarBox = new QGroupBox( qtr( "Main Toolbar" ), firstTab );
     QGridLayout *mainTboxLayout = new QGridLayout( mainToolbarBox );
 
     QLabel *label = new QLabel( qtr( "Toolbar position:" ) );
@@ -107,10 +120,10 @@ ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
     mainTboxLayout->addWidget( advLabel, 3, 0, 1, 2 );
     mainTboxLayout->addWidget( controllerA, 3, 2, 1, 1 );
 
-    mainLayout->addWidget( mainToolbarBox, 0, 1, 1, -1 );
+    firstTabLayout->addWidget( mainToolbarBox, 0, 1, 1, -1 );
 
     /* TimeToolBar */
-    QGroupBox *timeToolbarBox = new QGroupBox( qtr( "Time Toolbar" ) , this );
+    QGroupBox *timeToolbarBox = new QGroupBox( qtr( "Time Toolbar" ) , firstTab );
     QGridLayout *timeTboxLayout = new QGridLayout( timeToolbarBox );
 
     QString line = getSettings()->value( "MainWindow/InputToolbar",
@@ -119,27 +132,28 @@ ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
             this );
     timeTboxLayout->addWidget( controller, 0, 0, 1, -1 );
 
-    mainLayout->addWidget( timeToolbarBox, 1, 1, 1, -1 );
+    firstTabLayout->addWidget( timeToolbarBox, 1, 1, 1, -1 );
 
     /* FSCToolBar */
     QGroupBox *FSCToolbarBox = new QGroupBox( qtr( "Fullscreen Controller" ),
-                                              this );
+                                              firstTab );
     QGridLayout *FSCTboxLayout = new QGridLayout( FSCToolbarBox );
 
     QString lineFSC = getSettings()->value( "MainWindow/FSCtoolbar",
                                             FSC_TB_DEFAULT ).toString();
     controllerFSC = new DroppingController( p_intf,
-            lineFSC, this );
+            lineFSC, firstTab );
     FSCTboxLayout->addWidget( controllerFSC, 0, 0, 1, -1 );
 
-    mainLayout->addWidget( FSCToolbarBox, 2, 1, 1, -1 );
+    firstTabLayout->addWidget( FSCToolbarBox, 2, 1, 1, -1 );
 
     /* Profile */
-    QGroupBox *profileBox = new QGroupBox( qtr( "Profile" ), this );
+    QGroupBox *profileBox = new QGroupBox( qtr( "Profile" ), firstTab );
     QGridLayout *profileBoxLayout = new QGridLayout( profileBox );
 
     profileCombo = new QComboBox;
-    QLabel *profileLabel = new QLabel( qtr( "Select profile:" ), this );
+    QLabel *profileLabel = new QLabel( qtr( "Select profile:" ), firstTab );
+    profileLabel->setAlignment( Qt::AlignRight );
 
     QToolButton *newButton = new QToolButton;
     newButton->setIcon( QIcon( ":/new" ) );
@@ -152,7 +166,7 @@ ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
     profileBoxLayout->addWidget( newButton, 0, 2 );
     profileBoxLayout->addWidget( deleteButton, 0, 3 );
 
-    mainLayout->addWidget( profileBox, 3, 1, 1, -1 );
+    firstTabLayout->addWidget( profileBox, 3, 1, 1, -1 );
 
     /* Fill combos */
     int i_size = getSettings()->beginReadArray( "ToolbarProfiles" );
@@ -178,6 +192,31 @@ ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
     }
     profileCombo->setCurrentIndex( -1 );
 
+    /* filler */
+    firstTabLayout->addWidget( new QWidget(this), 5, 2 );
+
+    tabsWidget->addTab( firstTab, qtr( "Toolbars editor" ) );
+
+    /* Styles tab */
+    QWidget *secondTab = new QTabWidget( tabsWidget );
+    QGridLayout *secondTabLayout = new QGridLayout( tabsWidget );
+    secondTab->setLayout( secondTabLayout );
+
+    stylesCombo = new QComboBox( secondTab );
+    stylesCombo->addItem( qtr( "Default (needs restart)" ), "" );
+    stylesCombo->addItems( QStyleFactory::keys() );
+    QString configvalue = getSettings()->value( "MainWindow/QTStyle", "" ).toString();
+    stylesCombo->setCurrentIndex( stylesCombo->findText( configvalue ) );
+    stylesCombo->insertSeparator( 1 );
+    CONNECT( stylesCombo, currentIndexChanged( int ), this, changeStyle( int ) );
+
+    label = new QLabel( qtr( "Force window style:") , secondTab );
+    label->setAlignment( Qt::AlignRight );
+    secondTabLayout->addWidget( label, 0, 0 );
+    secondTabLayout->addWidget( stylesCombo, 0, 1, 1, 2 );
+
+    tabsWidget->addTab( secondTab, qtr( "Window styles" ) );
+
     /* Buttons */
     QDialogButtonBox *okCancel = new QDialogButtonBox;
     QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
@@ -191,7 +230,7 @@ ToolbarEditDialog::ToolbarEditDialog( QWidget *_w, intf_thread_t *_p_intf)
     CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
     BUTTONACT( okButton, close() );
     BUTTONACT( cancelButton, cancel() );
-    mainLayout->addWidget( okCancel, 5, 2 );
+    windowlayout->addWidget( okCancel );
 }
 
 
@@ -244,11 +283,28 @@ void ToolbarEditDialog::changeProfile( int i )
     controllerFSC->resetLine( qs_list[5] );
 }
 
+void ToolbarEditDialog::changeStyle( int i )
+{
+    QString s_style = stylesCombo->itemText( i );
+    QApplication::setStyle( s_style );
+
+    /* force refresh on all widgets */
+    QWidgetList widgets = QApplication::allWidgets();
+    QWidgetList::iterator it;
+    it = widgets.begin();
+    while( it != widgets.end() ) {
+        (*it)->update();
+        it++;
+    };
+}
+
 void ToolbarEditDialog::close()
 {
     msg_Dbg( p_intf, "Close and save" );
     getSettings()->setValue( "MainWindow/ToolbarPos",
             positionCombo->itemData( positionCombo->currentIndex() ).toInt() );
+    getSettings()->setValue( "MainWindow/QTStyle",
+            stylesCombo->itemText( stylesCombo->currentIndex() ) );
     getSettings()->setValue( "MainWindow/MainToolbar1", controller1->getValue() );
     getSettings()->setValue( "MainWindow/MainToolbar2", controller2->getValue() );
     getSettings()->setValue( "MainWindow/AdvToolbar", controllerA->getValue() );
diff --git a/modules/gui/qt4/dialogs/toolbar.hpp b/modules/gui/qt4/dialogs/toolbar.hpp
index 84dbeb3..f45c148 100644
--- a/modules/gui/qt4/dialogs/toolbar.hpp
+++ b/modules/gui/qt4/dialogs/toolbar.hpp
@@ -70,7 +70,7 @@ public:
 private:
 
     QCheckBox *flatBox, *bigBox, *shinyBox;
-    QComboBox *positionCombo, *profileCombo;
+    QComboBox *positionCombo, *profileCombo, *stylesCombo;
 
     WidgetListing *widgetListing;
     DroppingController *controller1, *controller2, *controllerA;
@@ -80,6 +80,7 @@ private slots:
     void newProfile();
     void deleteProfile();
     void changeProfile( int );
+    void changeStyle( int );
     void cancel();
     void close();
 };
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index e350775..9f551c0 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -360,10 +360,10 @@ static void *Thread( void *obj )
         argv[argc] = NULL;
     }
 #endif
+    
     QVLCApp app( argc, argv );
     p_intf->p_sys->p_app = &app;
 
-
     /* All the settings are in the .conf/.ini style */
     p_intf->p_sys->mainSettings = new QSettings(
 #ifdef WIN32
@@ -456,6 +456,11 @@ static void *Thread( void *obj )
         free( psz_path );
     }
 
+    /* Loads and tries to apply the preferred QStyle */
+    QString s_style = getSettings()->value( "MainWindow/QTStyle", "" ).toString();
+    if ( s_style.compare("") != 0 )
+        QApplication::setStyle( s_style );
+
     /* Launch */
     app.exec();
 
-- 
1.6.2.4




More information about the vlc-devel mailing list