shortcut: refactoring for context menu shortcut
authorGiWoong Kim <giwoong.kim@samsung.com>
Mon, 17 Aug 2015 09:39:17 +0000 (18:39 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Mon, 17 Aug 2015 12:47:17 +0000 (21:47 +0900)
- remove unnecessary shortcut map and menu item parser
from KeyboardShortcut class
- menu shortcut informations are collected directly
by Detailed Info dialog
- use a icon text for Detailed Info menu name

Change-Id: Id1300fa3f82c4ab583cf60a7155ede882a69f718
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/input/keyboardshortcut.cpp
tizen/src/ui/input/keyboardshortcut.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/menu/detailedinfodialog.cpp
tizen/src/ui/menu/detailedinfodialog.h
tizen/src/ui/menu/menuitem.cpp
tizen/src/ui/menu/menuitem.h
tizen/src/ui/xmllayoutparser.cpp
tizen/src/ui/xmllayoutparser.h

index e23a3fa1ea5f7512af3bd8a45838f848a37a3d1b..c3baebee0a98045ef17eec61be4e4156d8e63037 100644 (file)
@@ -66,18 +66,6 @@ void KeyboardShortcut::removeHwKeyShortcut()
     qDebug() << "Removed hwKey shortcuts";
 }
 
-void KeyboardShortcut::removePopupMenuShortcut()
-{
-    for (int index = 0; index < popupMenuShortcutList.count(); index++) {
-        delete popupMenuShortcutList.at(index);
-    }
-
-    popupMenuShortcutList.clear();
-    popupMenuShortcutMap.clear();
-
-    qDebug() << "Removed popupMenu shortcuts";
-}
-
 void KeyboardShortcut::registShortcutKey(QShortcut *shortcut, QString item)
 {
     QSignalMapper *mapper = new QSignalMapper(this);
@@ -165,226 +153,6 @@ void KeyboardShortcut::setKeyboardShortcutHwKey()
     }
 }
 
-void KeyboardShortcut::setKeyboardShortcutContextMenu(
-    MenuItem *item, QString property, QString keySequence)
-{
-    QShortcut *shortcut = new QShortcut(QKeySequence::fromString(keySequence), parent);
-    int itemType = item->getType();
-    QString itemName = item->getName();
-
-    switch (itemType) {
-        case MenuItemType::closeItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutClose()));
-            break;
-        case MenuItemType::infoItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutDetailedInfo()));
-            if (itemName.isEmpty()) {
-                itemName = DETAILED_INFO_TITLE;
-            }
-            break;
-        case MenuItemType::onTopItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutTopMost()));
-            break;
-        case MenuItemType::hostKeyboardItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutHostKeyboard()));
-            break;
-        case MenuItemType::forceCloseItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutForceClose()));
-            break;
-        case MenuItemType::shellItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutShell()));
-            break;
-        case MenuItemType::controlPanelItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutControlPanel()));
-            break;
-        case MenuItemType::screenShotItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutRequestScreenshot()));
-            break;
-        case MenuItemType::controllerItem:
-            connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutController()));
-            break;
-        case MenuItemType::scaleItem:
-            if (property == "prev") {
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutScalePrev()));
-            } else if (property == "next") {
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutScaleNext()));
-            } else {
-                qDebug() << "undefined property: " << property;
-            }
-            break;
-        case MenuItemType::switchItem:
-            if (property == "prev") {
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutSwitchPrev()));
-            } else if (property == "next") {
-                connect(shortcut, SIGNAL(activated()), this, SLOT(slotShortcutSwitchNext()));
-            } else {
-                qDebug() << "undefined property: " << property;
-            }
-            break;
-        default:
-            qDebug() << "undefined item type: " << itemType;
-            return;
-    }
-
-    if (!property.isEmpty()) {
-        itemName.append(" " + property);
-    }
-
-    popupMenuShortcutList.append(shortcut);
-    popupMenuShortcutMap.insert(itemName, keySequence);
-}
-
-void KeyboardShortcut::slotShortcutClose()
-{
-    parent->getPopupMenu()->slotClose();
-}
-
-void KeyboardShortcut::slotShortcutDetailedInfo()
-{
-    parent->getPopupMenu()->slotDetailedInfo();
-}
-
-void KeyboardShortcut::slotShortcutShell()
-{
-    parent->getPopupMenu()->slotShell();
-}
-
-void KeyboardShortcut::slotShortcutRequestScreenshot()
-{
-    parent->getPopupMenu()->slotRequestScreenshot();
-}
-
-void KeyboardShortcut::slotShortcutForceClose()
-{
-    parent->getPopupMenu()->slotForceClose();
-}
-
-void KeyboardShortcut::slotShortcutControlPanel()
-{
-    parent->getPopupMenu()->slotControlPanel();
-}
-
-void KeyboardShortcut::slotShortcutTopMost()
-{
-    QAction *action = parent->getPopupMenu()->getActionTopMost();
-    parent->getPopupMenu()->slotTopMost(!action->isChecked());
-}
-
-void KeyboardShortcut::slotShortcutSwitchPrev()
-{
-    QAction *action = parent->getPopupMenu()->switchGroup->checkedAction();
-    QList<QAction *> switchList = parent->getPopupMenu()->switchGroup->actions();
-
-    if (!action) {
-        qWarning() << "switch prev failed.";
-        return;
-    }
-
-    int index = switchList.indexOf(action);
-    if (index == switchList.count() - 1) {
-        index = 0;
-    } else {
-        index++;
-    }
-
-    QAction *nextSwitchAction = switchList.at(index);
-    nextSwitchAction->setChecked(true);
-    nextSwitchAction->trigger();
-}
-
-void KeyboardShortcut::slotShortcutSwitchNext()
-{
-    QAction *action = parent->getPopupMenu()->switchGroup->checkedAction();
-    QList<QAction *> switchList = parent->getPopupMenu()->switchGroup->actions();
-
-    if (!action) {
-        qWarning() << "switch next failed.";
-        return;
-    }
-
-    int index = switchList.indexOf(action);
-    if (index == 0) {
-        index = switchList.count() - 1;
-    } else {
-        index--;
-    }
-
-    QAction *nextSwitchAction = switchList.at(index);
-    nextSwitchAction->setChecked(true);
-    nextSwitchAction->trigger();
-}
-
-void KeyboardShortcut::slotShortcutScaleNext()
-{
-    QAction *action = parent->getPopupMenu()->scaleGroup->checkedAction();
-    QList<QAction *> scaleList = parent->getPopupMenu()->scaleGroup->actions();
-
-    if (!action) {
-        qWarning() << "scale next failed.";
-        return;
-    }
-
-    int index = scaleList.indexOf(action);
-    if (index == 0) {
-        index = scaleList.count() - 1;
-    } else {
-        index--;
-    }
-
-    QAction *nextScaleAction = scaleList.at(index);
-    nextScaleAction->setChecked(true);
-    nextScaleAction->trigger();
-}
-
-void KeyboardShortcut::slotShortcutScalePrev()
-{
-    QAction *action = parent->getPopupMenu()->scaleGroup->checkedAction();
-    QList<QAction *> scaleList = parent->getPopupMenu()->scaleGroup->actions();
-
-    if (!action) {
-        qWarning() << "scale prev failed.";
-        return;
-    }
-
-    int index = scaleList.indexOf(action);
-    if (index == scaleList.count() - 1) {
-        index = 0;
-    } else {
-        index++;
-    }
-
-    QAction *nextScaleAction = scaleList.at(index);
-    nextScaleAction->setChecked(true);
-    nextScaleAction->trigger();
-}
-
-void KeyboardShortcut::slotShortcutController()
-{
-    QAction *action = parent->getPopupMenu()->controllerGroup->checkedAction();
-    QList<QAction *> controllerList = parent->getPopupMenu()->controllerGroup->actions();
-
-    if (!action) {
-        qWarning() << "change controller failed.";
-        return;
-    }
-
-    int last_index = controllerList.count() - 1;
-    int index = controllerList.indexOf(action) + 1;
-
-    if (index > last_index) {
-        index = 0;
-    }
-
-    QAction *nextControllerAction = controllerList.at(index);
-    if (!nextControllerAction) {
-        qWarning() << "controllerList.at(" << index << ") is NULL";
-        return;
-    }
-
-    nextControllerAction->setChecked(true);
-    nextControllerAction->trigger();
-}
-
 void KeyboardShortcut::slotShortcutHostKeyboard()
 {
     QAction *action = parent->getPopupMenu()->keyboardGroup->checkedAction();
@@ -459,21 +227,11 @@ QList<QShortcut *> KeyboardShortcut::getControllerShortcutList()
     return controllerShortcutList;
 }
 
