KeySequence: activatedAmbiguously() signal handling
authorGiWoong Kim <giwoong.kim@samsung.com>
Wed, 11 Nov 2015 07:22:48 +0000 (16:22 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Mon, 23 Nov 2015 08:29:05 +0000 (17:29 +0900)
When a key sequence is being typed at the keyboard, it is said
to be ambiguous as long as it matches the start of more than one shortcut.
When a shortcut's key sequence is completed, activatedAmbiguously() is
emitted if the key sequence is still ambiguous (i.e., it is the start of
one or more other shortcuts). The activated() signal is not emitted in this case.

A warning message box will show up in Emulator when
conflicted shortcut key is typed by user.

Change-Id: I62538ed48ec02786f70565652c7cd734992ec06a
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
(cherry picked from commit 0a92e94173ba38e957cffbf30e8c7ed9cb233624)

tizen/src/ui/input/keyboardshortcut.cpp
tizen/src/ui/input/keyboardshortcut.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h

index 8e2b52b1e0d4ef08b6b867e62164148216c111cc..10be0ad3f1932c4fc2baeb95211a9217bf2d7c45 100644 (file)
@@ -53,6 +53,18 @@ QMap<HardwareKey *, QShortcut *> &KeyboardShortcut::getHwKeyShortcutMap()
     return hwKeyShortcutMap;
 }
 
+void KeyboardShortcut::slotAmbiguousShortcut()
+{
+    /* When a shortcut's key sequence is completed, activatedAmbiguously()
+     * is emitted if the key sequence is still ambiguous (i.e., it is the
+     * start of one or more other shortcuts). */
+    qWarning("one shortcut key was overlapped with another");
+
+    QMessageBox::warning(win, EMULATOR_TITLE,
+        "When a key sequence is being typed at the keyboard, "\
+        "it is said to be ambiguous as long as it matches the start of more than one shortcut.");
+}
+
 void KeyboardShortcut::registerHwKeyShortcuts(QList<HardwareKey *> &list)
 {
     for (int index = 0; index < list.count(); index++) {
@@ -60,8 +72,10 @@ void KeyboardShortcut::registerHwKeyShortcuts(QList<HardwareKey *> &list)
         if (hwKey && hwKey->getKeySequence().isEmpty() == false) {
             QShortcut *shortcut = new QShortcut(hwKey->getKeySequence(), win);
 
-            connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
             mapper->setMapping(shortcut, hwKey->getKeycode());
+            connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
+            connect(shortcut, SIGNAL(activatedAmbiguously()),
+                this, SLOT(slotAmbiguousShortcut()));
 
             hwKeyShortcutMap.insert(hwKey, shortcut);
         }
index 35e98b5851c3ee1ab5a1d5f1931d5ceaa94e05aa..86045520f06f125a9c04a2cd7532d3c165c77f1b 100644 (file)
@@ -51,6 +51,7 @@ public:
 
 public slots:
     void slotHwKeyShortcut(int keycode);
+    void slotAmbiguousShortcut();
 
 private:
     MainWindow *win;
index 7d4ef07fcfd3c30bb6afef26288d67687dbf2562..d36fdd708fe37210e237d5bb82477662fdfcd710 100644 (file)
@@ -213,9 +213,7 @@ void ContextMenu::createOnTopItem(QMenu *menu, MenuItem *item)
     if (item->getShortcuts().isEmpty() == false) {
         QShortcut *shortcut = new QShortcut(
             item->getShortcuts().begin().value(), parent);
-        connect(shortcut, SIGNAL(activated()), this, SLOT(slotTopMostShortcut()));
-
-        actionTopMost->setShortcut(shortcut->key());
+        attachShortcut(actionTopMost, shortcut, SLOT(slotTopMostShortcut()));
     }
 
     item->setAction(actionTopMost);
@@ -236,9 +234,7 @@ void ContextMenu::createMoveItem(QMenu *menu, MenuItem *item)
     if (item->getShortcuts().isEmpty() == false) {
         QShortcut *shortcut = new QShortcut(
             item->getShortcuts().begin().value(), parent);
-        connect(shortcut, SIGNAL(activated()), this, SLOT(slotMove()));
-
-        actionMove->setShortcut(shortcut->key());
+        attachShortcut(actionMove, shortcut, SLOT(slotMove()));
     }
 
     item->setAction(actionMove);
@@ -269,23 +265,17 @@ void ContextMenu::createSwitchItem(QMenu *menu, MenuItem *item)
             QMap<QString, QKeySequence>::const_iterator iter;
             if ((iter = shortcuts.find("prev")) != shortcuts.end()) {
                 QShortcut *shortcut = new QShortcut(iter.value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotSwitchShortcutPrev()));
-
-                switchAction->setShortcut(shortcut->key());
+                attachShortcut(switchAction, shortcut, SLOT(slotSwitchShortcutPrev()));
             }
             if ((iter = shortcuts.find("next")) != shortcuts.end()) {
                 QShortcut *shortcut = new QShortcut(iter.value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotSwitchShortcutNext()));
-
-                switchAction->setShortcut(shortcut->key());
+                attachShortcut(switchAction, shortcut, SLOT(slotSwitchShortcutNext()));
             }
 
             if (switchAction->shortcut().isEmpty() == true) {
                 QShortcut *shortcut = new QShortcut(
                     item->getShortcuts().begin().value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotSwitchShortcutNext()));
