Commit 56264f75 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Reworked menu shortcuts handling

parent 48bb700f
/*****************************************************************************
* KeyboardShortcutHelper.cpp: An helper to catch keyboard shortcut modifications
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* 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.
*****************************************************************************/
#include <QtDebug>
#include <QAction>
#include "SettingValue.h"
#include "SettingsManager.h"
#include "KeyboardShortcutHelper.h"
KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QWidget* parent, bool menu ) :
KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QWidget* parent ) :
QShortcut( parent ),
m_name( name ),
m_menu( menu )
m_action( NULL )
{
if ( m_menu == false )
{
QString set = VLMC_GET_STRING( name );
setKey( QKeySequence( set ) );
}
QString set = VLMC_GET_STRING( name );
setKey( QKeySequence( set ) );
SettingsManager::getInstance()->watchValue( name, this,
SLOT( shortcutUpdated( const QVariant& ) ),
SettingsManager::Vlmc );
}
KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QAction *action,
QWidget *parent /*= NULL*/ ) :
QShortcut( parent ),
m_name( name ),
m_action( action )
{
}
void KeyboardShortcutHelper::shortcutUpdated( const QVariant& value )
{
if ( m_menu == false )
if ( m_action == NULL )
setKey( QKeySequence( value.toString() ) );
else
emit changed( m_name, value.toString() );
m_action->setShortcut( value.toString() );
}
......@@ -26,23 +26,25 @@
#include <QShortcut>
#include <QString>
class QAction;
class KeyboardShortcutHelper : public QShortcut
{
Q_OBJECT
public:
KeyboardShortcutHelper( const QString& name, QWidget* parent = NULL, bool menu = false );
KeyboardShortcutHelper( const QString &name, QWidget* parent = NULL );
KeyboardShortcutHelper( const QString &name, QAction *action,
QWidget *parent = NULL );
virtual ~KeyboardShortcutHelper()
{
}
private:
QString m_name;
bool m_menu;
QAction *m_action;
private slots:
void shortcutUpdated( const QVariant& value );
signals:
void changed( const QString&, const QString& );
};
#endif // KEYBOARDSHORTCUTHELPER_H
......@@ -511,8 +511,7 @@ void MainWindow::on_actionRedo_triggered()
#define INIT_SHORTCUT( instName, shortcutName, actionInstance ) \
QString instName = VLMC_GET_STRING( shortcutName ); \
KeyboardShortcutHelper* helper##instName = new KeyboardShortcutHelper( shortcutName, this, true ); \
connect( helper##instName, SIGNAL( changed( const QString&, const QString&) ), this, SLOT( keyboardShortcutChanged(const QString&, const QString&)) ); \
KeyboardShortcutHelper* helper##instName = new KeyboardShortcutHelper( shortcutName, m_ui.actionInstance, this ); \
m_ui.actionInstance->setShortcut( instName );
void MainWindow::initializeMenuKeyboardShortcut()
......@@ -534,38 +533,6 @@ void MainWindow::initializeMenuKeyboardShortcut()
#undef INIT_SHORTCUT
void MainWindow::keyboardShortcutChanged( const QString& name, const QString& val )
{
if ( name == "keyboard/help" )
m_ui.actionHelp->setShortcut( val );
else if ( name == "keyboard/quit" )
m_ui.actionQuit->setShortcut( val );
else if ( name == "keyboard/preferences" )
m_ui.actionPreferences->setShortcut( val );
else if ( name == "keyboard/fullscreen" )
m_ui.actionFullscreen->setShortcut( val );
else if ( name == "keyboard/newproject" )
m_ui.actionNew_Project->setShortcut( val );
else if ( name == "keyboard/openproject" )
m_ui.actionLoad_Project->setShortcut( val );
else if ( name == "keyboard/save" )
m_ui.actionSave->setShortcut( val );
else if ( name == "keyboard/saveas" )
m_ui.actionSave_As->setShortcut( val );
else if ( name == "keyboard/closeproject" )
m_ui.actionClose_Project->setShortcut( val );
else if ( name == "keyboard/importmedia" )
m_ui.actionImport->setShortcut( val );
else if ( name == "keyboard/renderproject" )
m_ui.actionRender->setShortcut( val );
else if ( name == "keyboard/undo" )
m_ui.actionUndo->setShortcut( val );
else if ( name == "keyboard/redo" )
m_ui.actionRedo->setShortcut( val );
else
qWarning() << "Unknown shortcut:" << name;
}
void MainWindow::on_actionCrash_triggered()
{
//WARNING: read this part at your own risk !!
......
......@@ -112,7 +112,6 @@ private slots:
void on_actionImport_triggered();
void toolButtonClicked( int id );
void projectUpdated( const QString& projectName, bool savedStatus );
void keyboardShortcutChanged( const QString&, const QString& );
void canUndoChanged( bool canUndo );
void canRedoChanged( bool canRedo );
......
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