-QList<QShortcut *> KeyboardShortcut::getPopupMenuShortcutList()
-{
-    return popupMenuShortcutList;
-}
-
 QList<QShortcut *> KeyboardShortcut::getHwKeyShortcutList()
 {
     return hwKeyShortcutList;
 }
 
-QMap<QString, QString> KeyboardShortcut::getPopupMenuShortcutMap()
-{
-    return popupMenuShortcutMap;
-}
-
 QMap<QString, QString> KeyboardShortcut::getHwKeyShortcutMap()
 {
     return hwKeyShortcutMap;
@@ -488,7 +246,6 @@ KeyboardShortcut::~KeyboardShortcut()
 {
     removeHwKeyShortcut();
     removeControllerShortcut();
-    removePopupMenuShortcut();
 
     qDebug("destroy keyboard shortcut");
 }
index c91d9c1abac9b2764412a45ac00b9bf200659c92..39544874e1b39c75e28f160c9c62ed698d7eeb54 100644 (file)
@@ -36,7 +36,6 @@
 #include <QMap>
 
 #include "layout/hardwarekey.h"
-#include "menu/menuitem.h"
 
 class MainWindow;
 
@@ -50,33 +49,17 @@ public:
 
     void setKeyboardShortcutHwKey();
     void setKeyboardShortcutController();
-    void setKeyboardShortcutContextMenu(MenuItem *item, QString property, QString keySequence);
     void removeControllerShortcut();
     void removeHwKeyShortcut();
-    void removePopupMenuShortcut();
 
     QList<QShortcut *> getControllerShortcutList();
-    QList<QShortcut *> getPopupMenuShortcutList();
     QList<QShortcut *> getHwKeyShortcutList();
-    QMap<QString, QString> getPopupMenuShortcutMap();
     QMap<QString, QString> getHwKeyShortcutMap();
     QMap<QString, QString> getControllerShortcutMap();
 
 public slots:
     void slotShortcutHwKey(const QString &name);
-    void slotShortcutClose();
-    void slotShortcutDetailedInfo();
-    void slotShortcutControlPanel();
-    void slotShortcutShell();
-    void slotShortcutRequestScreenshot();
-    void slotShortcutForceClose();
     void slotShortcutHostKeyboard();
-    void slotShortcutController();
-    void slotShortcutScalePrev();
-    void slotShortcutScaleNext();
-    void slotShortcutSwitchPrev();
-    void slotShortcutSwitchNext();
-    void slotShortcutTopMost();
 
 private:
     void registShortcutKey(QShortcut *shortcut, QString item);
@@ -86,10 +69,8 @@ private:
     MainWindow *parent;
     QList<HardwareKey *> hwKeyList;
     QList<HardwareKey *> controllerKeyList;
-    QList<QShortcut *> popupMenuShortcutList;
     QList<QShortcut *> controllerShortcutList;
     QList<QShortcut *> hwKeyShortcutList;
-    QMap<QString, QString> popupMenuShortcutMap;
     QMap<QString, QString> hwKeyShortcutMap;
     QMap<QString, QString> controllerShortcutMap;
 };
