Commit 25b21537 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Keyboard shortcut widget is automatically generated.

parent 9eefcff5
...@@ -43,6 +43,7 @@ SET(VLMC_SRCS ...@@ -43,6 +43,7 @@ SET(VLMC_SRCS
Gui/library/MediaListViewController.cpp Gui/library/MediaListViewController.cpp
Gui/library/StackViewController.cpp Gui/library/StackViewController.cpp
Gui/library/StackViewNavController.cpp Gui/library/StackViewNavController.cpp
Gui/settings/KeyboardShortcut.cpp
Gui/settings/KeyboardShortcutInput.cpp Gui/settings/KeyboardShortcutInput.cpp
Gui/settings/Panel.cpp Gui/settings/Panel.cpp
Gui/settings/PreferenceWidget.cpp Gui/settings/PreferenceWidget.cpp
...@@ -124,6 +125,8 @@ SET (VLMC_HDRS ...@@ -124,6 +125,8 @@ SET (VLMC_HDRS
Gui/MainWindow.h Gui/MainWindow.h
Gui/PreviewRuler.h Gui/PreviewRuler.h
Gui/PreviewWidget.h Gui/PreviewWidget.h
Gui/settings/ISettingsCategorieWidget.h
Gui/settings/KeyboardShortcut.h
Gui/settings/KeyboardShortcutInput.h Gui/settings/KeyboardShortcutInput.h
Gui/settings/Panel.h Gui/settings/Panel.h
Gui/settings/PreferenceWidget.h Gui/settings/PreferenceWidget.h
......
...@@ -23,12 +23,13 @@ ...@@ -23,12 +23,13 @@
#include "SettingValue.h" #include "SettingValue.h"
#include <QtDebug> #include <QtDebug>
SettingValue::SettingValue( const QVariant& defaultValue, const QString &name, SettingValue::SettingValue( SettingValue::Type type, const QVariant& defaultValue,
const QString& desc ) : const QString &name, const QString& desc ) :
m_val( defaultValue ), m_val( defaultValue ),
m_defaultVal( defaultValue ), m_defaultVal( defaultValue ),
m_name( name ), m_name( name ),
m_desc( desc ) m_desc( desc ),
m_type( type )
{ {
} }
...@@ -65,3 +66,9 @@ SettingValue::name() const ...@@ -65,3 +66,9 @@ SettingValue::name() const
{ {
return m_name; return m_name;
} }
SettingValue::Type
SettingValue::type() const
{
return m_type;
}
...@@ -37,13 +37,22 @@ class SettingValue : public QObject ...@@ -37,13 +37,22 @@ class SettingValue : public QObject
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY( SettingValue ); Q_DISABLE_COPY( SettingValue );
public: public:
enum Type
{
Int,
Double,
String,
Bool,
Language,
KeyboardShortcut
};
/** /**
* \brief Constructs a setting value with its default value and description * \brief Constructs a setting value with its default value and description
* *
* \param defaultValue The setting default value. * \param defaultValue The setting default value.
* \param desc The setting description * \param desc The setting description
*/ */
SettingValue( const QVariant& defaultValue, const QString& name, SettingValue( Type type, const QVariant& defaultValue, const QString& name,
const QString& desc ); const QString& desc );
/** /**
...@@ -67,6 +76,8 @@ class SettingValue : public QObject ...@@ -67,6 +76,8 @@ class SettingValue : public QObject
void restoreDefault(); void restoreDefault();
const QString &name() const; const QString &name() const;
Type type() const;
private: private:
/** /**
* \brief the QVariant containingthe value of the settings * \brief the QVariant containingthe value of the settings
...@@ -75,6 +86,7 @@ class SettingValue : public QObject ...@@ -75,6 +86,7 @@ class SettingValue : public QObject
QVariant m_defaultVal; QVariant m_defaultVal;
QString m_name; QString m_name;
QString m_desc; QString m_desc;
Type m_type;
signals: signals:
/** /**
* \brief This signal is emmited while the m_val * \brief This signal is emmited while the m_val
......
...@@ -100,11 +100,11 @@ SettingsManager::value( const QString &key, ...@@ -100,11 +100,11 @@ SettingsManager::value( const QString &key,
return NULL; return NULL;
} }
QHash<QString, QVariant> SettingsManager::SettingHash
SettingsManager::group( const QString &groupName, SettingsManager::Type type ) SettingsManager::group( const QString &groupName, SettingsManager::Type type )
{ {
QHash<QString, QVariant> ret; SettingsManager::SettingHash ret;
QReadLocker rl( &m_rwLock ); QReadLocker rl( &m_rwLock );
QString grp = groupName + '/'; QString grp = groupName + '/';
if ( type == Project ) if ( type == Project )
...@@ -115,7 +115,7 @@ SettingsManager::group( const QString &groupName, SettingsManager::Type type ) ...@@ -115,7 +115,7 @@ SettingsManager::group( const QString &groupName, SettingsManager::Type type )
for ( ; it != ed; ++it ) for ( ; it != ed; ++it )
{ {
if ( it.key().startsWith( grp ) ) if ( it.key().startsWith( grp ) )
ret.insert( it.key(), it.value()->get() ); ret.insert( it.key(), it.value() );
} }
} }
else if ( type == Vlmc ) else if ( type == Vlmc )
...@@ -127,7 +127,7 @@ SettingsManager::group( const QString &groupName, SettingsManager::Type type ) ...@@ -127,7 +127,7 @@ SettingsManager::group( const QString &groupName, SettingsManager::Type type )
{ {
if ( it.key().startsWith( grp ) ) if ( it.key().startsWith( grp ) )
{ {
ret.insert( it.key(), it.value()->get() ); ret.insert( it.key(), it.value() );
} }
} }
} }
...@@ -276,16 +276,16 @@ SettingsManager::commit( SettingsManager::Type type ) ...@@ -276,16 +276,16 @@ SettingsManager::commit( SettingsManager::Type type )
} }
void void
SettingsManager::createVar( const QString &key, const QVariant &defaultValue, SettingsManager::createVar( SettingValue::Type type, const QString &key,
const QString &name, const QString &desc, const QVariant &defaultValue, const QString &name,
SettingsManager::Type type /*= Vlmc*/ ) const QString &desc, SettingsManager::Type varType /*= Vlmc*/ )
{ {
QWriteLocker wlock( &m_rwLock ); QWriteLocker wlock( &m_rwLock );
if ( type == Vlmc && m_classicSettings.contains( key ) == false ) if ( varType == Vlmc && m_classicSettings.contains( key ) == false )
m_classicSettings.insert( key, new SettingValue( defaultValue, name, desc ) ); m_classicSettings.insert( key, new SettingValue( type, defaultValue, name, desc ) );
else if ( type == Project && m_xmlSettings.contains( key ) == false ) else if ( varType == Project && m_xmlSettings.contains( key ) == false )
m_xmlSettings.insert( key, new SettingValue( defaultValue, name, desc ) ); m_xmlSettings.insert( key, new SettingValue( type, defaultValue, name, desc ) );
else else
Q_ASSERT_X( false, __FILE__, "creating an already created variable" ); Q_ASSERT_X( false, __FILE__, "creating an already created variable" );
} }
......
...@@ -52,13 +52,36 @@ class QDomDocument; ...@@ -52,13 +52,36 @@ class QDomDocument;
#define VLMC_PROJECT_GET_BOOL( key ) SettingsManager::getInstance()->value( key, SettingsManager::Project )->get().toBool() #define VLMC_PROJECT_GET_BOOL( key ) SettingsManager::getInstance()->value( key, SettingsManager::Project )->get().toBool()
#define VLMC_CREATE_PROJECT_VAR( key, defaultValue, name, desc ) \ #define VLMC_CREATE_PROJECT_VAR( type, key, defaultValue, name, desc ) \
SettingsManager::getInstance()->createVar( key, defaultValue, QObject::tr( name ), \ SettingsManager::getInstance()->createVar( type, key, defaultValue, QObject::tr( name ), \
QObject::tr(desc), SettingsManager::Project ); QObject::tr(desc), SettingsManager::Project );
#define VLMC_CREATE_PREFERENCE( key, defaultValue, name, desc ) \
SettingsManager::getInstance()->createVar( key, defaultValue, QObject::tr( name ), \ #define VLMC_CREATE_PROJECT_INT( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Int, key, defaultValue, name, desc )
#define VLMC_CREATE_PROJECT_STRING( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, name, desc )
#define VLMC_CREATE_PROJECT_DOUBLE( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc )
#define VLMC_CREATE_PROJECT_BOOL( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc )
#define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc ) \
SettingsManager::getInstance()->createVar( type, key, defaultValue, QObject::tr( name ), \
QObject::tr(desc), SettingsManager::Vlmc ); QObject::tr(desc), SettingsManager::Vlmc );
#define VLMC_CREATE_PREFERENCE_INT( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Int, key, defaultValue, name, desc )
#define VLMC_CREATE_PREFERENCE_STRING( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, name, desc )
#define VLMC_CREATE_PREFERENCE_DOUBLE( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Double, key, defaultValue, name, desc )
#define VLMC_CREATE_PREFERENCE_LANGUAGE( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Language, key, defaultValue, name, desc )
#define VLMC_CREATE_PREFERENCE_KEYBOARD( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::KeyboardShortcut, key, defaultValue, name, desc )
#define VLMC_CREATE_PREFERENCE_BOOL( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, name, desc )
class SettingsManager : public QObject, public Singleton<SettingsManager> class SettingsManager : public QObject, public Singleton<SettingsManager>
{ {
Q_OBJECT Q_OBJECT
...@@ -79,13 +102,13 @@ class SettingsManager : public QObject, public Singleton<SettingsManager> ...@@ -79,13 +102,13 @@ class SettingsManager : public QObject, public Singleton<SettingsManager>
SettingsManager::Type = Vlmc); SettingsManager::Type = Vlmc);
SettingValue *value( const QString &key, SettingValue *value( const QString &key,
SettingsManager::Type type = Vlmc ); SettingsManager::Type type = Vlmc );
QHash<QString, QVariant> group( const QString &groupName, SettingHash group( const QString &groupName,
SettingsManager::Type type = Vlmc ); SettingsManager::Type type = Vlmc );
void createVar( const QString &key, void createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue, const QVariant &defaultValue,
const QString &name, const QString &desc, const QString &name, const QString &desc,
Type type = Vlmc ); Type varType = Vlmc );
bool watchValue( const QString &key, bool watchValue( const QString &key,
QObject* receiver, QObject* receiver,
const char *method, const char *method,
......
...@@ -166,26 +166,26 @@ void MainWindow::changeEvent( QEvent *e ) ...@@ -166,26 +166,26 @@ void MainWindow::changeEvent( QEvent *e )
void void
MainWindow::initVlmcPreferences() MainWindow::initVlmcPreferences()
{ {
VLMC_CREATE_PREFERENCE( "keyboard/defaultmode", "n", "Select mode", "Select the selection tool in the timeline" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/defaultmode", "n", "Select mode", "Select the selection tool in the timeline" );
VLMC_CREATE_PREFERENCE( "keyboard/cutmode", "x", "Cut mode", "Select the cut/razor tool in the timeline" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/cutmode", "x", "Cut mode", "Select the cut/razor tool in the timeline" );
VLMC_CREATE_PREFERENCE( "keyboard/mediapreview", "Ctrl+Return", "Media preview", "Preview the selected media, or pause the current preview" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/mediapreview", "Ctrl+Return", "Media preview", "Preview the selected media, or pause the current preview" );
VLMC_CREATE_PREFERENCE( "keyboard/renderpreview", "Space", "Render preview", "Preview the project, or pause the current preview" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/renderpreview", "Space", "Render preview", "Preview the project, or pause the current preview" );
//A bit nasty, but we better use what Qt's providing as default shortcut //A bit nasty, but we better use what Qt's providing as default shortcut
VLMC_CREATE_PREFERENCE( "keyboard/undo", QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(), "Undo", "Undo the last action" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/undo", QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit(), "Undo", "Undo the last action" );
VLMC_CREATE_PREFERENCE( "keyboard/redo", QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(), "Redo", "Redo the last action" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/redo", QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit(), "Redo", "Redo the last action" );
VLMC_CREATE_PREFERENCE( "keyboard/help", QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(), "Help", "Toggle the help page" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/help", QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit(), "Help", "Toggle the help page" );
VLMC_CREATE_PREFERENCE( "keyboard/quit", "Ctrl+Q", "Quit", "Quit VLMC" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/quit", "Ctrl+Q", "Quit", "Quit VLMC" );
VLMC_CREATE_PREFERENCE( "keyboard/preferences", "Alt+P", "Preferences", "Open VLMC preferences" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/preferences", "Alt+P", "Preferences", "Open VLMC preferences" );
VLMC_CREATE_PREFERENCE( "keyboard/fullscreen", "F", "Fullscreen", "Switch to fullscreen mode" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/fullscreen", "F", "Fullscreen", "Switch to fullscreen mode" );
VLMC_CREATE_PREFERENCE( "keyboard/newproject", QKeySequence( QKeySequence::New ).toString().toLocal8Bit(), "New project", "Open the new project wizzard" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/newproject", QKeySequence( QKeySequence::New ).toString().toLocal8Bit(), "New project", "Open the new project wizzard" );
VLMC_CREATE_PREFERENCE( "keyboard/openproject", QKeySequence( QKeySequence::Open ).toString().toLocal8Bit(), "Open a project", "Open an existing project" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/openproject", QKeySequence( QKeySequence::Open ).toString().toLocal8Bit(), "Open a project", "Open an existing project" );
VLMC_CREATE_PREFERENCE( "keyboard/save", QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(), "Save", "Save the current project" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/save", QKeySequence( QKeySequence::Save ).toString().toLocal8Bit(), "Save", "Save the current project" );
VLMC_CREATE_PREFERENCE( "keyboard/saveas", "Ctrl+Shift+S", "Save as", "Save the current project to a new file" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/saveas", "Ctrl+Shift+S", "Save as", "Save the current project to a new file" );
VLMC_CREATE_PREFERENCE( "keyboard/closeproject", QKeySequence( QKeySequence::Close ).toString().toLocal8Bit(), "Close the project", "Close the current project" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/closeproject", QKeySequence( QKeySequence::Close ).toString().toLocal8Bit(), "Close the project", "Close the current project" );
VLMC_CREATE_PREFERENCE( "keyboard/importmedia", "Ctrl+I", "Import media", "Open the import window" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/importmedia", "Ctrl+I", "Import media", "Open the import window" );
VLMC_CREATE_PREFERENCE( "keyboard/renderproject", "Ctrl+R", "Render the project", "Render the project to a file" ); VLMC_CREATE_PREFERENCE_KEYBOARD( "keyboard/renderproject", "Ctrl+R", "Render the project", "Render the project to a file" );
VLMC_CREATE_PREFERENCE( "global/VLMCLang", "en_US", "Langage", "The VLMC's UI language" ); VLMC_CREATE_PREFERENCE_LANGUAGE( "global/VLMCLang", "en_US", "Langage", "The VLMC's UI language" );
} }
void MainWindow::setupLibrary() void MainWindow::setupLibrary()
...@@ -337,18 +337,12 @@ void MainWindow::initializeDockWidgets( void ) ...@@ -337,18 +337,12 @@ void MainWindow::initializeDockWidgets( void )
void MainWindow::createGlobalPreferences() void MainWindow::createGlobalPreferences()
{ {
m_globalPreferences = new Settings( this ); m_globalPreferences = new Settings( this );
// m_globalPreferences->addWidget( tr ( "VLMC" ), m_globalPreferences->addCategorie( "general", SettingsManager::Vlmc,
// new VLMCPreferences( m_globalPreferences ), QIcon( ":/images/images/vlmc.png" ),
// QIcon( ":/images/images/vlmc.png" ), tr ( "VLMC settings" ) );
// tr ( "VLMC settings" ) ); m_globalPreferences->addCategorie( "keyboard", SettingsManager::Vlmc,
// m_globalPreferences->addWidget( tr ("Language preferences" ), QIcon( ":/images/keyboard" ),
// new LanguagePreferences( m_globalPreferences ), tr( "Keyboard Settings" ) );
// QIcon( ":/images/images/vlmc.png" ),
// tr ( "Language settings" ) );
// m_globalPreferences->addWidget( tr ("Keyboard" ),
// new KeyboardShortcut( m_globalPreferences ),
// QIcon( ":/images/keyboard" ),
// tr( "Keyboard Settings" ) );
} }
void MainWindow::createProjectPreferences() void MainWindow::createProjectPreferences()
......
/*****************************************************************************
* ISettingsCategorieWidget.h: Common interface for settings widgets.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-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 ISETTINGSCATEGORIEWIDGET_H
#define ISETTINGSCATEGORIEWIDGET_H
class QVariant;
class QWidget;
class ISettingsCategorieWidget
{
public:
virtual QWidget* widget() = 0;
virtual void save() = 0;
};
#endif // ISETTINGSCATEGORIEWIDGET_H
/*****************************************************************************
* KeyboardShortcut.h: Handle KeyboardShortcut setting type.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-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 "KeyboardShortcut.h"
#include "KeyboardShortcutInput.h"
#include "SettingValue.h"
KeyboardShortcut::KeyboardShortcut( SettingValue *s, QWidget *parent /*= NULL*/ ) :
m_setting( s )
{
m_input = new KeyboardShortcutInput( s->name(), s->get().toString(), parent );
}
QWidget*
KeyboardShortcut::widget()
{
return m_input;
}
void
KeyboardShortcut::save()
{
m_setting->set( m_input->shortcut() );
}
/*****************************************************************************
* KeyboardShortcut.cpp: Handle KeyboardShortcut setting type.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzee-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 KEYBOARDSHORTCUT_H
#define KEYBOARDSHORTCUT_H
#include "ISettingsCategorieWidget.h"
#include <stddef.h>
class KeyboardShortcutInput;
class SettingValue;
class KeyboardShortcut : public ISettingsCategorieWidget
{
public:
KeyboardShortcut( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
void save();
private:
SettingValue *m_setting;
KeyboardShortcutInput *m_input;
};
#endif // KEYBOARDSHORTCUT_H
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <QTimer> #include <QTimer>
#include <QtDebug> #include <QtDebug>
#include "SettingsManager.h"
#include "KeyboardShortcutInput.h" #include "KeyboardShortcutInput.h"
KeyboardShortcutInput::KeyboardShortcutInput( const QString& name, KeyboardShortcutInput::KeyboardShortcutInput( const QString& name,
...@@ -57,6 +58,13 @@ void KeyboardShortcutInput::mouseReleaseEvent( QMouseEvent* ) ...@@ -57,6 +58,13 @@ void KeyboardShortcutInput::mouseReleaseEvent( QMouseEvent* )
{ {
} }
QString
KeyboardShortcutInput::shortcut() const
{
QKeySequence seq( m_shortcuts[0], m_shortcuts[1], m_shortcuts[2], m_shortcuts[3] );
return seq.toString();
}
void KeyboardShortcutInput::release() void KeyboardShortcutInput::release()
{ {
QKeySequence seq( m_shortcuts[0], m_shortcuts[1], m_shortcuts[2], m_shortcuts[3] ); QKeySequence seq( m_shortcuts[0], m_shortcuts[1], m_shortcuts[2], m_shortcuts[3] );
...@@ -64,7 +72,6 @@ void KeyboardShortcutInput::release() ...@@ -64,7 +72,6 @@ void KeyboardShortcutInput::release()
m_capturing = false; m_capturing = false;
setDown( false ); setDown( false );
setText( seq.toString() ); setText( seq.toString() );
emit changed( m_name, seq.toString() );
} }
void KeyboardShortcutInput::cancel() void KeyboardShortcutInput::cancel()
......
...@@ -33,7 +33,9 @@ class KeyboardShortcutInput : public QPushButton ...@@ -33,7 +33,9 @@ class KeyboardShortcutInput : public QPushButton
public: public:
KeyboardShortcutInput( const QString& name, const QString& initialValue = QString(), QWidget* parent = NULL ); KeyboardShortcutInput( const QString& name, const QString& initialValue = QString(), QWidget* parent = NULL );
protected: QString shortcut() const;
protected:
virtual void keyPressEvent( QKeyEvent* e ); virtual void keyPressEvent( QKeyEvent* e );
virtual void mousePressEvent( QMouseEvent* e ); virtual void mousePressEvent( QMouseEvent* e );
virtual void mouseReleaseEvent( QMouseEvent* e ); virtual void mouseReleaseEvent( QMouseEvent* e );
...@@ -50,8 +52,6 @@ class KeyboardShortcutInput : public QPushButton ...@@ -50,8 +52,6 @@ class KeyboardShortcutInput : public QPushButton
unsigned int m_current; unsigned int m_current;
int m_shortcuts[4]; int m_shortcuts[4];
int m_initialValue[4]; int m_initialValue[4];
signals:
void changed( const QString&, const QString& );
}; };
#endif // KEYBOARDSHORTCUTINPUT_H #endif // KEYBOARDSHORTCUTINPUT_H
...@@ -21,19 +21,59 @@ ...@@ -21,19 +21,59 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include "ISettingsCategorieWidget.h"
#include "PreferenceWidget.h"
#include "SettingsManager.h"
#include "KeyboardShortcut.h"
#include <QFormLayout>
#include <QtDebug> #include <QtDebug>
#include <QWidget> #include <QWidget>
#include "PreferenceWidget.h" #include <QLabel>
PreferenceWidget::PreferenceWidget( const QString &categorie, SettingsManager::Type type,
QWidget *parent ) :
QWidget( parent ),
m_categorie( categorie )
{
SettingsManager::SettingHash settings =
SettingsManager::getInstance()->group( categorie, type );
QFormLayout *layout = new QFormLayout( this );
foreach ( SettingValue* s, settings.values() )
{
ISettingsCategorieWidget *widget = widgetFactory( s );
if ( widget == NULL )
layout->addRow( s->name(), new QLabel( s->description() ) );
else
{
layout->addRow( s->name(), widget->widget() );
m_settings.push_back( widget );
}
}
PreferenceWidget::PreferenceWidget( QWidget* parent ) setLayout( layout );
: QWidget( parent ) }
ISettingsCategorieWidget*
PreferenceWidget::widgetFactory( SettingValue *s )
{ {
switch ( s->type() )
{
case SettingValue::KeyboardShortcut:
return new KeyboardShortcut( s, this );
default:
return NULL;
}
} }
void
PreferenceWidget::load()
{
}
void void
PreferenceWidget::loadThemAll( const QString& part, PreferenceWidget::save()
bool defaults)
{ {
load(); foreach ( ISettingsCategorieWidget* w, m_settings )
w->save();
} }
...@@ -26,20 +26,28 @@ ...@@ -26,20 +26,28 @@
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
#include "SettingsManager.h"
class ISettingsCategorieWidget;
class SettingValue;
class PreferenceWidget : public QWidget class PreferenceWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
PreferenceWidget( QWidget* parent = 0 ); typedef QList<ISettingsCategorieWidget*> SettingsList;
PreferenceWidget( const QString& categorie, SettingsManager::Type type,
QWidget* parent = 0 );
virtual ~PreferenceWidget() {} virtual ~PreferenceWidget() {}
virtual void load() = 0; virtual void load();
virtual void save() = 0; virtual void save();
private:
ISettingsCategorieWidget *widgetFactory( SettingValue* s );
protected slots: private:
void loadThemAll( const QString& part = "default", QString m_categorie;
bool defaults = false ); SettingsList m_settings;
}; };
#endif #endif
...@@ -66,18 +66,15 @@ Settings::~Settings() ...@@ -66,18 +66,15 @@ Settings::~Settings()
{ {
} }
void Settings::addWidget( const QString& name, void Settings::addCategorie( const QString& name,
PreferenceWidget* pWidget, SettingsManager::Type type,
const QIcon& icon, const QIcon& icon,
const QString& label ) const QString& label )
{ {
connect( this, SIGNAL( loadSettings() ), pWidget, SLOT( loadThemAll() ) ); PreferenceWidget *pWidget = new PreferenceWidget( name, type, this );
// We don't want the widget to be visible // We don't want the widget to be visible
pWidget->hide(); pWidget->hide();
// Save the widget name into a property
pWidget->setProperty( "name", name );
// Add the widget to the list // Add the widget to the list
m_pWidgets.append( pWidget ); m_pWidgets.append( pWidget );
...@@ -128,10 +125,6 @@ QHBoxLayout* Settings::buildLayout() ...@@ -128,10 +125,6 @@ QHBoxLayout* Settings::buildLayout()
return hLayout; return hLayout;
} }
void Settings::save( void )
{
}
void Settings::buttonClicked( QAbstractButton* button ) void Settings::buttonClicked( QAbstractButton* button )
{ {
bool save = false; bool save = false;
...@@ -159,7 +152,8 @@ void Settings::buttonClicked( QAbstractButton* button ) ...@@ -159,7 +152,8 @@ void Settings::buttonClicked( QAbstractButton* button )
m_pWidgets.at( i )->save(); m_pWidgets.at( i )->save();
} }
if ( hide == true ) setVisible( false ); if ( hide == true )
setVisible( false );
} }