From cfaa0cb3a43d5cc645fbbe55f1d001edc2dc9b10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20Stenac?= Date: Sun, 27 Aug 2006 14:40:22 +0000 Subject: [PATCH] Improved layout for preferences --- modules/gui/qt4/components/preferences.cpp | 44 ++++--- .../qt4/components/preferences_widgets.cpp | 110 ++++++++++++------ .../qt4/components/preferences_widgets.hpp | 31 +++-- 3 files changed, 129 insertions(+), 56 deletions(-) diff --git a/modules/gui/qt4/components/preferences.cpp b/modules/gui/qt4/components/preferences.cpp index 48189cb973..42ec90fc1b 100644 --- a/modules/gui/qt4/components/preferences.cpp +++ b/modules/gui/qt4/components/preferences.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #define ITEM_HEIGHT 25 @@ -414,13 +415,14 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, global_layout->addWidget( help ); QGroupBox *box = NULL; - QVBoxLayout *boxlayout = NULL; + QGridLayout *boxlayout = NULL; QScrollArea *scroller= new QScrollArea; scroller->setFrameStyle( QFrame::NoFrame ); QWidget *scrolled_area = new QWidget; - QVBoxLayout *layout = new QVBoxLayout(); + QGridLayout *layout = new QGridLayout(); + int i_line = 0, i_boxline = 0; if( p_item ) do { @@ -438,24 +440,29 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, if( box ) { box->setLayout( boxlayout ); - layout->addWidget( box, 1 ); + layout->addWidget( box, i_line, 0, 1, 2 ); + i_line++; } box = new QGroupBox( qfu(p_item->psz_text) ); - boxlayout = new QVBoxLayout(); + boxlayout = new QGridLayout(); + } + ConfigControl *control; + if( ! box ) + { + control = ConfigControl::createControl( VLC_OBJECT( p_intf ), + p_item, NULL, layout, i_line ); + } + else + { + control = ConfigControl::createControl( VLC_OBJECT( p_intf ), + p_item, NULL, boxlayout, i_boxline ); } - - ConfigControl *control = ConfigControl::createControl( - VLC_OBJECT( p_intf ), p_item, - NULL ); if( !control ) { continue; } - if( !box ) - layout->addWidget( control->getWidget() ); - else - boxlayout->addWidget( control->getWidget() ); - + if( box ) i_boxline++; + else i_line++; controls.append( control ); } while( !(p_item->i_type == CONFIG_HINT_END || @@ -467,7 +474,7 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, if( box ) { box->setLayout( boxlayout ); - layout->addWidget( box, 1 ); + layout->addWidget( box, i_line, 0, 1, 2 ); } vlc_object_release( p_module ); @@ -527,8 +534,13 @@ void PrefsPanel::setAdvanced( bool adv, bool force ) { if( (*i)->isAdvanced() ) { - if( !advanced ) some_hidden = true; - (*i)->getWidget()->setVisible( advanced ); + if( !advanced ) + { + some_hidden = true; + (*i)->hide(); + } + else + (*i)->show(); } } if( some_hidden_text ) diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp index 49039f1d06..0c6d0ecea2 100644 --- a/modules/gui/qt4/components/preferences_widgets.cpp +++ b/modules/gui/qt4/components/preferences_widgets.cpp @@ -38,10 +38,19 @@ #include #include #include +#include ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, module_config_t *p_item, QWidget *parent ) +{ + return createControl( p_this, p_item, parent, NULL, 0 ); +} + +ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, + module_config_t *p_item, + QWidget *parent, + QGridLayout *l, int line ) { ConfigControl *p_control = NULL; if( p_item->psz_current ) return NULL; @@ -49,14 +58,17 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, switch( p_item->i_type ) { case CONFIG_ITEM_MODULE: - p_control = new ModuleConfigControl( p_this, p_item, parent, false ); + p_control = new ModuleConfigControl( p_this, p_item, parent, false, + l, line ); break; case CONFIG_ITEM_MODULE_CAT: - p_control = new ModuleConfigControl( p_this, p_item, parent, true ); + p_control = new ModuleConfigControl( p_this, p_item, parent, true, + l, line ); break; case CONFIG_ITEM_STRING: if( !p_item->i_list ) - p_control = new StringConfigControl( p_this, p_item, parent,false ); + p_control = new StringConfigControl( p_this, p_item, parent, + l, line, false ); else fprintf(stderr, "TODO\n" ); break; @@ -66,7 +78,8 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, else if( p_item->i_min || p_item->i_max ) fprintf( stderr, "Todo\n" ); else - p_control = new IntegerConfigControl( p_this, p_item, parent ); + p_control = new IntegerConfigControl( p_this, p_item, parent, + l, line ); break; default: break; @@ -81,28 +94,37 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, /*********** String **************/ StringConfigControl::StringConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, - QWidget *_parent, bool pwd ) : + QWidget *_parent, QGridLayout *l, + int line, bool pwd ) : VStringConfigControl( _p_this, _p_item, _parent ) { - QLabel *label = new QLabel( qfu(p_item->psz_text) ); + label = new QLabel( qfu(p_item->psz_text) ); text = new QLineEdit( qfu(p_item->psz_value) ); - finish(label); + finish(); - QHBoxLayout *layout = new QHBoxLayout(); - layout->addWidget( label, 0 ); layout->addWidget( text, 1 ); - widget->setLayout( layout ); + if( !l ) + { + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget( label, 0 ); layout->addWidget( text, 1 ); + widget->setLayout( layout ); + } + else + { + l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 ); + } } StringConfigControl::StringConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, - QLabel *label, QLineEdit *_text, bool pwd ): + QLabel *_label, QLineEdit *_text, bool pwd ): VStringConfigControl( _p_this, _p_item ) { text = _text; - finish( label ); + label = _label; + finish( ); } -void StringConfigControl::finish( QLabel *label ) +void StringConfigControl::finish() { text->setText( qfu(p_item->psz_value) ); text->setToolTip( qfu(p_item->psz_longtext) ); @@ -111,25 +133,35 @@ void StringConfigControl::finish( QLabel *label ) /********* Module **********/ ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this, - module_config_t *_p_item, QWidget *_parent, - bool bycat ) : 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 ) { - QLabel *label = new QLabel( qfu(p_item->psz_text) ); + label = new QLabel( qfu(p_item->psz_text) ); combo = new QComboBox(); - finish( label, bycat ); - QHBoxLayout *layout = new QHBoxLayout(); - layout->addWidget( label ); layout->addWidget( combo ); - widget->setLayout( layout ); + finish( bycat ); + if( !l ) + { + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget( label ); layout->addWidget( combo ); + widget->setLayout( layout ); + } + else + { + l->addWidget( label, line, 0 ); + l->addWidget( combo, line, 1, Qt::AlignRight ); + } } ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this, - module_config_t *_p_item, QLabel *label, QComboBox *_combo, + module_config_t *_p_item, QLabel *_label, QComboBox *_combo, bool bycat ) : VStringConfigControl( _p_this, _p_item ) { combo = _combo; - finish( label, bycat ); + label = _label; + finish( bycat ); } -void ModuleConfigControl::finish( QLabel *label, bool bycat ) +void ModuleConfigControl::finish( bool bycat ) { vlc_list_t *p_list; module_t *p_parser; @@ -186,28 +218,40 @@ QString ModuleConfigControl::getValue() /*********** Integer **************/ IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, - QWidget *_parent ) : + QWidget *_parent, QGridLayout *l, + int line ) : VIntConfigControl( _p_this, _p_item, _parent ) { - QLabel *label = new QLabel( qfu(p_item->psz_text) ); - spin = new QSpinBox; - finish( label ); + label = new QLabel( qfu(p_item->psz_text) ); + spin = new QSpinBox; spin->setMinimumWidth( 80 ); + spin->setMaximumWidth( 90 ); + finish(); - QHBoxLayout *layout = new QHBoxLayout(); - layout->addWidget( label, 0 ); layout->addWidget( spin, 1 ); - widget->setLayout( layout ); + if( !l ) + { + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget( label, 0 ); layout->addWidget( spin, 1 ); + widget->setLayout( layout ); + } + else + { + l->addWidget( label, line, 0 ); + l->addWidget( spin, line, 1, Qt::AlignRight ); + } } IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this, module_config_t *_p_item, - QLabel *label, QSpinBox *_spin ) : + QLabel *_label, QSpinBox *_spin ) : VIntConfigControl( _p_this, _p_item ) { spin = _spin; - finish(label); + label = _label; + finish(); } -void IntegerConfigControl::finish( QLabel *label ) +void IntegerConfigControl::finish() { + spin->setMaximum( 2000000000 ); spin->setValue( p_item->i_value ); spin->setToolTip( qfu(p_item->psz_longtext) ); label->setToolTip( qfu(p_item->psz_longtext) ); diff --git a/modules/gui/qt4/components/preferences_widgets.hpp b/modules/gui/qt4/components/preferences_widgets.hpp index 7731ea1d32..92d29ac957 100644 --- a/modules/gui/qt4/components/preferences_widgets.hpp +++ b/modules/gui/qt4/components/preferences_widgets.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "ui/input_stats.h" #include "qt4.hpp" #include @@ -53,9 +55,14 @@ public: QString getName() { return qfu( p_item->psz_name ); } QWidget *getWidget() { assert( widget ); return widget; } bool isAdvanced() { return p_item->b_advanced; } + virtual void hide() { getWidget()->hide(); }; + virtual void show() { getWidget()->show(); }; static ConfigControl * createControl( vlc_object_t*, module_config_t*,QWidget* ); + static ConfigControl * createControl( vlc_object_t*, + module_config_t*,QWidget*, + QGridLayout *, int); protected: vlc_object_t *p_this; module_config_t *p_item; @@ -83,14 +90,18 @@ public: class IntegerConfigControl : public VIntConfigControl { public: - IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget * ); + IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *, + QGridLayout *, int ); IntegerConfigControl( vlc_object_t *, module_config_t *, QLabel*, QSpinBox* ); virtual ~IntegerConfigControl() {}; virtual int getValue(); + virtual void show() { spin->show(); label->show(); } + virtual void hide() { spin->hide(); label->hide(); } private: QSpinBox *spin; - void finish( QLabel * ); + QLabel *label; + void finish(); }; #if 0 @@ -150,27 +161,33 @@ class StringConfigControl : public VStringConfigControl { public: StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, - bool pwd ); + QGridLayout *, int, bool pwd ); StringConfigControl( vlc_object_t *, module_config_t *, QLabel *, QLineEdit*, bool pwd ); virtual ~StringConfigControl() {}; virtual QString getValue() { return text->text(); }; + virtual void show() { text->show(); label->show(); } + virtual void hide() { text->hide(); label->hide(); } private: - void finish( QLabel * ); + void finish(); QLineEdit *text; + QLabel *label; }; class ModuleConfigControl : public VStringConfigControl { public: - ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool - bycat ); + ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool, + QGridLayout*, int ); ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *, QComboBox*, bool ); virtual ~ModuleConfigControl() {}; virtual QString getValue(); + virtual void hide() { combo->hide(); label->hide(); } + virtual void show() { combo->show(); label->show(); } private: - void finish( QLabel *, bool ); + void finish( bool ); + QLabel *label; QComboBox *combo; }; #if 0 -- 2.39.2