]> git.sesse.net Git - vlc/commitdiff
Qt4 - Preferences. Introduction of a checkBoxListItem struct to handle (key, value...
authorJean-Baptiste Kempf <jb@videolan.org>
Mon, 30 Apr 2007 00:44:18 +0000 (00:44 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 30 Apr 2007 00:44:18 +0000 (00:44 +0000)
modules/gui/qt4/components/preferences_widgets.cpp
modules/gui/qt4/components/preferences_widgets.hpp

index 5b40b3142d0d4f605b91ac8f6e81a2ec0f8bcf88..5c2f98d108a960b245d286795f61b174c6acedb5 100644 (file)
@@ -490,10 +490,10 @@ ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
     finish( bycat );
 
     int boxline = 0;
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
          it != modules.end(); it++ )
     {
-        layoutGroupBox->addWidget( *it, boxline++, 0 );
+        layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
     }
     layoutGroupBox->addWidget( text, boxline, 0 );
 
@@ -507,6 +507,8 @@ ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
     {
         l->addWidget( groupBox, line, 0, 1, -1 );
     }
+
+    text->setToolTip( formatTooltip( qfu( p_item->psz_longtext) ) );
 }
 #if 0
 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
@@ -521,7 +523,7 @@ ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
 
 ModuleListConfigControl::~ModuleListConfigControl()
 {
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
          it != modules.end(); it++ )
     {
         delete *it;
@@ -530,6 +532,25 @@ ModuleListConfigControl::~ModuleListConfigControl()
     delete text;
 }
 
+#define CHECKBOX_LISTS \
+{ \
+       QCheckBox *cb = new QCheckBox( qfu( p_parser->psz_longname ) );\
+       checkBoxListItem *cbl = new checkBoxListItem; \
+\
+       CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
+       cb->setToolTip( formatTooltip( qfu(p_parser->psz_longname)) );\
+       cbl->checkBox = cb; \
+\
+       int i = -1; \
+       while( p_parser->pp_shortcuts[++i] != NULL); \
+       i--; \
+\
+       cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
+                                 : p_parser->psz_object_name ); \
+       modules.push_back( cbl ); \
+}
+
 void ModuleListConfigControl::finish( bool bycat )
 {
     vlc_list_t *p_list;
@@ -552,29 +573,21 @@ void ModuleListConfigControl::finish( bool bycat )
                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
                     p_config->value.i == p_item->min.i )
                 {
-                    QCheckBox *cb =
-                        new QCheckBox( qfu( p_parser->psz_object_name ) );
-                    CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );
-                    cb->setToolTip(
-                            formatTooltip( qfu(p_parser->psz_longname)) );
-                    modules.push_back( cb );
-                }
+                    CHECKBOX_LISTS;
+               }
             }
         }
         else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
         {
-            QCheckBox *cb =
-                new QCheckBox( qfu( p_parser->psz_object_name ) );
-                    CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );
-            cb->setToolTip( formatTooltip(qfu(p_parser->psz_longname)) );
-            modules.push_back( cb );
-        }
+            CHECKBOX_LISTS;
+       }
     }
     vlc_list_release( p_list );
     text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( groupBox )
         groupBox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
+#undef CHECKBOX_LISTS
 
 QString ModuleListConfigControl::getValue()
 {
@@ -583,20 +596,20 @@ QString ModuleListConfigControl::getValue()
 
 void ModuleListConfigControl::hide()
 {
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
          it != modules.end(); it++ )
     {
-        (*it)->hide();
+        (*it)->checkBox->hide();
     }
     groupBox->hide();
 }
 
 void ModuleListConfigControl::show()
 {
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
          it != modules.end(); it++ )
     {
-        (*it)->show();
+        (*it)->checkBox->show();
     }
     groupBox->show();
 }
@@ -607,19 +620,19 @@ void ModuleListConfigControl::onUpdate( int value )
     text->clear();
     bool first = true;
 
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
          it != modules.end(); it++ )
     {
-        if( (*it)->isChecked() )
+        if( (*it)->checkBox->isChecked() )
         {
             if( first )
             {
-                text->setText( text->text() + (*it)->text() );
+                text->setText( text->text() + (*it)->psz_module );
                 first = false;
             }
             else
             {
-                text->setText( text->text() + ":" + (*it)->text() );
+                text->setText( text->text() + ":" + (*it)->psz_module );
             }
         }
     }
index 7881261f23e37b9241e6ff269ad2440f19aad4b3..3666f22e71a6d6fb829ae236b2129bda1e1816ff 100644 (file)
@@ -326,6 +326,11 @@ private:
     QComboBox *combo;
 };
 
+struct checkBoxListItem {
+    QCheckBox *checkBox;
+    char *psz_module;
+};
+
 class ModuleListConfigControl : public VStringConfigControl
 {
     Q_OBJECT;
@@ -342,7 +347,7 @@ public slots:
     void onUpdate( int value );
 private:
     void finish( bool );
-    QVector<QCheckBox*> modules;
+    QVector<checkBoxListItem*> modules;
     QGroupBox *groupBox;
     QLineEdit *text;
 };