index 791ac6020a4563ecf89cb32e303d027ba252882d..f21d0b329d6fa3e1db3fca8da454d2279cab2a15 100644 (file)
@@ -83,20 +83,9 @@ ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent)
 void ContextMenu::createItems(QMenu *menu, QList<MenuItem *> &list)
 {
     MenuItem *item = NULL;
-    KeyboardShortcut *keyboardShortcut = parent->getKeyboardShortcut();
-
     for (int i = 0; i < list.count(); i++) {
         item = list.at(i);
 
-        QMap<QString, QString> shortcutMap = item->getShortcutMap();
-        if (!shortcutMap.isEmpty()) {
-            QMap<QString, QString>::iterator iter;
-            for (iter = shortcutMap.begin(); iter != shortcutMap.end(); iter++) {
-                keyboardShortcut->setKeyboardShortcutContextMenu(item,
-                                                        iter.key(), iter.value());
-            }
-        }
-
         switch (item->getType()) {
         case MenuItemType::separator:
             createSeparator(menu);
@@ -181,25 +170,6 @@ void ContextMenu::createAdvancedItem(QMenu *menu, MenuItem *item)
     createItems(advancedMenu, ((AdvancedMenuItem *)item)->getMenuList());
 }
 
-QString ContextMenu::getShortcutKeySeq(QString key)
-{
-    KeyboardShortcut *keyboardShortcut = parent->getKeyboardShortcut();
-    QMap<QString, QString> shortcutMap = keyboardShortcut->getPopupMenuShortcutMap();
-    QMap<QString, QString>::iterator iter;
-    QString keySequence;
-
-    if (!shortcutMap.isEmpty()) {
-        for (iter = shortcutMap.begin(); iter != shortcutMap.end(); iter++) {
-            if (iter.key().startsWith(key)) {
-                keySequence.append(iter.value());
-                break;
-            }
-        }
-    }
-
-    return keySequence;
-}
-
 void ContextMenu::createInfoItem(QMenu *menu, MenuItem *item)
 {
     if (menu == NULL || item == NULL) {
@@ -207,9 +177,16 @@ void ContextMenu::createInfoItem(QMenu *menu, MenuItem *item)
     }
 
     QString menuName = item->getName();
-    actionDetailedInfo = addGeneralAction(menu, QIcon(QPixmap(":/icons/detailed_info.png")),
-        menuName.isEmpty() ? vmName : menuName, SLOT(slotDetailedInfo()),
-        getShortcutKeySeq(DETAILED_INFO_TITLE));
+    actionDetailedInfo = addGeneralAction(
+        menu, QIcon(QPixmap(":/icons/detailed_info.png")),
+        menuName.isEmpty() ? vmName : menuName,
+        item->getShortcutMap().isEmpty()? NULL :
+            new QShortcut(item->getShortcutMap().begin().value(), parent),
+        SLOT(slotDetailedInfo()));
+
+    actionDetailedInfo->setIconText(menuName.isEmpty() ? QString(DETAILED_INFO_TITLE) : menuName);
+
+    item->setAction(actionDetailedInfo);
 }
 
 void ContextMenu::createOnTopItem(QMenu *menu, MenuItem *item)
@@ -221,9 +198,19 @@ void ContextMenu::createOnTopItem(QMenu *menu, MenuItem *item)
     QString menuName = item->getName();
     actionTopMost = menu->addAction(
         menuName.isEmpty() ? MENU_ONTOP_ITEM_TEXT : menuName);
-    actionTopMost->setShortcut(getShortcutKeySeq(menuName));
     actionTopMost->setCheckable(true);
     connect(actionTopMost, SIGNAL(triggered(bool)), this, SLOT(slotTopMost(bool)));
+
+    /* shortcut */
+    if (item->getShortcutMap().isEmpty() == false) {
+        QShortcut *shortcut = new QShortcut(
+            item->getShortcutMap().begin().value(), parent);
+        connect(shortcut, SIGNAL(activated()), this, SLOT(slotTopMostShortcut()));
+
+        actionTopMost->setShortcut(shortcut->key());
+    }
+
+    item->setAction(actionTopMost);
 }
 
 void ContextMenu::createSwitchItem(QMenu *menu, MenuItem *item)
@@ -239,12 +226,38 @@ void ContextMenu::createSwitchItem(QMenu *menu, MenuItem *item)
         switchMenu = menu->addMenu(QIcon(QPixmap(":/icons/rotate.png")),
             menuName.isEmpty() ? MENU_SWITCH_ITEM_TEXT : menuName);
 
-        QAction *menuAction = switchMenu->menuAction();
-        menuAction->setShortcut(getShortcutKeySeq(menuName));
         switchGroup = new QActionGroup(this);
         switchMapper = new QSignalMapper(this);
         connect(switchMapper, SIGNAL(mapped(int)), this, SLOT(slotSwitch(int)));
 
+        /* shortcuts */
+        QAction *switchAction = switchMenu->menuAction();
+        QMap<QString, QKeySequence> shortcutMap = item->getShortcutMap();
+
+        if (shortcutMap.isEmpty() == false) {
+            QMap<QString, QKeySequence>::const_iterator iter;
+            if ((iter = shortcutMap.find("prev")) != shortcutMap.end()) {
+                QShortcut *shortcut = new QShortcut(iter.value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotSwitchShortcutPrev()));
+
+                switchAction->setShortcut(shortcut->key());
+            }
+            if ((iter = shortcutMap.find("next")) != shortcutMap.end()) {
+                QShortcut *shortcut = new QShortcut(iter.value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotSwitchShortcutNext()));
+
+                switchAction->setShortcut(shortcut->key());
+            }
+
+            if (switchAction->shortcut().isEmpty() == true) {
+                QShortcut *shortcut = new QShortcut(
+                    item->getShortcutMap().begin().value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotSwitchShortcutNext()));
+
+                switchAction->setShortcut(shortcut->key());
+            }
+        }
+
         QAction *action = NULL;
         for (int i = 0; i < mainFormList.count(); i++) {
             action = switchMenu->addAction(mainFormList.at(i)->getName());
@@ -260,6 +273,8 @@ void ContextMenu::createSwitchItem(QMenu *menu, MenuItem *item)
     } else {
         qWarning("cannot create a switchItem");
     }
