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++) {
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);
}
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);
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);
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()));
}
}
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()));
}
}
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()));
}
}
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 */
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");