[vlc-devel] commit: Qt: profiles for the interface toolbar edition ( Jean-Baptiste Kempf )

git version control git at videolan.org
Sun Feb 15 23:47:01 CET 2009


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sun Feb 15 23:39:40 2009 +0100| [c3338de60c0680338089477ec040039f6610c6c5] | committer: Jean-Baptiste Kempf 

Qt: profiles for the interface toolbar edition

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c3338de60c0680338089477ec040039f6610c6c5
---

 modules/gui/qt4/dialogs/toolbar.cpp  |   97 +++++++++++++++++++++++++++++++++-
 modules/gui/qt4/dialogs/toolbar.hpp  |    8 +++-
 modules/gui/qt4/dialogs_provider.cpp |    2 +-
 3 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt4/dialogs/toolbar.cpp b/modules/gui/qt4/dialogs/toolbar.cpp
index 5ee640e..ca67c1b 100644
--- a/modules/gui/qt4/dialogs/toolbar.cpp
+++ b/modules/gui/qt4/dialogs/toolbar.cpp
@@ -39,6 +39,7 @@
 
 #include <QDragEnterEvent>
 #include <QDialogButtonBox>
+#include <QInputDialog>
 
 ToolbarEditDialog *ToolbarEditDialog::instance = NULL;
 
@@ -134,6 +135,37 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf)
 
     mainLayout->addWidget( FSCToolbarBox, 3, 0, 1, -1 );
 
+    /* Profile */
+    QGroupBox *profileBox = new QGroupBox( qtr( "Profile" ), this );
+    QGridLayout *profileBoxLayout = new QGridLayout( profileBox );
+
+    profileCombo = new QComboBox;
+    QLabel *profileLabel = new QLabel( qtr( "Select profile:" ), this );
+
+    QToolButton *newButton = new QToolButton;
+    newButton->setIcon( QIcon( ":/new" ) );
+    QToolButton *deleteButton = new QToolButton;
+    deleteButton->setIcon( QIcon( ":/clear" ) );
+    deleteButton->setToolTip( qtr( "Delete the current profile" ) );
+
+    profileBoxLayout->addWidget( profileLabel, 0, 0 );
+    profileBoxLayout->addWidget( profileCombo, 0, 1 );
+    profileBoxLayout->addWidget( newButton, 0, 2 );
+    profileBoxLayout->addWidget( deleteButton, 0, 3 );
+
+    mainLayout->addWidget( profileBox, 4, 0, 1, -1 );
+
+    /* Fill combos */
+    int i_size = getSettings()->beginReadArray( "ToolbarProfiles" );
+    for( int i = 0; i < i_size; i++ )
+    {
+        getSettings()->setArrayIndex(i);
+        profileCombo->addItem( getSettings()->value( "ProfileName" ).toString(),
+                               getSettings()->value( "Value" ).toString() );
+    }
+    getSettings()->endArray();
+    profileCombo->setCurrentIndex( -1 );
+
     /* Buttons */
     QDialogButtonBox *okCancel = new QDialogButtonBox;
     QPushButton *okButton = new QPushButton( qtr( "Cl&ose" ), this );
@@ -142,14 +174,62 @@ ToolbarEditDialog::ToolbarEditDialog( intf_thread_t *_p_intf)
     okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
     okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
 
+    BUTTONACT( deleteButton, deleteProfile() );
+    BUTTONACT( newButton, newProfile() );
+    CONNECT( profileCombo, currentIndexChanged( int ), this, changeProfile( int ) );
     BUTTONACT( okButton, close() );
     BUTTONACT( cancelButton, cancel() );
