From: GiWoong Kim Date: Wed, 11 Nov 2015 07:22:48 +0000 (+0900) Subject: KeySequence: activatedAmbiguously() signal handling X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~170 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a92e94173ba38e957cffbf30e8c7ed9cb233624;p=sdk%2Femulator%2Fqemu.git KeySequence: activatedAmbiguously() signal handling 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 --- diff --git a/tizen/src/ui/input/keyboardshortcut.cpp b/tizen/src/ui/input/keyboardshortcut.cpp index 8e2b52b1e0..10be0ad3f1 100644 --- a/tizen/src/ui/input/keyboardshortcut.cpp +++ b/tizen/src/ui/input/keyboardshortcut.cpp @@ -53,6 +53,18 @@ QMap &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 &list) { for (int index = 0; index < list.count(); index++) { @@ -60,8 +72,10 @@ void KeyboardShortcut::registerHwKeyShortcuts(QList &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); } diff --git a/tizen/src/ui/input/keyboardshortcut.h b/tizen/src/ui/input/keyboardshortcut.h index 35e98b5851..86045520f0 100644 --- a/tizen/src/ui/input/keyboardshortcut.h +++ b/tizen/src/ui/input/keyboardshortcut.h @@ -51,6 +51,7 @@ public: public slots: void slotHwKeyShortcut(int keycode); + void slotAmbiguousShortcut(); private: MainWindow *win; diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index e8dcb37210..d24cae44a3 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -217,9 +217,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); @@ -241,9 +239,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); @@ -274,23 +270,17 @@ void ContextMenu::createSwitchItem(QMenu *menu, MenuItem *item) QMap::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())); } } @@ -338,23 +328,17 @@ void ContextMenu::createScaleItem(QMenu *menu, MenuItem *item) QMap::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())); } } @@ -411,23 +395,17 @@ void ContextMenu::createControllerItem(QMenu *menu, MenuItem *item) QMap::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())); } } @@ -588,12 +566,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 */ @@ -621,6 +608,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"); diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h index 83e0772569..63dc565140 100644 --- a/tizen/src/ui/menu/contextmenu.h +++ b/tizen/src/ui/menu/contextmenu.h @@ -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);