]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/preferences_widgets.cpp
Qt: ConfigControl: unify and fix visibility changes.
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
index 88ddda2c582b6a91c067468867cd8272567930ff..32e6bdd5d5de8d4f44f198db491de8569714a3b3 100644 (file)
@@ -39,6 +39,7 @@
 #include <vlc_keys.h>
 #include <vlc_intf_strings.h>
 #include <vlc_modules.h>
+#include <vlc_plugin.h>
 
 #include <QString>
 #include <QVariant>
@@ -219,6 +220,7 @@ StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
 
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
         layout->addWidget( text, LAST_COLUMN );
@@ -243,6 +245,8 @@ StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
     finish( );
 }
 
+int VStringConfigControl::getType() const { return CONFIG_ITEM_STRING; }
+
 void StringConfigControl::finish()
 {
     text->setText( qfu(p_item->value.psz) );
@@ -278,6 +282,7 @@ FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
 
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label, 0 );
         layout->insertSpacing( 1, 10 );
@@ -373,6 +378,7 @@ FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
     font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
     if( !_p_layout )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label, 0 );
         layout->addWidget( font, 1 );
@@ -421,6 +427,7 @@ StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
     finish( p_module_config );
     if( !l )
     {
+        widget = new QWidget( _parent );
         l = new QGridLayout();
         l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
         widget->setLayout( l );
@@ -595,6 +602,7 @@ ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
     finish( bycat );
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
         widget->setLayout( layout );
@@ -703,6 +711,7 @@ ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
 
     if( !l )
     {
+        widget = new QWidget( _parent );
         QVBoxLayout *layout = new QVBoxLayout();
         layout->addWidget( groupBox, line, 0 );
         widget->setLayout( layout );
@@ -813,21 +822,14 @@ QString ModuleListConfigControl::getValue() const
     return text->text();
 }
 
-void ModuleListConfigControl::hide()
+void ModuleListConfigControl::changeVisibility( bool b )
 {
     foreach ( checkBoxListItem *it, modules )
-        it->checkBox->hide();
-    groupBox->hide();
+        it->checkBox->setVisible( b );
+    groupBox->setVisible( b );
+    ConfigControl::changeVisibility( b );
 }
 
-void ModuleListConfigControl::show()
-{
-    foreach ( checkBoxListItem *it, modules )
-        it->checkBox->show();
-    groupBox->show();
-}
-
-
 void ModuleListConfigControl::onUpdate()
 {
     text->clear();
@@ -875,6 +877,7 @@ IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
 
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
         widget->setLayout( layout );
@@ -917,6 +920,8 @@ int IntegerConfigControl::getValue() const
     return spin->value();
 }
 
+int VIntConfigControl::getType() const { return CONFIG_ITEM_INTEGER; }
+
 /********* Integer range **********/
 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
                                             module_config_t *_p_item,
@@ -984,6 +989,7 @@ IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
     finish( p_module_config );
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
         widget->setLayout( layout );
@@ -1101,6 +1107,7 @@ BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
 
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( checkbox, 0 );
         widget->setLayout( layout );
@@ -1122,6 +1129,8 @@ BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
     finish();
 }
 
+int BoolConfigControl::getType() const { return CONFIG_ITEM_BOOL; }
+
 void BoolConfigControl::finish()
 {
     checkbox->setChecked( p_item->value.i );
@@ -1147,6 +1156,7 @@ ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
 
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label, 0 ); layout->addWidget( color_but, LAST_COLUMN );
         widget->setLayout( layout );
@@ -1231,6 +1241,7 @@ FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
 
     if( !l )
     {
+        widget = new QWidget( _parent );
         QHBoxLayout *layout = new QHBoxLayout();
         layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
         widget->setLayout( layout );
@@ -1242,6 +1253,8 @@ FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
     }
 }
 
+int VFloatConfigControl::getType() const { return CONFIG_ITEM_FLOAT; }
+
 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
                                         module_config_t *_p_item,
                                         QLabel *_label,
@@ -1315,7 +1328,8 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
     QGridLayout *gLayout = new QGridLayout( keyContainer );
 
     label = new QLabel(
-            qtr( "Select an action to change the associated hotkey") );
+        qtr( "Select or double click an action to change the associated "
+             "hotkey. Use delete key to remove hotkeys") );
 
     QLabel *searchLabel = new QLabel( qtr( "Search" ) );
     SearchLineEdit *actionSearch = new SearchLineEdit( keyContainer );
@@ -1345,6 +1359,8 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
              this, filter( const QString& ) );
 }
 
