Commit e74c516f authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Settings: Simplifications

parent 01f29963
...@@ -61,9 +61,9 @@ EffectInstanceWidget::setEffectInstance( EffectInstance *instance ) ...@@ -61,9 +61,9 @@ EffectInstanceWidget::setEffectInstance( EffectInstance *instance )
ISettingsCategoryWidget *widget = widgetFactory( s ); ISettingsCategoryWidget *widget = widgetFactory( s );
QLabel *label = new QLabel( tr( s->name() ), this ); QLabel *label = new QLabel( tr( s->name() ), this );
m_widgets.push_back( label ); m_widgets.push_back( label );
m_widgets.push_back( widget->widget() ); m_widgets.push_back( widget );
widget->widget()->setToolTip( s->description() ); widget->setToolTip( s->description() );
m_ui->settingsLayout->addRow( label , widget->widget() ); m_ui->settingsLayout->addRow( label , widget );
m_settings.push_back( widget ); m_settings.push_back( widget );
++it; ++it;
} }
......
...@@ -26,18 +26,13 @@ ...@@ -26,18 +26,13 @@
#include <QCheckBox> #include <QCheckBox>
BoolWidget::BoolWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : BoolWidget::BoolWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_checkbox = new QCheckBox( parent ); m_checkbox = new QCheckBox( this );
layout()->addWidget( m_checkbox );
changed( s->get() ); changed( s->get() );
} }
QWidget*
BoolWidget::widget()
{
return m_checkbox;
}
void void
BoolWidget::save() BoolWidget::save()
{ {
......
...@@ -36,7 +36,6 @@ class BoolWidget : public ISettingsCategoryWidget ...@@ -36,7 +36,6 @@ class BoolWidget : public ISettingsCategoryWidget
public: public:
BoolWidget( SettingValue *s, QWidget *parent = NULL ); BoolWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save(); void save();
private slots: private slots:
......
...@@ -28,21 +28,16 @@ ...@@ -28,21 +28,16 @@
#include <QPushButton> #include <QPushButton>
ColorWidget::ColorWidget( SettingValue *s, QWidget *parent ) : ColorWidget::ColorWidget( SettingValue *s, QWidget *parent ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_color = s->get().value<QColor>(); m_color = s->get().value<QColor>();
m_button = new QPushButton( parent ); m_button = new QPushButton( this );
m_button->setPalette( QPalette( m_color ) ); m_button->setPalette( QPalette( m_color ) );
layout()->addWidget( m_button );
connect( m_button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); connect( m_button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
changed( m_color ); changed( m_color );
} }
QWidget*
ColorWidget::widget()
{
return m_button;
}
void void
ColorWidget::save() ColorWidget::save()
{ {
......
...@@ -36,7 +36,6 @@ class ColorWidget : public ISettingsCategoryWidget ...@@ -36,7 +36,6 @@ class ColorWidget : public ISettingsCategoryWidget
public: public:
ColorWidget( SettingValue *s, QWidget *parent = NULL ); ColorWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save(); void save();
private slots: private slots:
......
...@@ -29,21 +29,19 @@ ...@@ -29,21 +29,19 @@
#include <QSlider> #include <QSlider>
DoubleSliderWidget::DoubleSliderWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : DoubleSliderWidget::DoubleSliderWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_container = new QWidget( parent );
//Creating the slider //Creating the slider
m_slider = new QSlider( m_container ); m_slider = new QSlider( this );
m_slider->setOrientation( Qt::Horizontal ); m_slider->setOrientation( Qt::Horizontal );
//Creating the label //Creating the label
m_valueDisplayer = new QLabel( QString::number( s->get().toDouble() ), m_container ); m_valueDisplayer = new QLabel( QString::number( s->get().toDouble() ), this );
//Avoid label resizing due to roundups //Avoid label resizing due to roundups
const QFontMetrics &fm = m_valueDisplayer->fontMetrics(); const QFontMetrics &fm = m_valueDisplayer->fontMetrics();
m_valueDisplayer->setFixedWidth( fm.width( "0.00" ) ); m_valueDisplayer->setFixedWidth( fm.width( "0.00" ) );
//Setting the layout: //Setting the layout:
QHBoxLayout *layout = new QHBoxLayout( m_container ); layout()->addWidget( m_slider );
layout->addWidget( m_slider ); layout()->addWidget( m_valueDisplayer );
layout->addWidget( m_valueDisplayer );
//TODO: check if the value is clamped //TODO: check if the value is clamped
m_slider->setMaximum( s->max().toDouble() * 100.0 ); m_slider->setMaximum( s->max().toDouble() * 100.0 );
m_slider->setMinimum( s->min().toDouble() * 100.0 ); m_slider->setMinimum( s->min().toDouble() * 100.0 );
...@@ -51,12 +49,6 @@ DoubleSliderWidget::DoubleSliderWidget( SettingValue *s, QWidget *parent /*= NUL ...@@ -51,12 +49,6 @@ DoubleSliderWidget::DoubleSliderWidget( SettingValue *s, QWidget *parent /*= NUL
connect( m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) ); connect( m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
} }
QWidget*
DoubleSliderWidget::widget()
{
return m_container;
}
void void
DoubleSliderWidget::save() DoubleSliderWidget::save()
{ {
......
...@@ -36,12 +36,10 @@ class DoubleSliderWidget : public ISettingsCategoryWidget ...@@ -36,12 +36,10 @@ class DoubleSliderWidget : public ISettingsCategoryWidget
public: public:
DoubleSliderWidget( SettingValue *s, QWidget *parent = NULL ); DoubleSliderWidget( SettingValue *s, QWidget *parent = NULL );
QWidget *widget();
void save(); void save();
private: private:
QSlider *m_slider; QSlider *m_slider;
QWidget *m_container;
QLabel *m_valueDisplayer; QLabel *m_valueDisplayer;
private slots: private slots:
......
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_spinbox = new QDoubleSpinBox( parent ); m_spinbox = new QDoubleSpinBox( this );
layout()->addWidget( m_spinbox );
changed( s->get() ); changed( s->get() );
if ( ( s->flags() & SettingValue::Clamped ) != 0 ) if ( ( s->flags() & SettingValue::Clamped ) != 0 )
...@@ -40,12 +41,6 @@ DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : ...@@ -40,12 +41,6 @@ DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
} }
} }
QWidget*
DoubleWidget::widget()
{
return m_spinbox;
}
void void
DoubleWidget::save() DoubleWidget::save()
{ {
......
...@@ -36,7 +36,6 @@ class DoubleWidget : public ISettingsCategoryWidget ...@@ -36,7 +36,6 @@ class DoubleWidget : public ISettingsCategoryWidget
public: public:
DoubleWidget( SettingValue *s, QWidget *parent = NULL ); DoubleWidget( SettingValue *s, QWidget *parent = NULL );
QWidget *widget();
void save(); void save();
private slots: private slots:
......
...@@ -27,25 +27,28 @@ ...@@ -27,25 +27,28 @@
#include "SettingValue.h" #include "SettingValue.h"
class QVariant; class QVariant;
class QWidget;
#include <QObject> #include <QWidget>
#include <QHBoxLayout>
class ISettingsCategoryWidget : public QObject class ISettingsCategoryWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
virtual ~ISettingsCategoryWidget(){} virtual ~ISettingsCategoryWidget(){}
virtual SettingValue *setting() { return m_setting; } virtual SettingValue *setting() { return m_setting; }
virtual QWidget* widget() = 0;
virtual void save() = 0; virtual void save() = 0;
protected: protected:
ISettingsCategoryWidget( SettingValue* s ) : m_setting( s ) ISettingsCategoryWidget( QWidget *parent, SettingValue* s ) :
QWidget( parent ),
m_setting( s )
{ {
connect( s, SIGNAL( changed( const QVariant& ) ), connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) ); this, SLOT( changed( const QVariant& ) ) );
QHBoxLayout *layout = new QHBoxLayout;
setLayout( layout );
} }
protected: protected:
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
#include <QSpinBox> #include <QSpinBox>
IntWidget::IntWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : IntWidget::IntWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_spinbox = new QSpinBox( parent ); m_spinbox = new QSpinBox( this );
if ( ( s->flags() & SettingValue::Clamped ) != 0 ) if ( ( s->flags() & SettingValue::Clamped ) != 0 )
{ {
if ( s->min().isValid() ) if ( s->min().isValid() )
...@@ -40,15 +40,10 @@ IntWidget::IntWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : ...@@ -40,15 +40,10 @@ IntWidget::IntWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
{ {
m_spinbox->setSingleStep( 8 ); m_spinbox->setSingleStep( 8 );
} }
layout()->addWidget( m_spinbox );
changed( s->get() ); changed( s->get() );
} }
QWidget*
IntWidget::widget()
{
return m_spinbox;
}
void void
IntWidget::save() IntWidget::save()
{ {
......
...@@ -36,7 +36,6 @@ class IntWidget : public ISettingsCategoryWidget ...@@ -36,7 +36,6 @@ class IntWidget : public ISettingsCategoryWidget
public: public:
IntWidget( SettingValue *s, QWidget *parent = NULL ); IntWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save(); void save();
private slots: private slots:
......
...@@ -25,15 +25,10 @@ ...@@ -25,15 +25,10 @@
#include "SettingValue.h" #include "SettingValue.h"
KeyboardShortcut::KeyboardShortcut( SettingValue *s, QWidget *parent /*= NULL*/ ) : KeyboardShortcut::KeyboardShortcut( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_input = new KeyboardShortcutInput( s->name(), s->get().toString(), parent ); m_input = new KeyboardShortcutInput( s->name(), s->get().toString(), this );
} layout()->addWidget( m_input );
QWidget*
KeyboardShortcut::widget()
{
return m_input;
} }
void void
......
...@@ -35,7 +35,6 @@ class KeyboardShortcut : public ISettingsCategoryWidget ...@@ -35,7 +35,6 @@ class KeyboardShortcut : public ISettingsCategoryWidget
public: public:
KeyboardShortcut( SettingValue *s, QWidget *parent = NULL ); KeyboardShortcut( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save(); void save();
private slots: private slots:
......
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
#define TS_PREFIX "vlmc_" #define TS_PREFIX "vlmc_"
LanguageWidget::LanguageWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : LanguageWidget::LanguageWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_list = new QComboBox( parent ); m_list = new QComboBox( this );
QDir dir( ":/ts/", "*.qm", QDir::Name | QDir::IgnoreCase, QDir::Files ); QDir dir( ":/ts/", "*.qm", QDir::Name | QDir::IgnoreCase, QDir::Files );
foreach ( const QString& tsFileName, dir.entryList() ) foreach ( const QString& tsFileName, dir.entryList() )
...@@ -74,16 +74,10 @@ LanguageWidget::LanguageWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : ...@@ -74,16 +74,10 @@ LanguageWidget::LanguageWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
// Add the system default option (auto-detection of the locale) // Add the system default option (auto-detection of the locale)
m_list->insertItem( 0, "System Locale (autodetect)", "default" ); m_list->insertItem( 0, "System Locale (autodetect)", "default" );
layout()->addWidget( m_list );
changed( s->get() ); changed( s->get() );
} }
QWidget*
LanguageWidget::widget()
{
return m_list;
}
void void
LanguageWidget::save() LanguageWidget::save()
{ {
......
...@@ -36,7 +36,6 @@ class LanguageWidget : public ISettingsCategoryWidget ...@@ -36,7 +36,6 @@ class LanguageWidget : public ISettingsCategoryWidget
public: public:
LanguageWidget( SettingValue *s, QWidget *parent = NULL ); LanguageWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save(); void save();
private slots: private slots:
......
...@@ -24,32 +24,22 @@ ...@@ -24,32 +24,22 @@
#include "SettingValue.h" #include "SettingValue.h"
#include <QFileDialog> #include <QFileDialog>
#include <QHBoxLayout>
#include <QLineEdit> #include <QLineEdit>
#include <QPushButton> #include <QPushButton>
PathWidget::PathWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : PathWidget::PathWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_widget = new QWidget( parent ); m_lineEdit = new QLineEdit( this );
QHBoxLayout *layout = new QHBoxLayout; m_pushButton = new QPushButton( this );
m_lineEdit = new QLineEdit( m_widget );
m_pushButton = new QPushButton( m_widget );
m_pushButton->setText( tr( "Select a path" ) ); m_pushButton->setText( tr( "Select a path" ) );
layout->addWidget( m_lineEdit ); layout()->addWidget( m_lineEdit );
layout->addWidget( m_pushButton ); layout()->addWidget( m_pushButton );
m_widget->setLayout( layout );
changed( s->get() ); changed( s->get() );
connect( m_pushButton, SIGNAL( clicked() ), this, SLOT( selectPathButtonPressed() ) ); connect( m_pushButton, SIGNAL( clicked() ), this, SLOT( selectPathButtonPressed() ) );
} }
QWidget*
PathWidget::widget()
{
return m_widget;
}
void void
PathWidget::save() PathWidget::save()
{ {
......
...@@ -37,7 +37,6 @@ class PathWidget : public ISettingsCategoryWidget ...@@ -37,7 +37,6 @@ class PathWidget : public ISettingsCategoryWidget
public: public:
PathWidget( SettingValue *s, QWidget *parent = NULL ); PathWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save(); void save();
private slots: private slots:
......
...@@ -63,8 +63,8 @@ PreferenceWidget::PreferenceWidget( const QString &name, const char *label, Sett ...@@ -63,8 +63,8 @@ PreferenceWidget::PreferenceWidget( const QString &name, const char *label, Sett
QLabel *label = new QLabel( tr( s->name() ), this ); QLabel *label = new QLabel( tr( s->name() ), this );
label->setToolTip( tr( s->description() ) ); label->setToolTip( tr( s->description() ) );
m_labels.insert( s, label ); m_labels.insert( s, label );
widget->widget()->setToolTip( s->description() ); widget->setToolTip( s->description() );
layout->addRow( label, widget->widget() ); layout->addRow( label, widget );
m_settings.push_back( widget ); m_settings.push_back( widget );
} }
......
...@@ -26,20 +26,15 @@ ...@@ -26,20 +26,15 @@
#include <QLineEdit> #include <QLineEdit>
StringWidget::StringWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) : StringWidget::StringWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
ISettingsCategoryWidget( s ) ISettingsCategoryWidget( parent, s )
{ {
m_lineEdit = new QLineEdit( parent ); m_lineEdit = new QLineEdit( this );
if ( ( s->flags() & SettingValue::Password ) != 0 ) if ( ( s->flags() & SettingValue::Password ) != 0 )
m_lineEdit->setEchoMode( QLineEdit::Password ); m_lineEdit->setEchoMode( QLineEdit::Password );
layout()->addWidget( m_lineEdit );
changed( s->get() ); changed( s->get() );
} }
QWidget*
StringWidget::widget()
{
return m_lineEdit;
}
void void
StringWidget::save() StringWidget::save()
{ {
......
...@@ -36,7 +36,6 @@ class StringWidget : public ISettingsCategoryWidget ...@@ -36,7 +36,6 @@ class StringWidget : public ISettingsCategoryWidget
public: public:
StringWidget( SettingValue *s, QWidget *parent = NULL ); StringWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save(); void save();
private slots: private slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment