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

Settings: Adding a path selection widget.

parent 02a0b81b
...@@ -167,6 +167,7 @@ ELSE(NOT WITH_GUI) ...@@ -167,6 +167,7 @@ ELSE(NOT WITH_GUI)
Gui/settings/KeyboardShortcutInput.cpp Gui/settings/KeyboardShortcutInput.cpp
Gui/settings/LanguageWidget.cpp Gui/settings/LanguageWidget.cpp
Gui/settings/Panel.cpp Gui/settings/Panel.cpp
Gui/settings/PathWidget.cpp
Gui/settings/PreferenceWidget.cpp Gui/settings/PreferenceWidget.cpp
Gui/settings/Settings.cpp Gui/settings/Settings.cpp
Gui/settings/StringWidget.cpp Gui/settings/StringWidget.cpp
...@@ -221,6 +222,7 @@ ELSE(NOT WITH_GUI) ...@@ -221,6 +222,7 @@ ELSE(NOT WITH_GUI)
Gui/settings/IntWidget.h Gui/settings/IntWidget.h
Gui/settings/ISettingsCategoryWidget.h Gui/settings/ISettingsCategoryWidget.h
Gui/settings/LanguageWidget.h Gui/settings/LanguageWidget.h
Gui/settings/PathWidget.h
Gui/settings/PreferenceWidget.h Gui/settings/PreferenceWidget.h
Gui/settings/StringWidget.h Gui/settings/StringWidget.h
Gui/settings/Panel.h Gui/settings/Panel.h
......
/*****************************************************************************
* StringWidget.h: Handle text settings.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@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 );
}
/*****************************************************************************
* PathWidget: Handle path settings.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@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
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "IntWidget.h" #include "IntWidget.h"
#include "KeyboardShortcut.h" #include "KeyboardShortcut.h"
#include "LanguageWidget.h" #include "LanguageWidget.h"
#include "PathWidget.h"
#include "StringWidget.h" #include "StringWidget.h"
#include <QFormLayout> #include <QFormLayout>
...@@ -88,6 +89,8 @@ PreferenceWidget::widgetFactory( SettingValue *s ) ...@@ -88,6 +89,8 @@ PreferenceWidget::widgetFactory( SettingValue *s )
return new DoubleWidget( s, this ); return new DoubleWidget( s, this );
case SettingValue::Bool: case SettingValue::Bool:
return new BoolWidget( s, this ); return new BoolWidget( s, this );
case SettingValue::Path:
return new PathWidget( s, this );
default: default:
return NULL; return NULL;
} }
......
...@@ -44,7 +44,8 @@ class SettingValue : public QObject ...@@ -44,7 +44,8 @@ class SettingValue : public QObject
String, String,
Bool, Bool,
Language, Language,
KeyboardShortcut KeyboardShortcut,
Path,
}; };
enum Flags enum Flags
{ {
......
...@@ -63,6 +63,9 @@ SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \ ...@@ -63,6 +63,9 @@ SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc, SettingValue::Nothing ) VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PROJECT_BOOL( key, defaultValue, name, desc ) \ #define VLMC_CREATE_PROJECT_BOOL( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing ) 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 ) \ #define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc, flags ) \
SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \ SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
...@@ -81,6 +84,8 @@ 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 ) VLMC_CREATE_PREFERENCE( SettingValue::KeyboardShortcut, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PREFERENCE_BOOL( key, defaultValue, name, desc ) \ #define VLMC_CREATE_PREFERENCE_BOOL( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing ) 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 : //Convenience maccros :
#define VLMC_CREATE_PRIVATE_PREFERENCE_STRING( key, defaultValue ) \ #define VLMC_CREATE_PRIVATE_PREFERENCE_STRING( key, defaultValue ) \
......
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