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