+
+    item->setAction(switchMenu->menuAction());
 }
 
 void ContextMenu::createScaleItem(QMenu *menu, MenuItem *item)
@@ -275,25 +290,51 @@ void ContextMenu::createScaleItem(QMenu *menu, MenuItem *item)
         scaleMenu = menu->addMenu(QIcon(QPixmap(":/icons/scale.png")),
             menuName.isEmpty() ? MENU_SCALE_ITEM_TEXT : menuName);
 
-        QAction *menuAction = scaleMenu->menuAction();
-        menuAction->setShortcut(getShortcutKeySeq(menuName));
         scaleGroup = new QActionGroup(this);
         scaleMapper = new QSignalMapper(this);
         connect(scaleMapper, SIGNAL(mapped(int)), this, SLOT(slotScale(int)));
 
+        /* shortcuts */
+        QAction *scaleAction = scaleMenu->menuAction();
+        QMap<QString, QKeySequence> shortcutMap = item->getShortcutMap();
+
+        if (shortcutMap.isEmpty() == false) {
+            QMap<QString, QKeySequence>::const_iterator shortcutIter;
+            if ((shortcutIter = shortcutMap.find("prev")) != shortcutMap.end()) {
+                QShortcut *shortcut = new QShortcut(shortcutIter.value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotScaleShortcutPrev()));
+
+                scaleAction->setShortcut(shortcut->key());
+            }
+            if ((shortcutIter = shortcutMap.find("next")) != shortcutMap.end()) {
+                QShortcut *shortcut = new QShortcut(shortcutIter.value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotScaleShortcutNext()));
+
+                scaleAction->setShortcut(shortcut->key());
+            }
+
+            if (scaleAction->shortcut().isEmpty() == true) {
+                QShortcut *shortcut = new QShortcut(
+                    item->getShortcutMap().begin().value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotScaleShortcutNext()));
+
+                scaleAction->setShortcut(shortcut->key());
+            }
+        }
+
         QAction *action = NULL;
 
-        QMapIterator<int, QString> iter(factorMap);
-        iter.toBack();
-        while(iter.hasPrevious() == true) {
-            iter.previous();
+        QMapIterator<int, QString> factorIter(factorMap);
+        factorIter.toBack();
+        while(factorIter.hasPrevious() == true) {
+            factorIter.previous();
 
-            QString factorName = iter.value();
+            QString factorName = factorIter.value();
             action = scaleMenu->addAction(
-                factorName.isEmpty() ? (QString::number(iter.key()) + '%') : factorName);
+                factorName.isEmpty() ? (QString::number(factorIter.key()) + '%') : factorName);
             action->setActionGroup(scaleGroup);
             action->setCheckable(true);
-            scaleMapper->setMapping(action, iter.key());
+            scaleMapper->setMapping(action, factorIter.key());
             connect(action, SIGNAL(triggered()), scaleMapper, SLOT(map()));
         }
 
@@ -305,6 +346,8 @@ void ContextMenu::createScaleItem(QMenu *menu, MenuItem *item)
     } else {
         qWarning("cannot create a scaleItem");
     }
+
+    item->setAction(scaleMenu->menuAction());
 }
 
 void ContextMenu::createControllerItem(QMenu *menu, MenuItem *item)
@@ -320,12 +363,37 @@ void ContextMenu::createControllerItem(QMenu *menu, MenuItem *item)
         controllerMenu = menu->addMenu(
             menuName.isEmpty() ? MENU_CONTROLLER_ITEM_TEXT : menuName);
 
-        QAction *menuAction = controllerMenu->menuAction();
-        menuAction->setShortcut(getShortcutKeySeq(menuName));
         controllerGroup = new QActionGroup(this);
         controllerMapper = new QSignalMapper(this);
-        connect(controllerMapper, SIGNAL(mapped(int)), this,
-            SLOT(slotController(int)));
+        connect(controllerMapper, SIGNAL(mapped(int)), this, SLOT(slotController(int)));
+
+        /* shortcuts */
+        QAction *conAction = controllerMenu->menuAction();
+        QMap<QString, QKeySequence> shortcutMap = item->getShortcutMap();
+
+        if (shortcutMap.isEmpty() == false) {
+            QMap<QString, QKeySequence>::const_iterator iter;
+            if ((iter = shortcutMap.find("prev")) != shortcutMap.end()) {
+                QShortcut *shortcut = new QShortcut(iter.value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotConShortcutPrev()));
+
+                conAction->setShortcut(shortcut->key());
+            }
+            if ((iter = shortcutMap.find("next")) != shortcutMap.end()) {
+                QShortcut *shortcut = new QShortcut(iter.value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotConShortcutNext()));
+
+                conAction->setShortcut(shortcut->key());
+            }
+
+            if (conAction->shortcut().isEmpty() == true) {
+                QShortcut *shortcut = new QShortcut(
+                    item->getShortcutMap().begin().value(), parent);
+                connect(shortcut, SIGNAL(activated()), this, SLOT(slotConShortcutNext()));
+
+                conAction->setShortcut(shortcut->key());
+            }
+        }
 
         QAction *action = NULL;
         action = controllerMenu->addAction("None");
@@ -344,6 +412,8 @@ void ContextMenu::createControllerItem(QMenu *menu, MenuItem *item)
     } else {
         qWarning("cannot create a controllerItem");
     }
+
+    item->setAction(controllerMenu->menuAction());
 }
 
 void ContextMenu::createHostKeyboardItem(QMenu *menu, MenuItem *item)