+int KeySelectorControl::getType() const { return CONFIG_ITEM_KEY; }
+
 void KeySelectorControl::finish()
 {
     if( label && p_item->psz_longtext )
@@ -1365,12 +1381,12 @@ void KeySelectorControl::finish()
     QMap<QString, QString> global_keys;
     for (size_t i = 0; i < confsize; i++)
     {
-        module_config_t *p_item = p_config + i;
+        module_config_t *p_config_item = p_config + i;
 
         /* If we are a (non-global) key option not empty */
-        if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
-         && !strncmp( p_item->psz_name , "key-", 4 )
-         && !EMPTY_STR( p_item->psz_text ) )
+        if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
+         && !strncmp( p_config_item->psz_name , "key-", 4 )
+         && !EMPTY_STR( p_config_item->psz_text ) )
         {
             /*
                Each tree item has:
@@ -1379,23 +1395,25 @@ void KeySelectorControl::finish()
                 - KeyValue in String in column 1
              */
             QTreeWidgetItem *treeItem = new QTreeWidgetItem();
-            treeItem->setText( 0, qtr( p_item->psz_text ) );
+            treeItem->setText( 0, qtr( p_config_item->psz_text ) );
             treeItem->setData( 0, Qt::UserRole,
-                               QVariant( qfu( p_item->psz_name ) ) );
+                               QVariant( qfu( p_config_item->psz_name ) ) );
 
-            QString keys = qfu( p_item->value.psz );
+            QString keys = qfu( p_config_item->value.psz );
             treeItem->setText( 1, keys );
+            treeItem->setToolTip( 1, qtr("Double click to change") );
+            treeItem->setToolTip( 2, qtr("Double click to change") );
             treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
             table->addTopLevelItem( treeItem );
             continue;
         }
 
-        if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
-         && !strncmp( p_item->psz_name , "global-key", 10 )
-         && !EMPTY_STR( p_item->psz_text )
-         && !EMPTY_STR( p_item->value.psz ) )
+        if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
+         && !strncmp( p_config_item->psz_name , "global-key", 10 )
+         && !EMPTY_STR( p_config_item->psz_text )
+         && !EMPTY_STR( p_config_item->value.psz ) )
         {
-            global_keys.insertMulti( qtr( p_item->psz_text ), qfu( p_item->value.psz ) );
+            global_keys.insertMulti( qtr( p_config_item->psz_text ), qfu( p_config_item->value.psz ) );
         }
     }
 
@@ -1519,8 +1537,11 @@ bool KeySelectorControl::eventFilter( QObject *obj, QEvent *e )
     }
     else if( keyEv->key() == Qt::Key_Delete )
     {
-        aTable->currentItem()->setText( aTable->currentColumn(), NULL );
-        aTable->currentItem()->setData( aTable->currentColumn(), Qt::UserRole, QVariant() );
+        if( aTable->currentColumn() != 0 )
+        {
+            aTable->currentItem()->setText( aTable->currentColumn(), NULL );
+            aTable->currentItem()->setData( aTable->currentColumn(), Qt::UserRole, QVariant() );
+        }
         return true;
     }
     else
@@ -1541,12 +1562,13 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
     conflicts = false;
 
     table = _table;
-    setWindowTitle( b_global ? qtr( "Global" ): ""
-                    + qtr( "Hotkey for " ) + keyToChange );
+    setWindowTitle( ( b_global ? qtr( "Global" ) + QString(" ") : "" )
+                    + qtr( "Hotkey change" ) );
     setWindowRole( "vlc-key-input" );
 
     QVBoxLayout *vLayout = new QVBoxLayout( this );
-    selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
+    selected = new QLabel( qtr( "Press the new key or combination for " )
+                           + QString("<b>%1</b>").arg( keyToChange ) );
     vLayout->addWidget( selected , Qt::AlignCenter );
 
     warning = new QLabel;
@@ -1554,7 +1576,7 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
     vLayout->insertWidget( 1, warning );
 
     buttonBox = new QDialogButtonBox;
-    QPushButton *ok = new QPushButton( qtr("OK") );
+    QPushButton *ok = new QPushButton( qtr("Assign") );
     QPushButton *cancel = new QPushButton( qtr("Cancel") );
     buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
     buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
@@ -1577,8 +1599,8 @@ void KeyInputDialog::checkForConflicts( int i_vlckey )
         !conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString().isEmpty() &&
          conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString() != "Unset" )
     {
-        warning->setText( qtr("Warning: the key is already assigned to \"") +
-                conflictList[0]->text( 0 ) + "\"" );
+        warning->setText( qtr("Warning: this key or combination is already assigned to ") +
+                QString( "\"<b>%1</b>\"" ).arg( conflictList[0]->text( 0 ) ) );
         warning->show();
         buttonBox->show();
 
@@ -1597,7 +1619,8 @@ void KeyInputDialog::keyPressEvent( QKeyEvent *e )
         e->key() == Qt::Key_AltGr )
         return;
     int i_vlck = qtEventToVLCKey( e );
-    selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
+    selected->setText( qtr( "Key or combination: " )
+                + QString("<b>%1</b>").arg( VLCKeyToString( i_vlck ) ) );
     checkForConflicts( i_vlck );
     keyValue = i_vlck;
 }
@@ -1609,4 +1632,3 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e )
     checkForConflicts( i_vlck );
     keyValue = i_vlck;
 }
-