[vlmc-devel] commit: Setting Widgets: Watch for value changes ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Tue Apr 20 20:24:01 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Tue Apr 20 20:22:10 2010 +0200| [f6172153057f62879956c6fa86853b21c2f7263d] | committer: Hugo Beauzée-Luyssen 

Setting Widgets: Watch for value changes

Fixes #93

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=f6172153057f62879956c6fa86853b21c2f7263d
---

 src/CMakeLists.txt                         |    8 ++++++++
 src/Gui/settings/BoolWidget.cpp            |   10 +++++++++-
 src/Gui/settings/BoolWidget.h              |    5 +++++
 src/Gui/settings/DoubleWidget.cpp          |   10 +++++++++-
 src/Gui/settings/DoubleWidget.h            |    5 +++++
 src/Gui/settings/ISettingsCategoryWidget.h |    9 ++++++++-
 src/Gui/settings/IntWidget.cpp             |   10 +++++++++-
 src/Gui/settings/IntWidget.h               |    5 +++++
 src/Gui/settings/KeyboardShortcut.h        |    6 ++++++
 src/Gui/settings/LanguageWidget.cpp        |   15 +++++++++++----
 src/Gui/settings/LanguageWidget.h          |    5 +++++
 src/Gui/settings/StringWidget.cpp          |    9 ++++++++-
 src/Gui/settings/StringWidget.h            |    5 +++++
 13 files changed, 93 insertions(+), 9 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5b2d9d4..3a4f076 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
diff --git a/src/Gui/settings/BoolWidget.cpp b/src/Gui/settings/BoolWidget.cpp
index 10b5419..31d174f 100644
--- a/src/Gui/settings/BoolWidget.cpp
+++ b/src/Gui/settings/BoolWidget.cpp
@@ -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() );
+}
diff --git a/src/Gui/settings/BoolWidget.h b/src/Gui/settings/BoolWidget.h
index 9c3bdbb..4ec844a 100644
--- a/src/Gui/settings/BoolWidget.h
+++ b/src/Gui/settings/BoolWidget.h
@@ -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;
diff --git a/src/Gui/settings/DoubleWidget.cpp b/src/Gui/settings/DoubleWidget.cpp
index 23e8ab6..5269613 100644
--- a/src/Gui/settings/DoubleWidget.cpp
+++ b/src/Gui/settings/DoubleWidget.cpp
@@ -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() );
+}
diff --git a/src/Gui/settings/DoubleWidget.h b/src/Gui/settings/DoubleWidget.h
index 989beff..a69be78 100644
--- a/src/Gui/settings/DoubleWidget.h
+++ b/src/Gui/settings/DoubleWidget.h
@@ -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;
diff --git a/src/Gui/settings/ISettingsCategoryWidget.h b/src/Gui/settings/ISettingsCategoryWidget.h
index 2935460..d4f0fd8 100644
--- a/src/Gui/settings/ISettingsCategoryWidget.h
+++ b/src/Gui/settings/ISettingsCategoryWidget.h
@@ -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
diff --git a/src/Gui/settings/IntWidget.cpp b/src/Gui/settings/IntWidget.cpp
index ea4f691..d76005e 100644
--- a/src/Gui/settings/IntWidget.cpp
+++ b/src/Gui/settings/IntWidget.cpp
@@ -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() );
+}
diff --git a/src/Gui/settings/IntWidget.h b/src/Gui/settings/IntWidget.h
index b09098d..c711b6a 100644
--- a/src/Gui/settings/IntWidget.h
+++ b/src/Gui/settings/IntWidget.h
@@ -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;
diff --git a/src/Gui/settings/KeyboardShortcut.h b/src/Gui/settings/KeyboardShortcut.h
index be80e29..3ddb495 100644
--- a/src/Gui/settings/KeyboardShortcut.h
+++ b/src/Gui/settings/KeyboardShortcut.h
@@ -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;
diff --git a/src/Gui/settings/LanguageWidget.cpp b/src/Gui/settings/LanguageWidget.cpp
index 750e3d7..172441b 100644
--- a/src/Gui/settings/LanguageWidget.cpp
+++ b/src/Gui/settings/LanguageWidget.cpp
@@ -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 );
+}
diff --git a/src/Gui/settings/LanguageWidget.h b/src/Gui/settings/LanguageWidget.h
index 49ebe4b..e6e73e6 100644
--- a/src/Gui/settings/LanguageWidget.h
+++ b/src/Gui/settings/LanguageWidget.h
@@ -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;
diff --git a/src/Gui/settings/StringWidget.cpp b/src/Gui/settings/StringWidget.cpp
index 361ef72..9d4305d 100644
--- a/src/Gui/settings/StringWidget.cpp
+++ b/src/Gui/settings/StringWidget.cpp
@@ -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() );
+}
diff --git a/src/Gui/settings/StringWidget.h b/src/Gui/settings/StringWidget.h
index 0750c47..11f424c 100644
--- a/src/Gui/settings/StringWidget.h
+++ b/src/Gui/settings/StringWidget.h
@@ -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;



More information about the Vlmc-devel mailing list