@@ -355,19 +425,22 @@ void ContextMenu::createHostKeyboardItem(QMenu *menu, MenuItem *item)
     QString menuName = item->getName();
     QMenu *keyboardMenu = menu->addMenu(QIcon(QPixmap(":/icons/host_keyboard.png")),
         menuName.isEmpty() ? MENU_HOSTKBD_ITEM_TEXT : menuName);
-    QAction *menuAction = keyboardMenu->menuAction();
-    menuAction->setShortcut(getShortcutKeySeq(menuName));
     keyboardGroup = new QActionGroup(this);
 
-    QAction *action = keyboardMenu->addAction(MENU_ON_ITEM_TEXT);
-    action->setActionGroup(keyboardGroup);
-    action->setCheckable(true);
-    connect(action, SIGNAL(toggled(bool)), this, SLOT(slotHostKeyboard(bool)));
+    QAction *hostKbdAction = keyboardMenu->addAction(MENU_ON_ITEM_TEXT);
+    hostKbdAction->setActionGroup(keyboardGroup);
+    hostKbdAction->setCheckable(true);
+    connect(hostKbdAction, SIGNAL(toggled(bool)), this, SLOT(slotHostKeyboard(bool)));
 
-    action = keyboardMenu->addAction(MENU_OFF_ITEM_TEXT);
-    action->setActionGroup(keyboardGroup);
-    action->setCheckable(true);
-    action->setChecked(true);
+    /* shortcuts */
+    // TODO:
+
+    hostKbdAction = keyboardMenu->addAction(MENU_OFF_ITEM_TEXT);
+    hostKbdAction->setActionGroup(keyboardGroup);
+    hostKbdAction->setCheckable(true);
+    hostKbdAction->setChecked(true);
+
+    item->setAction(hostKbdAction);
 }
 
 void ContextMenu::createShellItem(QMenu *menu, MenuItem *item)
@@ -377,9 +450,14 @@ void ContextMenu::createShellItem(QMenu *menu, MenuItem *item)
     }
 
     QString menuName = item->getName();
-    actionShell = addGeneralAction(menu, QIcon(QPixmap(":/icons/shell.png")),
-        menuName.isEmpty() ? MENU_SHELL_ITEM_TEXT : menuName, SLOT(slotShell()),
-        getShortcutKeySeq(menuName));
+    actionShell = addGeneralAction(
+        menu, QIcon(QPixmap(":/icons/shell.png")),
+        menuName.isEmpty() ? MENU_SHELL_ITEM_TEXT : menuName,
+        item->getShortcutMap().isEmpty()? NULL :
+            new QShortcut(item->getShortcutMap().begin().value(), parent),
+        SLOT(slotShell()));
+
+    item->setAction(actionShell);
 }
 
 void ContextMenu::createControlPanelItem(QMenu *menu, MenuItem *item)
@@ -392,8 +470,11 @@ void ContextMenu::createControlPanelItem(QMenu *menu, MenuItem *item)
     actionControlPanel = addGeneralAction(
         menu, QIcon(QPixmap(":/icons/control_panel.png")),
         menuName.isEmpty() ? MENU_ECP_ITEM_TEXT : menuName,
-        SLOT(slotControlPanel()),
-        getShortcutKeySeq(menuName));
+        item->getShortcutMap().isEmpty()? NULL :
+            new QShortcut(item->getShortcutMap().begin().value(), parent),
+        SLOT(slotControlPanel()));
+
+    item->setAction(actionControlPanel);
 }
 
 void ContextMenu::createScreenShotItem(QMenu *menu, MenuItem *item)
@@ -406,8 +487,11 @@ void ContextMenu::createScreenShotItem(QMenu *menu, MenuItem *item)
     actionScreenShot = addGeneralAction(
         menu, QIcon(QPixmap(":/icons/screen_shot.png")),
         menuName.isEmpty() ? MENU_SCREENSHOT_ITEM_TEXT : menuName,
-        SLOT(slotRequestScreenshot()),
-        getShortcutKeySeq(menuName));
+        item->getShortcutMap().isEmpty()? NULL :
+            new QShortcut(item->getShortcutMap().begin().value(), parent),
+        SLOT(slotRequestScreenshot()));
+
+    item->setAction(actionScreenShot);
 }
 
 void ContextMenu::createAboutItem(QMenu *menu, MenuItem *item)
@@ -417,9 +501,14 @@ void ContextMenu::createAboutItem(QMenu *menu, MenuItem *item)
     }
 
     QString menuName = item->getName();
-    actionAbout = addGeneralAction(menu, QIcon(QPixmap(":/icons/about.png")),
-        menuName.isEmpty() ? MENU_ABOUT_ITEM_TEXT : menuName, SLOT(slotAbout()),
-        getShortcutKeySeq(menuName));
+    actionAbout = addGeneralAction(
+        menu, QIcon(QPixmap(":/icons/about.png")),
+        menuName.isEmpty() ? MENU_ABOUT_ITEM_TEXT : menuName,
+        item->getShortcutMap().isEmpty()? NULL :
+            new QShortcut(item->getShortcutMap().begin().value(), parent),
+        SLOT(slotAbout()));
+
+    item->setAction(actionAbout);
 }
 
 void ContextMenu::createForceCloseItem(QMenu *menu, MenuItem *item)
@@ -432,8 +521,11 @@ void ContextMenu::createForceCloseItem(QMenu *menu, MenuItem *item)
     actionForceClose = addGeneralAction(
         menu, QIcon(QPixmap(":/icons/force_close.png")),
         menuName.isEmpty() ? MENU_FORCECLOSE_ITEM_TEXT : menuName,
-        SLOT(slotForceClose()),
-        getShortcutKeySeq(menuName));
+        item->getShortcutMap().isEmpty()? NULL :
+            new QShortcut(item->getShortcutMap().begin().value(), parent),
+        SLOT(slotForceClose()));
+
+    item->setAction(actionForceClose);
 }
 
 void ContextMenu::createCloseItem(QMenu *menu, MenuItem *item)
