Skip to content
Permalink
Browse files
Add keyboard shortcut to actions in the UI
Also bolds action tooltip text to make it clearer.
Shortcuts live inside ({shortcut-here}) in the tooltip
  • Loading branch information
NathanW2 committed Jan 21, 2017
1 parent ad963e6 commit 6d53f83d621e1cf98c18278f0a0801042a9f07d1
Showing with 28 additions and 0 deletions.
  1. +20 −0 src/gui/qgsshortcutsmanager.cpp
  2. +8 −0 src/gui/qgsshortcutsmanager.h
@@ -103,6 +103,8 @@ bool QgsShortcutsManager::registerAction( QAction* action, const QString& defaul
QString sequence = settings.value( mSettingsPath + actionText, defaultSequence ).toString();

action->setShortcut( sequence );
action->setToolTip( "<b>" + action->toolTip() + "</b>" );
this->updateActionToolTip( action, sequence );

return true;
}
@@ -216,6 +218,7 @@ bool QgsShortcutsManager::setObjectKeySequence( QObject* object, const QString&
bool QgsShortcutsManager::setKeySequence( QAction* action, const QString& sequence )
{
action->setShortcut( sequence );
this->updateActionToolTip( action, sequence );

QString actionText = action->text();
actionText.remove( '&' ); // remove the accelerator
@@ -307,3 +310,20 @@ void QgsShortcutsManager::shortcutDestroyed()
{
mShortcuts.remove( qobject_cast<QShortcut*>( sender() ) );
}

void QgsShortcutsManager::updateActionToolTip( QAction *action, QString sequence )
{
QString current = action->toolTip();
// Remove the old shortcut.
QRegExp rx( "\\(.*\\)" );
current.replace( rx, "" );

if ( !sequence.isEmpty() )
{
action->setToolTip( current + " (" + sequence + ")" );
}
else
{
action->setToolTip( current );
}
}
@@ -231,6 +231,14 @@ class GUI_EXPORT QgsShortcutsManager : public QObject
ShortcutsHash mShortcuts;
QString mSettingsPath;
static QgsShortcutsManager* sInstance;

/**
* Updates the action to include the shortcut keys. Shortcut keys are
* included between () at the end of the action tooltop.

This comment has been minimized.

Copy link
@DelazJ

DelazJ Jan 21, 2017

Contributor

tooltip

This comment has been minimized.

Copy link
@NathanW2

NathanW2 Jan 21, 2017

Author Member

Opps thanks.

* @param action The action to append the shortcut.
* @param sequence The shortcut sequence.
*/
void updateActionToolTip( QAction* action, QString sequence );
};

#endif // QGSSHORTCUTSMANAGER_H

0 comments on commit 6d53f83

Please sign in to comment.