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