@@ -443,19 +535,28 @@ void ContextMenu::createCloseItem(QMenu *menu, MenuItem *item)
     }
 
     QString menuName = item->getName();
-    actionClose = addGeneralAction(menu, QIcon(QPixmap(":/icons/close.png")),
-        menuName.isEmpty() ? MENU_CLOSE_ITEM_TEXT : menuName, SLOT(slotClose()),
-        getShortcutKeySeq(menuName));
+    actionClose = addGeneralAction(
+        menu, QIcon(QPixmap(":/icons/close.png")),
+        menuName.isEmpty() ? MENU_CLOSE_ITEM_TEXT : menuName,
+        item->getShortcutMap().isEmpty()? NULL :
+            new QShortcut(item->getShortcutMap().begin().value(), parent),
+        SLOT(slotClose()));
+
+    item->setAction(actionClose);
 }
 
 QAction *ContextMenu::addGeneralAction(QMenu *menu,
-    const QIcon &icon, const QString &text, const char *slot, const QString &shortcut)
+    const QIcon &icon, const QString &text, QShortcut *shortcut, const char *slot)
 {
     QAction *action = menu->addAction(text);
     action->setIcon(icon);
-    action->setShortcut(shortcut);
     connect(action, SIGNAL(triggered()), this, slot);
 
+    if (shortcut != NULL) {
+        connect(shortcut, SIGNAL(activated()), this, slot);
+        action->setShortcut(shortcut->key());
+    }
+
     return action;
 }
 
@@ -523,6 +624,14 @@ void ContextMenu::slotTopMost(bool on)
     parent->getUIState()->setOnTop(on);
 }
 
+void ContextMenu::slotTopMostShortcut()
+{
+    /* toggle */
+    slotTopMost(!actionTopMost->isChecked());
+
+    qDebug() << "shortcut:" << actionTopMost->text() << actionTopMost->isChecked();
+}
+
 void ContextMenu::slotSwitch(int index)
 {
     qDebug("switch : %d", index);
@@ -544,6 +653,58 @@ void ContextMenu::slotSwitch(int index)
     keyboardShortcut->setKeyboardShortcutHwKey();
 }
 
+void ContextMenu::slotSwitchShortcutPrev()
+{
+    QList<QAction *> switchActions = switchGroup->actions();
+    if (switchActions.count() < 2) {
+        return;
+    }
+
+    int index = 0;
+
+    QAction *action = switchGroup->checkedAction();
+    if (action != NULL) {
+        index = switchActions.indexOf(action);
+        if (index == 0) {
+            index = switchActions.count() - 1;
+        } else {
+            index--;
+        }
+    }
+
+    QAction *prevAction = switchActions.at(index);
+    prevAction->setChecked(true);
+    prevAction->trigger();
+
+    qDebug() << "shortcut: prev" << switchMenu->title() << prevAction->text();
+}
+
+void ContextMenu::slotSwitchShortcutNext()
+{
+    QList<QAction *> switchActions = switchGroup->actions();
+    if (switchActions.count() < 2) {
+        return;
+    }
+
+    int index = 0;
+
+    QAction *action = switchGroup->checkedAction();
+    if (action != NULL) {
+        index = switchActions.indexOf(action);
+        if (index == switchActions.count() - 1) {
+            index = 0;
+        } else {
+            index++;
+        }
+    }
+
+    QAction *nextAction = switchActions.at(index);
+    nextAction->setChecked(true);
+    nextAction->trigger();
+
+    qDebug() << "shortcut: next" << switchMenu->title() << nextAction->text();
+}
+
 void ContextMenu::slotScale(int scale)
 {
     qDebug("scale : %d", scale);
@@ -560,6 +721,58 @@ void ContextMenu::slotScale(int scale)
     }
 }
 
+void ContextMenu::slotScaleShortcutPrev()
+{
+    QList<QAction *> scaleActions = scaleGroup->actions();
+    if (scaleActions.count() < 2) {
+        return;
+    }
+
+    int index = 0;
+
+    QAction *action = scaleGroup->checkedAction();
+    if (action != NULL) {
+        index = scaleActions.indexOf(action);
+        if (index == 0) {
+            index = scaleActions.count() - 1;
+        } else {
+            index--;
+        }
+    }
+
+    QAction *prevAction = scaleActions.at(index);
+    prevAction->setChecked(true);
+    prevAction->trigger();
+
+    qDebug() << "shortcut: prev" << scaleMenu->title() << prevAction->text();
+}
+
+void ContextMenu::slotScaleShortcutNext()
+{
+    QList<QAction *> scaleActions = scaleGroup->actions();
+    if (scaleActions.count() < 2) {
+        return;
+    }
+
+    int index = 0;
+
+    QAction *action = scaleGroup->checkedAction();
+    if (action != NULL) {
+        index = scaleActions.indexOf(action);
+        if (index == scaleActions.count() - 1) {
+            index = 0;
+        } else {
+            index++;
+        }
+    }
+
+    QAction *nextAction = scaleActions.at(index);
+    nextAction->setChecked(true);
+    nextAction->trigger();
+
+    qDebug() << "shortcut: next" << scaleMenu->title() << nextAction->text();
+}
+
 void ContextMenu::slotController(int index)
 {
     qDebug("controller : %d", index);
@@ -576,6 +789,58 @@ void ContextMenu::slotCloseCon()
     parent->getUIState()->conState.conFormIndex = -1;
 }
 
