Commit 41f72688 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Keyboard shortcut are now configurable.

Shortcut creation must be updated to use the newly created
KeyboardShortcutHelper, else, it won't receive updated values.
parent 200de258
#include <QtDebug>
#include "SettingValue.h"
#include "SettingsManager.h"
#include "KeyboardShortcutHelper.h"
KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QWidget* parent ) :
QShortcut( parent ),
m_name( name )
{
const SettingValue* set = SettingsManager::getInstance()->getValue( "keyboard_shortcut", name );
qDebug() << set->get().toString();
setKey( QKeySequence( set->get().toString() ) );
connect( set, SIGNAL( changed( const QVariant& ) ), this, SLOT( shortcutUpdated( const QVariant& ) ) );
}
void KeyboardShortcutHelper::shortcutUpdated( const QVariant& value )
{
qDebug() << "Key sequence updated:" << value.toString();
setKey( QKeySequence( value.toString() ) );
}
/*****************************************************************************
* KeyboardShortcutHelper.h: An helper to catch keyboard shortcut modifications
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <beauze.h@gmail.com>
*
* 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 KEYBOARDSHORTCUTHELPER_H
#define KEYBOARDSHORTCUTHELPER_H
#include <QShortcut>
#include <QString>
class KeyboardShortcutHelper : public QShortcut
{
Q_OBJECT
public:
KeyboardShortcutHelper( const QString& name, QWidget* parent = NULL );
virtual ~KeyboardShortcutHelper()
{
}
private:
QString m_name;
private slots:
void shortcutUpdated( const QVariant& value );
};
#endif // KEYBOARDSHORTCUTHELPER_H
HEADERS += Commands.h
SOURCES += Commands.cpp
HEADERS += Commands.h \
KeyboardShortcutHelper.h
SOURCES += Commands.cpp \
KeyboardShortcutHelper.cpp
......@@ -4,6 +4,7 @@
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Christophe Courtaut <christophe.courtaut@gmail.com>
* Hugo Beauzee-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -22,6 +23,8 @@
#include "UndoStack.h"
#include "ProjectManager.h"
#include "SettingsManager.h"
#include "KeyboardShortcutHelper.h"
UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
{
......@@ -34,10 +37,11 @@ UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
connect( ProjectManager::getInstance(), SIGNAL( projectSaved() ),
m_undoStack, SLOT( setClean() ) );
m_undoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+z", "Undo" ) ), this );
m_redoShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+z", "Redo" ) ), this );
m_undoShortcut = new KeyboardShortcutHelper( "Undo", this );
m_redoShortcut = new KeyboardShortcutHelper( "Redo", this );
connect( m_undoShortcut, SIGNAL( activated() ), m_undoStack, SLOT( undo() ) );
connect( m_redoShortcut, SIGNAL( activated() ), m_undoStack, SLOT( redo() ) );
}
void UndoStack::push( QUndoCommand* command )
......
......@@ -25,8 +25,9 @@
#include <QUndoStack>
#include <QUndoView>
#include <QShortcut>
#include <QUndoCommand>
#include "KeyboardShortcutHelper.h"
#include "QSingleton.hpp"
class UndoStack : public QUndoView, public QSingleton<UndoStack>
......@@ -40,9 +41,9 @@ class UndoStack : public QUndoView, public QSingleton<UndoStack>
private:
UndoStack( QWidget* parent );
QUndoStack* m_undoStack;
QShortcut* m_undoShortcut;
QShortcut* m_redoShortcut;
QUndoStack* m_undoStack;
KeyboardShortcutHelper* m_undoShortcut;
KeyboardShortcutHelper* m_redoShortcut;
signals:
void cleanChanged( bool val );
......
......@@ -38,7 +38,10 @@ KeyboardShortcut::KeyboardShortcut( QWidget* parent ) :
while ( it != ite )
{
m_keySeq[it.key()] = new QKeySequence( it.value()->get().toString() );
m_layout->addRow( it.key(), new KeyboardShortcutInput( m_keySeq[it.key()]->toString(), this ) );
KeyboardShortcutInput* ksi = new KeyboardShortcutInput( it.key(), m_keySeq[it.key()]->toString(), this );
m_layout->addRow( it.key(), ksi );
connect( ksi, SIGNAL( changed( const QString&, const QString& ) ),
this, SLOT( shortcutUpdated( const QString&, const QString& ) ) );
++it;
}
setLayout( m_layout );
......@@ -55,3 +58,9 @@ void KeyboardShortcut::load()
void KeyboardShortcut::save()
{
}
void KeyboardShortcut::shortcutUpdated( const QString& name, const QString& value )
{
qDebug() << "Shortcut updated:" << name << "value:" << value;
SettingsManager::getInstance()->setValue( "keyboard_shortcut", name, value );
}
......@@ -23,6 +23,7 @@
#ifndef KEYBOARDSHORTCUT_H
#define KEYBOARDSHORTCUT_H
#include <QObject>
#include <QFormLayout>
#include <QHash>
#include <QString>
......@@ -32,11 +33,16 @@
class KeyboardShortcut : public PreferenceWidget
{
Q_OBJECT
public:
KeyboardShortcut( QWidget* parent = 0 );
virtual ~KeyboardShortcut();
void load();
void save();
private slots:
void shortcutUpdated( const QString& name, const QString& value );
private:
QFormLayout* m_layout;
QHash<QString, QKeySequence*> m_keySeq;
......
......@@ -26,8 +26,10 @@
#include "KeyboardShortcutInput.h"
KeyboardShortcutInput::KeyboardShortcutInput( const QString& initialValue, QWidget* parent ) :
KeyboardShortcutInput::KeyboardShortcutInput( const QString& name,
const QString& initialValue, QWidget* parent ) :
QPushButton( parent ),
m_name( name ),
m_capturing( false ),
m_current( 0 )
{
......@@ -52,8 +54,11 @@ void KeyboardShortcutInput::mouseReleaseEvent( QMouseEvent* )
void KeyboardShortcutInput::release()
{
QKeySequence seq( m_shortcuts[0], m_shortcuts[1], m_shortcuts[2], m_shortcuts[3] );
m_capturing = false;
setDown( false );
emit changed( m_name, seq.toString() );
}
void KeyboardShortcutInput::keyPressEvent( QKeyEvent* e )
......
......@@ -31,7 +31,7 @@ class KeyboardShortcutInput : public QPushButton
Q_OBJECT
public:
KeyboardShortcutInput( const QString& initialValue = QString(), QWidget* parent = NULL );
KeyboardShortcutInput( const QString& name, const QString& initialValue = QString(), QWidget* parent = NULL );
protected:
virtual void keyPressEvent( QKeyEvent* e );
virtual void mousePressEvent( QMouseEvent* e );
......@@ -42,10 +42,13 @@ class KeyboardShortcutInput : public QPushButton
void timeout();
private:
QString m_name;
bool m_capturing;
QTimer* m_timer;
unsigned int m_current;
int m_shortcuts[4];
signals:
void changed( const QString&, const QString& );
};
#endif // KEYBOARDSHORTCUTINPUT_H
......@@ -25,7 +25,6 @@
#include <QWidget>
#include "PreferenceWidget.h"
PreferenceWidget::PreferenceWidget( QWidget* parent )
: QWidget( parent ),
m_defaults( false ),
......
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