-    mainLayout->addWidget( okCancel, 4, 2 );
+    mainLayout->addWidget( okCancel, 5, 2 );
 }
 
 
 ToolbarEditDialog::~ToolbarEditDialog()
 {
+    getSettings()->beginWriteArray( "ToolbarProfiles" );
+    for( int i = 0; i < profileCombo->count(); i++ )
+    {
+        getSettings()->setArrayIndex(i);
+        getSettings()->setValue( "ProfileName", profileCombo->itemText( i ) );
+        getSettings()->setValue( "Value", profileCombo->itemData( i ) );
+    }
+    getSettings()->endArray();
+}
+
+void ToolbarEditDialog::newProfile()
+{
+    bool ok;
+    QString name =  QInputDialog::getText( this, qtr( "Profile Name" ),
+                 qtr( "Please enter the new profile name." ), QLineEdit::Normal, 0, &ok );
+    if( !ok ) return;
+
+    QString temp = QString::number( positionCombo->currentIndex() );
+    temp += "|" + controller1->getValue();
+    temp += "|" + controller2->getValue();
+    temp += "|" + controllerA->getValue();
+    temp += "|" + controller->getValue();
+    temp += "|" + controllerFSC->getValue();
+
+    profileCombo->addItem( name, temp );
+    profileCombo->setCurrentIndex( profileCombo->count() - 1 );
+}
+
+void ToolbarEditDialog::deleteProfile()
+{
+    profileCombo->removeItem( profileCombo->currentIndex() );
+}
+
+void ToolbarEditDialog::changeProfile( int i )
+{
+    QStringList qs_list = profileCombo->itemData( i ).toString().split( "|" );
+    if( qs_list.count() < 6 )
+        return;
+
+    positionCombo->setCurrentIndex( positionCombo->findData( qs_list[0].toInt() ) );
+    controller1->resetLine( qs_list[1] );
+    controller2->resetLine( qs_list[2] );
+    controllerA->resetLine( qs_list[3] );
+    controller->resetLine( qs_list[4] );
+    controllerFSC->resetLine( qs_list[5] );
 }
 
 void ToolbarEditDialog::close()
@@ -384,6 +464,21 @@ DroppingController::DroppingController( intf_thread_t *_p_intf,
     parseAndCreate( line, controlLayout );
 }
 
+void DroppingController::resetLine( QString line )
+{
+    hide();
+    QLayoutItem *child;
+    int i =0;
+    while( (child = controlLayout->takeAt( 0 ) ) != 0 )
+    {
+        child->widget()->hide();
+        delete child;
+    }
+
+    parseAndCreate( line, controlLayout );
+    show();
+}
+
 /* Overloading the AbstractController one, because we don't manage the
    Spacing items in the same ways */
 void DroppingController::createAndAddWidget( QBoxLayout *controlLayout,
diff --git a/modules/gui/qt4/dialogs/toolbar.hpp b/modules/gui/qt4/dialogs/toolbar.hpp
index 31da994..010c907 100644
--- a/modules/gui/qt4/dialogs/toolbar.hpp
+++ b/modules/gui/qt4/dialogs/toolbar.hpp
@@ -57,6 +57,8 @@ public:
             instance = new ToolbarEditDialog( p_intf );
         return instance;
     }
+    static void killInstance()
+    { if( instance ) delete instance; instance = NULL;}
     virtual ~ToolbarEditDialog();
     int getOptions() { return flatBox->isChecked() * WIDGET_FLAT +
                         bigBox->isChecked() * WIDGET_BIG +
@@ -66,13 +68,16 @@ private:
     static ToolbarEditDialog *instance;
 
     QCheckBox *flatBox, *bigBox, *shinyBox;
-    QComboBox *positionCombo;
+    QComboBox *positionCombo, *profileCombo;
 
     WidgetListing *widgetListing;
     DroppingController *controller1, *controller2, *controllerA;
     DroppingController *controllerFSC, *controller;
 
 private slots:
+    void newProfile();
+    void deleteProfile();
+    void changeProfile( int );
     void cancel();
     void close();
 };
@@ -85,6 +90,7 @@ public:
     QString getValue();
     virtual ~DroppingController();
 
+    void resetLine( QString );
 protected:
     virtual void createAndAddWidget( QBoxLayout *controlLayout, int i_index,
             buttonType_e i_type, int i_option );
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index c4485d5..0214f33 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -80,7 +80,6 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
 
 DialogsProvider::~DialogsProvider()
 {
-    msg_Dbg( p_intf, "Destroying the Dialog Provider" );
     PlaylistDialog::killInstance();
     MediaInfoDialog::killInstance();
     MessagesDialog::killInstance();
@@ -90,6 +89,7 @@ DialogsProvider::~DialogsProvider()
 #ifdef UPDATE_CHECK
     UpdateDialog::killInstance();
 #endif
+    ToolbarEditDialog::killInstance();
 
     delete menusMapper;
     delete menusUpdateMapper;




More information about the vlc-devel mailing list