+void ContextMenu::slotConShortcutPrev()
+{
+    QList<QAction *> conActions = controllerGroup->actions();
+    if (conActions.count() < 2) {
+        return;
+    }
+
+    int index = 0;
+
+    QAction *action = controllerGroup->checkedAction();
+    if (action != NULL) {
+        index = conActions.indexOf(action);
+        if (index == 0) {
+            index = conActions.count() - 1;
+        } else {
+            index--;
+        }
+    }
+
+    QAction *prevAction = conActions.at(index);
+    prevAction->setChecked(true);
+    prevAction->trigger();
+
+    qDebug() << "shortcut: prev" << controllerMenu->title() << prevAction->text();
+}
+
+void ContextMenu::slotConShortcutNext()
+{
+    QList<QAction *> conActions = controllerGroup->actions();
+    if (conActions.count() < 2) {
+        return;
+    }
+
+    int index = 0;
+
+    QAction *action = controllerGroup->checkedAction();
+    if (action != NULL) {
+        index = conActions.indexOf(action);
+        if (index == conActions.count() - 1) {
+            index = 0;
+        } else {
+            index++;
+        }
+    }
+
+    QAction *nextAction = conActions.at(index);
+    nextAction->setChecked(true);
+    nextAction->trigger();
+
+    qDebug() << "shortcut: next" << controllerMenu->title() << nextAction->text();
+}
+
 void ContextMenu::slotShell()
 {
     qDebug("SDB shell");
@@ -789,11 +1054,6 @@ QSignalMapper *ContextMenu::getControllerMapper()
     return controllerMapper;
 }
 