-
-                switchAction->setShortcut(shortcut->key());
+                attachShortcut(switchAction, shortcut, SLOT(slotSwitchShortcutNext()));
             }
         }
 
@@ -333,23 +323,17 @@ void ContextMenu::createScaleItem(QMenu *menu, MenuItem *item)
             QMap<QString, QKeySequence>::const_iterator shortcutIter;
             if ((shortcutIter = shortcuts.find("prev")) != shortcuts.end()) {
                 QShortcut *shortcut = new QShortcut(shortcutIter.value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotScaleShortcutPrev()));
-
-                scaleAction->setShortcut(shortcut->key());
+                attachShortcut(scaleAction, shortcut, SLOT(slotScaleShortcutPrev()));
             }
             if ((shortcutIter = shortcuts.find("next")) != shortcuts.end()) {
                 QShortcut *shortcut = new QShortcut(shortcutIter.value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotScaleShortcutNext()));
-
-                scaleAction->setShortcut(shortcut->key());
+                attachShortcut(scaleAction, shortcut, SLOT(slotScaleShortcutNext()));
             }
 
             if (scaleAction->shortcut().isEmpty() == true) {
                 QShortcut *shortcut = new QShortcut(
                     item->getShortcuts().begin().value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotScaleShortcutNext()));
-
-                scaleAction->setShortcut(shortcut->key());
+                attachShortcut(scaleAction, shortcut, SLOT(slotScaleShortcutNext()));
             }
         }
 
@@ -406,23 +390,17 @@ void ContextMenu::createControllerItem(QMenu *menu, MenuItem *item)
             QMap<QString, QKeySequence>::const_iterator iter;
             if ((iter = shortcuts.find("prev")) != shortcuts.end()) {
                 QShortcut *shortcut = new QShortcut(iter.value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotConShortcutPrev()));
-
-                conAction->setShortcut(shortcut->key());
+                attachShortcut(conAction, shortcut, SLOT(slotConShortcutPrev()));
             }
             if ((iter = shortcuts.find("next")) != shortcuts.end()) {
                 QShortcut *shortcut = new QShortcut(iter.value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotConShortcutNext()));
-
-                conAction->setShortcut(shortcut->key());
+                attachShortcut(conAction, shortcut, SLOT(slotConShortcutNext()));
             }
 
             if (conAction->shortcut().isEmpty() == true) {
                 QShortcut *shortcut = new QShortcut(
                     item->getShortcuts().begin().value(), parent);
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotConShortcutNext()));
-
-                conAction->setShortcut(shortcut->key());
+                attachShortcut(conAction, shortcut, SLOT(slotConShortcutNext()));
             }
         }
 
@@ -583,12 +561,21 @@ QAction *ContextMenu::addGeneralAction(QMenu *menu,
     action->setIcon(icon);
     connect(action, SIGNAL(triggered()), this, slot);
 
-    if (shortcut != NULL) {
+    attachShortcut(action, shortcut, slot);
+
+    return action;
+}
+
+void ContextMenu::attachShortcut(
+    QAction *action, QShortcut *shortcut, const char *slot)
+{
+    if (action != NULL && shortcut != NULL) {
         connect(shortcut, SIGNAL(activated()), this, slot);
+        connect(shortcut, SIGNAL(activatedAmbiguously()),
+            this, SLOT(slotAmbiguousShortcut()));
+
         action->setShortcut(shortcut->key());
     }
-
-    return action;
 }
 
 /* override */
@@ -615,6 +602,18 @@ bool ContextMenu::eventFilter(QObject *obj, QEvent *event)
     return QObject::eventFilter(obj, event);
 }
 
+void ContextMenu::slotAmbiguousShortcut()
+{
+    /* When a shortcut's key sequence is completed, activatedAmbiguously()
+     * is emitted if the key sequence is still ambiguous (i.e., it is the
+     * start of one or more other shortcuts). */
+    qWarning("one shortcut key was overlapped with another");
+
+    QMessageBox::warning(parent, EMULATOR_TITLE,
+        "When a key sequence is being typed at the keyboard, "\
+        "it is said to be ambiguous as long as it matches the start of more than one shortcut.");
+}
+
 void ContextMenu::slotDetailedInfo()
 {
     qDebug("VM info");
index 83e0772569b7c0863d0bd31bfbbd7aee804addb6..63dc565140ef2aaa0a3e76fc3a5c68b8978b1629 100644 (file)
@@ -69,9 +69,9 @@ public:
 
     ScreenShotDialog *screenshotDialog;
 
-signals:
-
 public slots:
+    void slotAmbiguousShortcut();
+
     void slotDetailedInfo();
     void slotTopMost(bool on);
     void slotTopMostShortcut();
@@ -123,6 +123,8 @@ protected:
 private:
     QAction *addGeneralAction(QMenu *menu, const QIcon &icon,
         const QString &text, QShortcut *shortcut, const char *slot);
+    void attachShortcut(QAction *action, QShortcut *shortcut, const char *slot);
+
     QMessageBox *showMsgBox(QMessageBox::Icon iconType, const QString &text,
         QMessageBox::StandardButtons buttons = QMessageBox::NoButton,
         QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);