Commit ae1ad6fa authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Shortcut now does work for menu items.

The code is pretty ugly, though it works. I think some refactoring will
be required sooner or later
parent f1643133
......@@ -4,16 +4,21 @@
#include "SettingsManager.h"
#include "KeyboardShortcutHelper.h"
KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QWidget* parent ) :
KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QWidget* parent, bool menu ) :
QShortcut( parent ),
m_name( name )
m_name( name ),
m_menu( menu )
{
const SettingValue* set = SettingsManager::getInstance()->getValue( "keyboard_shortcut", name );
setKey( QKeySequence( set->get().toString() ) );
if ( m_menu == false )
setKey( QKeySequence( set->get().toString() ) );
connect( set, SIGNAL( changed( const QVariant& ) ), this, SLOT( shortcutUpdated( const QVariant& ) ) );
}
void KeyboardShortcutHelper::shortcutUpdated( const QVariant& value )
{
setKey( QKeySequence( value.toString() ) );
if ( m_menu == false )
setKey( QKeySequence( value.toString() ) );
else
emit changed( m_name, value.toString() );
}
......@@ -31,15 +31,18 @@ class KeyboardShortcutHelper : public QShortcut
Q_OBJECT
public:
KeyboardShortcutHelper( const QString& name, QWidget* parent = NULL );
KeyboardShortcutHelper( const QString& name, QWidget* parent = NULL, bool menu = false );
virtual ~KeyboardShortcutHelper()
{
}
private:
QString m_name;
bool m_menu;
private slots:
void shortcutUpdated( const QVariant& value );
signals:
void changed( const QString&, const QString& );
};
#endif // KEYBOARDSHORTCUTHELPER_H
......@@ -83,6 +83,7 @@ void VLMCSettingsDefault::loadKeyboardShortcutDefaults( const QString& part )
//A bit nasty, but we better use what Qt's providing as default shortcut
ADD_SHORTCUT( "Undo", QKeySequence( QKeySequence::Undo ).toString().toLocal8Bit() );
ADD_SHORTCUT( "Redo", QKeySequence( QKeySequence::Redo ).toString().toLocal8Bit() );
ADD_SHORTCUT( "Help", QKeySequence( QKeySequence::HelpContents ).toString().toLocal8Bit() );
return ;
}
......@@ -4,6 +4,7 @@
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Ludovic Fauvet <etix@l0cal.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
......@@ -55,6 +56,8 @@
#include "LanguagePreferences.h"
#include "ProjectManager.h"
#include "KeyboardShortcut.h"
#include "SettingValue.h"
#include "SettingsManager.h"
MainWindow::MainWindow( QWidget *parent ) :
QMainWindow( parent ), m_renderer( NULL )
......@@ -75,6 +78,7 @@ MainWindow::MainWindow( QWidget *parent ) :
createStatusBar();
createGlobalPreferences();
createProjectPreferences();
initializeMenuKeyboardShortcut();
// Wizard
m_pWizard = new ProjectWizard( this );
......@@ -453,3 +457,23 @@ void MainWindow::projectChanged( const QString& projectName, bool savedStatus
title += " *";
setWindowTitle( title );
}
#define GET_SHORTCUT( instName, shortcutName ) \
const SettingValue* instName = SettingsManager::getInstance()->getValue( "keyboard_shortcut", shortcutName );\
KeyboardShortcutHelper* helper##instName = new KeyboardShortcutHelper( shortcutName, this, true ); \
connect( helper##instName, SIGNAL( changed( const QString&, const QString&) ), this, SLOT( keyboardShortcutChanged(QString,QString)) );
void MainWindow::initializeMenuKeyboardShortcut()
{
GET_SHORTCUT( help, "Help" );
m_ui.actionHelp->setShortcut( help->get().toString() );
}
void MainWindow::keyboardShortcutChanged( const QString& name, const QString& val )
{
qDebug() << "shortcut" << name << "changed to" << val;
if ( name == "Help" )
{
m_ui.actionHelp->setShortcut( val );
}
}
......@@ -66,6 +66,7 @@ private:
void createStatusBar();
void createGlobalPreferences();
void createProjectPreferences();
void initializeMenuKeyboardShortcut();
Ui::MainWindow m_ui;
QSlider* m_zoomSlider;
......@@ -95,6 +96,7 @@ private slots:
void on_actionProject_Preferences_triggered();
void toolButtonClicked( int id );
void projectChanged( const QString& projectName, bool savedStatus );
void keyboardShortcutChanged( const QString&, const QString& );
signals:
void translateDockWidgetTitle();
......
......@@ -27,7 +27,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>23</height>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
......@@ -109,9 +109,6 @@
<property name="text">
<string>Help</string>
</property>
<property name="shortcut">
<string>F1</string>
</property>
</action>
<action name="actionPreferences">
<property name="text">
......
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