]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/preferences_widgets.cpp
Qt4 - Indentation fix on previous commit.
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
index 90bc37917b94723d28cb1f8bd8f082045d3bd09d..2174813c486d6f4df2851ec171e5b10af4138172 100644 (file)
 #include <QSlider>
 #include <QFileDialog>
 #include <QFontDialog>
+#include <QGroupBox>
 
 #include <vlc_keys.h>
 
+
+QString formatTooltip(const QString & tooltip)
+{
+    QString formatted =
+    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
+    " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
+    " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
+    "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
+    "-qt-block-indent:0; text-indent:0px;\">" +
+    tooltip +
+    "</p></body></html>";
+    return formatted;
+}
+
 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
                                              module_config_t *p_item,
                                              QWidget *parent )
@@ -211,9 +226,9 @@ StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
 void StringConfigControl::finish()
 {
     text->setText( qfu(p_item->value.psz) );
-    text->setToolTip( qfu(p_item->psz_longtext) );
+    text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 /*********** File **************/
@@ -226,6 +241,10 @@ FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
     label = new QLabel( qfu(p_item->psz_text) );
     text = new QLineEdit( qfu(p_item->value.psz) );
     browse = new QPushButton( qtr( "Browse..." ) );
+    QHBoxLayout *textAndButton = new QHBoxLayout();
+    textAndButton->setMargin( 0 );
+    textAndButton->addWidget( text, 2 );
+    textAndButton->addWidget( browse, 0 );
 
     BUTTONACT( browse, updateField() );
 
@@ -234,14 +253,14 @@ FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
     if( !l )
     {
         QHBoxLayout *layout = new QHBoxLayout();
-        layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
-        layout->addWidget( browse, 2 );
+        layout->addWidget( label, 0 );
+        layout->addLayout( textAndButton, 1 );
         widget->setLayout( layout );
     }
     else
     {
-        l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
-        l->addWidget( browse, line, 2 );
+        l->addWidget( label, line, 0 );
+        l->addLayout( textAndButton, line, 1 );
     }
 }
 
@@ -272,9 +291,9 @@ void FileConfigControl::updateField()
 void FileConfigControl::finish()
 {
     text->setText( qfu(p_item->value.psz) );
-    text->setToolTip( qfu(p_item->psz_longtext) );
+    text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 /********* String / Directory **********/
@@ -367,9 +386,9 @@ void StringListConfigControl::finish( bool bycat )
                                           p_item->ppsz_list[i_index] ) )
             combo->setCurrentIndex( combo->count() - 1 );
     }
-    combo->setToolTip( qfu(p_item->psz_longtext) );
+    combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 QString StringListConfigControl::getValue()
@@ -448,9 +467,9 @@ void ModuleConfigControl::finish( bool bycat )
         }
     }
     vlc_list_release( p_list );
-    combo->setToolTip( qfu(p_item->psz_longtext) );
+    combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 QString ModuleConfigControl::getValue()
@@ -460,35 +479,41 @@ QString ModuleConfigControl::getValue()
 
 /********* Module list **********/
 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
-               module_config_t *_p_item, QWidget *_parent, bool bycat,
-               QGridLayout *l, int &line) :
-               VStringConfigControl( _p_this, _p_item, _parent )
+        module_config_t *_p_item, QWidget *_parent, bool bycat,
+        QGridLayout *l, int &line) :
+    VStringConfigControl( _p_this, _p_item, _parent )
 {
-    label = new QLabel( qfu(p_item->psz_text) );
+    groupBox = new QGroupBox ( qfu(p_item->psz_text) );
     text = new QLineEdit();
+    QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
+
     finish( bycat );
 
-    bool pom = false;
+    int boxline = 0;
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
+            it != modules.end(); it++ )
+    {
+        layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
+    }
+    layoutGroupBox->addWidget( text, boxline, 0 );
+
     if( !l )
     {
-        l = new QGridLayout();
-        line = 0;
-        pom = true;
+        QVBoxLayout *layout = new QVBoxLayout();
+        layout->addWidget( groupBox, line, 0 );
+        widget->setLayout( layout );
     }
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
-         it != modules.end(); it++ )
+    else
     {
-        l->addWidget( *it, line++, 1 );
+        l->addWidget( groupBox, line, 0, 1, -1 );
     }
-    l->addWidget( label, line, 0 );
-    l->addWidget( text, line, 1 );
-    if( pom )
-        widget->setLayout( l );
+
+    text->setToolTip( formatTooltip( qfu( p_item->psz_longtext) ) );
 }
 #if 0
 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
