[vlmc-devel] commit: Settings: Adding a path selection widget. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sun Jun 27 23:06:25 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Jun 27 20:40:07 2010 +0200| [e480a507b733a86472f2be97caa5341ca5e7e752] | committer: Hugo Beauzée-Luyssen 

Settings: Adding a path selection widget.

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

 src/CMakeLists.txt                    |    2 +
 src/Gui/settings/PathWidget.cpp       |   72 +++++++++++++++++++++++++++++++++
 src/Gui/settings/PathWidget.h         |   53 ++++++++++++++++++++++++
 src/Gui/settings/PreferenceWidget.cpp |    3 +
 src/Settings/SettingValue.h           |    3 +-
 src/Settings/SettingsManager.h        |    5 ++
 6 files changed, 137 insertions(+), 1 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c9c371e..f82090b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -167,6 +167,7 @@ ELSE(NOT WITH_GUI)
         Gui/settings/KeyboardShortcutInput.cpp
         Gui/settings/LanguageWidget.cpp
         Gui/settings/Panel.cpp
+        Gui/settings/PathWidget.cpp
         Gui/settings/PreferenceWidget.cpp
         Gui/settings/Settings.cpp
         Gui/settings/StringWidget.cpp
@@ -221,6 +222,7 @@ ELSE(NOT WITH_GUI)
         Gui/settings/IntWidget.h
         Gui/settings/ISettingsCategoryWidget.h
         Gui/settings/LanguageWidget.h
+        Gui/settings/PathWidget.h
         Gui/settings/PreferenceWidget.h
         Gui/settings/StringWidget.h
         Gui/settings/Panel.h
diff --git a/src/Gui/settings/PathWidget.cpp b/src/Gui/settings/PathWidget.cpp
new file mode 100644
index 0000000..f1f5171
--- /dev/null
+++ b/src/Gui/settings/PathWidget.cpp
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * StringWidget.h: Handle text settings.
+ *****************************************************************************
+ * Copyright (C) 2008-2010 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <hugo at vlmc.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "PathWidget.h"
+#include "SettingValue.h"
+
+#include <QFileDialog>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QPushButton>
+
+PathWidget::PathWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
+        m_setting( s )
+{
+    m_widget = new QWidget( parent );
+    QHBoxLayout *layout = new QHBoxLayout;
+    m_lineEdit = new QLineEdit( m_widget );
+    m_pushButton = new QPushButton( m_widget );
+    m_pushButton->setText( tr( "Select path" ) );
+    layout->addWidget( m_lineEdit );
+    layout->addWidget( m_pushButton );
+    m_widget->setLayout( layout );
+
+    connect( s, SIGNAL( changed( const QVariant& ) ),
+             this, SLOT( changed( const QVariant& ) ) );
+    changed( s->get() );
+    connect( m_pushButton, SIGNAL( clicked() ), this, SLOT( selectPathButtonPressed() ) );
+}
+
+QWidget*
+PathWidget::widget()
+{
+    return m_widget;
+}
+
+void
+PathWidget::save()
+{
+    m_setting->set( m_lineEdit->text() );
+}
+void
+PathWidget::changed( const QVariant &val )
+{
+    m_lineEdit->setText( val.toString() );
+}
+
+void
+PathWidget::selectPathButtonPressed()
+{
+    QString path = QFileDialog::getExistingDirectory( NULL, tr( "Select a path" ),
+                                                      m_setting->get().toString() );
+    m_lineEdit->setText( path );
+}
diff --git a/src/Gui/settings/PathWidget.h b/src/Gui/settings/PathWidget.h
new file mode 100644
index 0000000..412ce72
--- /dev/null
+++ b/src/Gui/settings/PathWidget.h
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * PathWidget: Handle path settings.
+ *****************************************************************************
+ * Copyright (C) 2008-2010 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <hugo at vlmc.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef PATHWIDGET_H
+#define PATHWIDGET_H
+
+#include "ISettingsCategoryWidget.h"
+#include <stddef.h>
+
+class   SettingValue;
+
+class   QLineEdit;
+class   QPushButton;
+
+class   PathWidget : public ISettingsCategoryWidget
+{
+    Q_OBJECT
+
+    public:
+        PathWidget( SettingValue *s, QWidget *parent = NULL );
+        QWidget*                widget();
+        void                    save();
+
+    private slots:
+        virtual void            changed( const QVariant& );
+        void                    selectPathButtonPressed();
+    private:
+        SettingValue            *m_setting;
+        QLineEdit               *m_lineEdit;
+        QPushButton             *m_pushButton;
+        QWidget                 *m_widget;
+};
+
+#endif // PATHWIDGET_H
diff --git a/src/Gui/settings/PreferenceWidget.cpp b/src/Gui/settings/PreferenceWidget.cpp
index d26ab76..af2e3da 100644
--- a/src/Gui/settings/PreferenceWidget.cpp
+++ b/src/Gui/settings/PreferenceWidget.cpp
@@ -31,6 +31,7 @@
 #include "IntWidget.h"
 #include "KeyboardShortcut.h"
 #include "LanguageWidget.h"
+#include "PathWidget.h"
 #include "StringWidget.h"
 
 #include <QFormLayout>
@@ -88,6 +89,8 @@ PreferenceWidget::widgetFactory( SettingValue *s )
         return new DoubleWidget( s, this );
     case SettingValue::Bool:
         return new BoolWidget( s, this );
+    case SettingValue::Path:
+        return new PathWidget( s, this );
     default:
         return NULL;
     }
diff --git a/src/Settings/SettingValue.h b/src/Settings/SettingValue.h
index c4e5b0f..2d72956 100644
--- a/src/Settings/SettingValue.h
+++ b/src/Settings/SettingValue.h
@@ -44,7 +44,8 @@ class   SettingValue : public QObject
             String,
             Bool,
             Language,
-            KeyboardShortcut
+            KeyboardShortcut,
+            Path,
         };
         enum    Flags
         {
diff --git a/src/Settings/SettingsManager.h b/src/Settings/SettingsManager.h
index 6fa1067..21689d5 100644
--- a/src/Settings/SettingsManager.h
+++ b/src/Settings/SettingsManager.h
@@ -63,6 +63,9 @@ SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
         VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PROJECT_BOOL( key, defaultValue, name, desc )  \
         VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing )
+#define VLMC_CREATE_PROJECT_PATH( key, defaultValue, name, desc )  \
+        VLMC_CREATE_PROJECT_PATH( SettingValue::Path, key, defaultValue, name, desc, SettingValue::Nothing )
+
 
 #define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc, flags )  \
 SettingsManager::getInstance()->createVar( type, key, defaultValue, name,  \
@@ -81,6 +84,8 @@ SettingsManager::getInstance()->createVar( type, key, defaultValue, name,  \
         VLMC_CREATE_PREFERENCE( SettingValue::KeyboardShortcut, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PREFERENCE_BOOL( key, defaultValue, name, desc )  \
         VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing )
+#define VLMC_CREATE_PREFERENCE_PATH( key, defaultValue, name, desc )  \
+        VLMC_CREATE_PREFERENCE( SettingValue::Path, key, defaultValue, name, desc, SettingValue::Nothing )
 
 //Convenience maccros :
 #define VLMC_CREATE_PRIVATE_PREFERENCE_STRING( key, defaultValue )  \



More information about the Vlmc-devel mailing list