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

Setting Widgets: Watch for value changes

Fixes #93
parent 712b85e9
......@@ -215,7 +215,15 @@ ELSE(NOT WITH_GUI)
Gui/preview/PreviewRuler.h
Gui/preview/PreviewWidget.h
Gui/project/GuiProjectManager.h
Gui/settings/KeyboardShortcut.h
Gui/settings/KeyboardShortcutInput.h
Gui/settings/BoolWidget.h
Gui/settings/DoubleWidget.h
Gui/settings/IntWidget.h
Gui/settings/ISettingsCategoryWidget.h
Gui/settings/LanguageWidget.h
Gui/settings/PreferenceWidget.h
Gui/settings/StringWidget.h
Gui/settings/Panel.h
Gui/settings/PreferenceWidget.h
Gui/settings/Settings.h
......
......@@ -29,7 +29,9 @@ BoolWidget::BoolWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
m_setting( s )
{
m_checkbox = new QCheckBox( parent );
m_checkbox->setChecked( s->get().toBool() );
connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) );
changed( s->get() );
}
QWidget*
......@@ -43,3 +45,9 @@ BoolWidget::save()
{
m_setting->set( m_checkbox->isChecked() );
}
void
BoolWidget::changed( const QVariant &val )
{
m_checkbox->setChecked( val.toBool() );
}
......@@ -32,11 +32,16 @@ class QCheckBox;
class BoolWidget : public ISettingsCategoryWidget
{
Q_OBJECT
public:
BoolWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save();
private slots:
virtual void changed( const QVariant& );
private:
SettingValue *m_setting;
QCheckBox *m_checkbox;
......
......@@ -29,7 +29,9 @@ DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
m_setting( s )
{
m_spinbox = new QDoubleSpinBox( parent );
m_spinbox->setValue( s->get().toDouble() );
changed( s->get() );
connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) );
}
QWidget*
......@@ -43,3 +45,9 @@ DoubleWidget::save()
{
m_setting->set( m_spinbox->value() );
}
void
DoubleWidget::changed( const QVariant &val )
{
m_spinbox->setValue( val.toDouble() );
}
......@@ -32,11 +32,16 @@ class QDoubleSpinBox;
class DoubleWidget : public ISettingsCategoryWidget
{
Q_OBJECT
public:
DoubleWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save();
private slots:
virtual void changed( const QVariant& );
private:
SettingValue *m_setting;
QDoubleSpinBox *m_spinbox;
......
......@@ -27,11 +27,18 @@
class QVariant;
class QWidget;
class ISettingsCategoryWidget
#include <QObject>
class ISettingsCategoryWidget : public QObject
{
Q_OBJECT
public:
virtual QWidget* widget() = 0;
virtual void save() = 0;
protected slots:
virtual void changed( const QVariant& ) = 0;
};
#endif // ISETTINGSCATEGORYWIDGET_H
......@@ -29,7 +29,9 @@ IntWidget::IntWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
m_setting( s )
{
m_spinbox = new QSpinBox( parent );
m_spinbox->setValue( s->get().toInt() );
connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) );
changed( s->get() );
}
QWidget*
......@@ -43,3 +45,9 @@ IntWidget::save()
{
m_setting->set( m_spinbox->value() );
}
void
IntWidget::changed( const QVariant &val )
{
m_spinbox->setValue( val.toInt() );
}
......@@ -32,11 +32,16 @@ class QSpinBox;
class IntWidget : public ISettingsCategoryWidget
{
Q_OBJECT
public:
IntWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save();
private slots:
virtual void changed( const QVariant& );
private:
SettingValue *m_setting;
QSpinBox *m_spinbox;
......
......@@ -31,11 +31,17 @@ class SettingValue;
class KeyboardShortcut : public ISettingsCategoryWidget
{
Q_OBJECT
public:
KeyboardShortcut( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save();
private slots:
///The KeyboardShortcutInput does this itself.
virtual void changed( const QVariant& ){}
private:
SettingValue *m_setting;
KeyboardShortcutInput *m_input;
......
......@@ -75,10 +75,9 @@ 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" );
QString lang = VLMC_GET_STRING( "general/VLMCLang" );
int idx = m_list->findData( lang );
if ( idx != -1 )
m_list->setCurrentIndex( idx );
connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) );
changed( s->get() );
}
QWidget*
......@@ -93,3 +92,11 @@ LanguageWidget::save()
QString lang = m_list->itemData( m_list->currentIndex() ).toString();
m_setting->set( lang );
}
void
LanguageWidget::changed( const QVariant &val )
{
int idx = m_list->findData( val.toString() );
if ( idx != -1 )
m_list->setCurrentIndex( idx );
}
......@@ -32,11 +32,16 @@ class QComboBox;
class LanguageWidget : public ISettingsCategoryWidget
{
Q_OBJECT
public:
LanguageWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save();
private slots:
virtual void changed( const QVariant& );
private:
SettingValue *m_setting;
QComboBox *m_list;
......
......@@ -29,7 +29,9 @@ StringWidget::StringWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
m_setting( s )
{
m_lineEdit = new QLineEdit( parent );
m_lineEdit->setText( s->get().toString() );
connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) );
changed( s->get() );
}
QWidget*
......@@ -43,3 +45,8 @@ StringWidget::save()
{
m_setting->set( m_lineEdit->text() );
}
void
StringWidget::changed( const QVariant &val )
{
m_lineEdit->setText( val.toString() );
}
......@@ -32,11 +32,16 @@ class QLineEdit;
class StringWidget : public ISettingsCategoryWidget
{
Q_OBJECT
public:
StringWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save();
private slots:
virtual void changed( const QVariant& );
private:
SettingValue *m_setting;
QLineEdit *m_lineEdit;
......
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