changeset 740:a31c8ee2e17e tonioni

Allow registering an alternative shortcut using QKeySequence so as to get the right native string
author Chris Cannam
date Thu, 06 Mar 2014 14:27:59 +0000
parents dfe543438d52
children 56ba2b03508e
files widgets/KeyReference.cpp widgets/KeyReference.h
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/KeyReference.cpp	Thu Mar 06 14:03:42 2014 +0000
+++ b/widgets/KeyReference.cpp	Thu Mar 06 14:27:59 2014 +0000
@@ -87,6 +87,13 @@
 }
 
 void
+KeyReference::registerAlternativeShortcut(QAction *action, QKeySequence shortcut)
+{
+    QString name = action->text();
+    registerAlternativeShortcut(name, shortcut.toString(QKeySequence::NativeText));
+}
+
+void
 KeyReference::registerAlternativeShortcut(QString name, QString alternative)
 {
     name.replace(tr("&"), "");
@@ -102,6 +109,12 @@
 }
 
 void
+KeyReference::registerAlternativeShortcut(QString name, QKeySequence shortcut)
+{
+    registerAlternativeShortcut(name, shortcut.toString(QKeySequence::NativeText));
+}
+
+void
 KeyReference::show()
 {
     if (m_dialog) {
@@ -147,7 +160,7 @@
                 altdesc = tr("</b>&nbsp;(%1)<b>").arg(altdesc);
             }
 
-            text += QString("<tr><td>&nbsp;<b>%1%2</b></td><td>&nbsp;%3</td><td>%4</td></tr>\n")
+            text += QString("<tr><td width=\"12%\">&nbsp;<b>%1%2</b></td><td>&nbsp;%3</td><td>%4</td></tr>\n")
                 .arg(shortcut).arg(altdesc).arg(actionName).arg(tip);
         }
     }
--- a/widgets/KeyReference.h	Thu Mar 06 14:03:42 2014 +0000
+++ b/widgets/KeyReference.h	Thu Mar 06 14:27:59 2014 +0000
@@ -20,6 +20,7 @@
 #include <QString>
 #include <vector>
 #include <map>
+#include <QKeySequence>
 
 class QAction;
 class QTextEdit;
@@ -38,9 +39,11 @@
 
     void registerShortcut(QAction *, QString overrideName = "");
     void registerAlternativeShortcut(QAction *, QString alternative);
+    void registerAlternativeShortcut(QAction *, QKeySequence alternative);
 
     void registerShortcut(QString actionName, QString shortcut, QString tipText);
     void registerAlternativeShortcut(QString actionName, QString alternative);
+    void registerAlternativeShortcut(QString actionName, QKeySequence alternative);
 
     void show();
     void hide();