-QAction *ContextMenu::getActionTopMost()
-{
-    return actionTopMost;
-}
-
 QMessageBox *ContextMenu::showMsgBox(
     QMessageBox::Icon iconType, const QString &text,
     QMessageBox::StandardButtons buttons,
index 57fa534b2ff5999a9d6fecff56f24d6ee45e16b1..1d9d3dfa74bd0db427766d3efd1afd5042befa20 100644 (file)
@@ -62,12 +62,11 @@ public:
     QSignalMapper *getScaleMapper();
     QSignalMapper *getControllerMapper();
 
+    QActionGroup *switchGroup;
     QActionGroup *scaleGroup;
     QActionGroup *keyboardGroup;
     QActionGroup *controllerGroup;
-    QActionGroup *switchGroup;
 
-    QAction *getActionTopMost();
     ScreenShotDialog *screenshotDialog;
 
 signals:
@@ -75,16 +74,28 @@ signals:
 public slots:
     void slotDetailedInfo();
     void slotTopMost(bool on);
+    void slotTopMostShortcut();
+
     void slotSwitch(int index);
+    void slotSwitchShortcutPrev();
+    void slotSwitchShortcutNext();
+
     void slotScale(int scale);
+    void slotScaleShortcutPrev();
+    void slotScaleShortcutNext();
+
     void slotController(int index);
     void slotCloseCon();
+    void slotConShortcutPrev();
+    void slotConShortcutNext();
+
     void slotShell();
     void slotControlPanel();
     void slotRequestScreenshot();
     void slotShowScreenshot(const QPixmap &);
     void slotHostKeyboard(bool on);
     void slotAbout();
+
     void slotForceClose();
     void slotForceCloseSelected(QAbstractButton *);
     void slotClose();
@@ -108,12 +119,10 @@ protected:
     void createForceCloseItem(QMenu *menu, MenuItem *item);
     void createCloseItem(QMenu *menu, MenuItem *item);
     bool eventFilter(QObject *obj, QEvent *event);
-    QString getShortcutKeySeq(QString key);
 
 private:
-    QAction *addGeneralAction(QMenu *menu,
-        const QIcon &icon, const QString &text, const char *slot,
-        const QString &shortcut);
+    QAction *addGeneralAction(QMenu *menu, const QIcon &icon,
+        const QString &text, QShortcut *shortcut, const char *slot);
     QMessageBox *showMsgBox(QMessageBox::Icon iconType, const QString &text,
         QMessageBox::StandardButtons buttons = QMessageBox::NoButton,
         QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
index c54b4c0388f89c5df4124259e1b319bec43fb5e2..0f4f9c055f43c143fad8307e4cbdc67cc4934dae 100644 (file)
@@ -30,6 +30,7 @@
 #include "detailedinfodialog.h"
 #include "resource/ui_strings.h"
 #include "mainwindow.h"
+#include "menu/advancedmenuitem.h"
 
 extern "C" {
 int get_display_pixel_density(void);
@@ -187,9 +188,9 @@ void DetailedInfoDialog::updateShortcutTableItems()
     qDebug() << "clear" << shortcutInfoTable->rowCount() << "shortcut items";
     removeTableRows(shortcutInfoTable, 0, shortcutInfoTable->rowCount());
 
-    /* insert shortcut info */
-    setShortcutInfoTable(keyboardShortcut->getPopupMenuShortcutMap(),
-                         keyboardShortcut->getPopupMenuShortcutList());
+    /* insert menu shortcut info */
+    insertMenuShortcutInfo(win->uiInfo->menuList);
+
     setShortcutInfoTable(keyboardShortcut->getHwKeyShortcutMap(),
                          keyboardShortcut->getHwKeyShortcutList());
     setShortcutInfoTable(keyboardShortcut->getControllerShortcutMap(),
@@ -198,6 +199,38 @@ void DetailedInfoDialog::updateShortcutTableItems()
     qDebug() << shortcutInfoTable->rowCount() << "shortcut items have been inserted";
 }
 
+void DetailedInfoDialog::insertMenuShortcutInfo(QList<MenuItem *> list)
+{
+    for (int i = 0; i < list.count(); i++) {
+        MenuItem *item = list.at(i);
+        if (item != NULL) {
+            if (item->getType() == MenuItemType::separator) {
+                /* do nothing */
+            } else if (item->getType() == MenuItemType::advancedItem) {
+                /* insert advanced menu shortcut info */
+                AdvancedMenuItem *advItem = (AdvancedMenuItem *)item;
+                insertMenuShortcutInfo(advItem->getMenuList());
+            } else if (item->getAction() != NULL &&
+                item->getShortcutMap().isEmpty() == false) {
+
+                QMap<QString, QKeySequence>::iterator iter = item->getShortcutMap().begin();
+                for ( ; iter != item->getShortcutMap().end(); iter++) {
+                    QString function = item->getAction()->iconText().isEmpty() ?
+                        item->getAction()->text() : item->getAction()->iconText();
+                    function += " " + iter.key();
+
+                    QString keySequence = iter.value().toString();
+#ifdef CONFIG_DARWIN
+                    keySequence.replace("Ctrl", "Cmd");
+#endif
+
+                    insertTableRow(shortcutInfoTable, function, keySequence);
+                }
+            }
+        }
+    }
+}
+
 void DetailedInfoDialog::setShortcutInfoTable(
     const QMap<QString, QString>& map, const QList<QShortcut *>& list)
 {
@@ -265,7 +298,7 @@ void DetailedInfoDialog::resizeTableToContents(QTableWidget *table)
     vmInfoTable->resizeColumnsToContents();
 }
 
-void DetailedInfoDialog::insertTableRow(QTableWidgettable,
+void DetailedInfoDialog::insertTableRow(QTableWidget *table,
     const QString& key, const QString& value, const QString& tooltip)
 {
     int row = table->rowCount();
@@ -278,7 +311,7 @@ void DetailedInfoDialog::insertTableRow(QTableWidget* table,
     }
 }
 
-void DetailedInfoDialog::insertTableRow(QTableWidgettable,
+void DetailedInfoDialog::insertTableRow(QTableWidget *table,
     const QString& key, const QString& value)
 {
     insertTableRow(table, QString(key), QString(value), QString());
index a7e64f32cfe6e5184ba8d8ce1663752b5670cf88..0191752e919bd280f3c91c7a4c88d5af4488deda 100644 (file)
@@ -33,6 +33,7 @@
 #include <QtWidgets>
 #include <QDialog>
 
+#include "menu/menuitem.h"
 #include "input/keyboardshortcut.h"
 
 class DetailedInfoDialog : public QDialog
@@ -44,11 +45,13 @@ public:
     ~DetailedInfoDialog();
 
     void updateShortcutTableItems();
+    void insertMenuShortcutInfo(QList<MenuItem *> list);
+
     void setShortcutInfoTable(const QMap<QString, QString>& map,
             const QList<QShortcut *>& list);
-    void insertTableRow(QTableWidgettable, const QString& key,
+    void insertTableRow(QTableWidget *table, const QString& key,
             const QString& value, const QString& tooltip);
-    void insertTableRow(QTableWidgettable, const QString& key,
+    void insertTableRow(QTableWidget *table, const QString& key,
             const QString& value);
     void removeTableRows(QTableWidget *table, int startIndex, int lastIndex);
 
index b8090fa46320d6a445c227d2f67d68b6d622a766..097d9de327bcac6f5945ecb030f3079dacef7a06 100644 (file)
@@ -33,6 +33,7 @@ MenuItem::MenuItem(int type, QString name)
 {
     this->type = type;
     this->name = name;
+    this->action = NULL;
 }
 
 int MenuItem::getType()
@@ -45,11 +46,21 @@ QString MenuItem::getName()
     return name;
 }
 
-QMap<QString, QString> &MenuItem::getShortcutMap()
+QMap<QString, QKeySequence> &MenuItem::getShortcutMap()
 {
     return shortcutMap;
 }
 
+void MenuItem::setAction(QAction *action)
+{
+    this->action = action;
+}
+
+QAction *MenuItem::getAction()
+{
+    return action;
+}
+
 MenuItem::~MenuItem()
 {
     /* do nothing */
index f4629b70f79fa41a5dc24287b6934ec8b96c6dec..f5dcea1c4e4f41975f510426c03f96c6ab520bc7 100644 (file)
@@ -31,6 +31,7 @@
 #define MENUITEM_H
 
 #include <QString>
+#include <QShortcut>
 #include <QMap>
 
 namespace MenuItemType
@@ -61,12 +62,15 @@ public:
 
     int getType();
     QString getName();
-    QMap<QString, QString> &getShortcutMap();
+    QMap<QString, QKeySequence> &getShortcutMap();
+    void setAction(QAction *action);
+    QAction *getAction();
 
 private:
     int type;
     QString name;
-    QMap<QString, QString> shortcutMap;
+    QMap<QString, QKeySequence> shortcutMap;
+    QAction *action;
 };
 
 #endif // MENUITEM_H
index 82ed1dfb9b287af4511058498c0314ac27fceadc..c884cbcb66cc2847885c71b96990b9a671997c64 100644 (file)
@@ -357,10 +357,10 @@ int XmlLayoutParser::parseFactorList(
 }
 
 int XmlLayoutParser::parseShortcut(
-    QXmlStreamReader &xml, QMap<QString, QString> &map)
+    QXmlStreamReader &xml, QMap<QString, QKeySequence> &map)
 {
     QString key = xml.attributes().value(PROP_ATTR_KEYWORD).toString();
-    map.insert(key, xml.readElementText());
+    map.insert(key, QKeySequence::fromString(xml.readElementText()));
 
     return map.count();
 }
index 6e01a0231f792cec65a293440d8227c588bacd48..bf7cd1cbefa62beea3f11397400b0c93c66247a4 100644 (file)
@@ -61,7 +61,7 @@ private:
     int parseMainFormList(QXmlStreamReader &xml, QList<MainForm *> &list);
 
     int parseFactorList(QXmlStreamReader &xml, QMap<int, QString> &map, int *defaultFactor);
-    int parseShortcut(QXmlStreamReader &xml, QMap<QString, QString> &map);
+    int parseShortcut(QXmlStreamReader &xml, QMap<QString, QKeySequence> &map);
     AdvancedMenuItem *parseAdvancedMenuItem(QXmlStreamReader &xml);
     ScaleMenuItem *parseScaleMenuItem(QXmlStreamReader &xml);
     MenuItem *parseGeneralMenuItem(QXmlStreamReader &xml, int menuType);