-                module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
-                bool bycat ) : VStringConfigControl( _p_this, _p_item )
+        module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
+        bool bycat ) : VStringConfigControl( _p_this, _p_item )
 {
     combo = _combo;
     label = _label;
@@ -498,15 +523,34 @@ ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
 
 ModuleListConfigControl::~ModuleListConfigControl()
 {
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
-         it != modules.end(); it++ )
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
+            it != modules.end(); it++ )
     {
         delete *it;
     }
-    delete label;
+    delete groupBox;
     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;
@@ -527,28 +571,23 @@ void ModuleListConfigControl::finish( bool bycat )
                 module_config_t *p_config = p_parser->p_config + i;
                 /* Hack: required subcategory is stored in i_min */
                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
-                    p_config->value.i == p_item->min.i )
+                        p_config->value.i == p_item->min.i )
                 {
-                    QCheckBox *cb =
-                        new QCheckBox( qfu( p_parser->psz_object_name ) );
-                    cb->setToolTip( 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 ) );
-            cb->setToolTip( qfu(p_parser->psz_longname) );
-            modules.push_back( cb );
+            CHECKBOX_LISTS;
         }
     }
     vlc_list_release( p_list );
-    text->setToolTip( qfu(p_item->psz_longtext) );
-    if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+    text->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
+    if( groupBox )
+        groupBox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
+#undef CHECKBOX_LISTS
 
 QString ModuleListConfigControl::getValue()
 {
@@ -557,33 +596,45 @@ 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();
     }
-    text->hide();
-    label->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();
     }
-    text->show();
-    label->show();
+    groupBox->show();
 }
 
 
-void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
+void ModuleListConfigControl::onUpdate( int value )
 {
     text->clear();
-    for( QVector<QCheckBox*>::iterator it = modules.begin();
+    bool first = true;
+
+    for( QVector<checkBoxListItem*>::iterator it = modules.begin();
          it != modules.end(); it++ )
     {
+        if( (*it)->checkBox->isChecked() )
+        {
+            if( first )
+            {
+                text->setText( text->text() + (*it)->psz_module );
+                first = false;
+            }
+            else
+            {
+                text->setText( text->text() + ":" + (*it)->psz_module );
+            }
+        }
     }
 }
 
@@ -600,6 +651,7 @@ IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
 {
     label = new QLabel( qfu(p_item->psz_text) );
     spin = new QSpinBox; spin->setMinimumWidth( 80 );
+    spin->setAlignment( Qt::AlignRight );
     spin->setMaximumWidth( 90 );
     finish();
 
@@ -630,9 +682,9 @@ void IntegerConfigControl::finish()
     spin->setMaximum( 2000000000 );
     spin->setMinimum( -2000000000 );
     spin->setValue( p_item->value.i );
-    spin->setToolTip( qfu(p_item->psz_longtext) );
+    spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 int IntegerConfigControl::getValue()
@@ -675,9 +727,9 @@ IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
     slider->setMaximum( p_item->max.i );
     slider->setMinimum( p_item->min.i );
     slider->setValue( p_item->value.i );
-    slider->setToolTip( qfu(p_item->psz_longtext) );
+    slider->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 int IntegerRangeSliderConfigControl::getValue()
@@ -727,9 +779,9 @@ void IntegerListConfigControl::finish( bool bycat )
         if( p_item->value.i == p_item->pi_list[i_index] )
             combo->setCurrentIndex( combo->count() - 1 );
     }
-    combo->setToolTip( qfu(p_item->psz_longtext) );
+    combo->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 int IntegerListConfigControl::getValue()
@@ -773,7 +825,7 @@ void BoolConfigControl::finish()
 {
     checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
                                                         : Qt::Unchecked );
-    checkbox->setToolTip( qfu(p_item->psz_longtext) );
+    checkbox->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 int BoolConfigControl::getValue()
@@ -795,6 +847,7 @@ FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
     label = new QLabel( qfu(p_item->psz_text) );
     spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
     spin->setMaximumWidth( 90 );
+    spin->setAlignment( Qt::AlignRight );
     finish();
 
     if( !l )
@@ -827,9 +880,9 @@ void FloatConfigControl::finish()
     spin->setMinimum( -2000000000. );
     spin->setSingleStep( 0.1 );
     spin->setValue( (double)p_item->value.f );
-    spin->setToolTip( qfu(p_item->psz_longtext) );
+    spin->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 }
 
 float FloatConfigControl::getValue()
@@ -893,7 +946,7 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
 void KeySelectorControl::finish()
 {
     if( label )
-        label->setToolTip( qfu(p_item->psz_longtext) );
+        label->setToolTip( formatTooltip(qfu(p_item->psz_longtext)) );
 
     /* Fill the table */
     table->setColumnCount( 2 );