From 57d0f9a0b8bebb7cbe24c8c44b325705440bf2a4 Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Mon, 17 Aug 2015 18:39:17 +0900 Subject: [PATCH] shortcut: refactoring for context menu shortcut - 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 --- tizen/src/ui/input/keyboardshortcut.cpp | 243 ------------------ tizen/src/ui/input/keyboardshortcut.h | 19 -- tizen/src/ui/menu/contextmenu.cpp | 422 +++++++++++++++++++++++++------ tizen/src/ui/menu/contextmenu.h | 21 +- tizen/src/ui/menu/detailedinfodialog.cpp | 43 +++- tizen/src/ui/menu/detailedinfodialog.h | 7 +- tizen/src/ui/menu/menuitem.cpp | 13 +- tizen/src/ui/menu/menuitem.h | 8 +- tizen/src/ui/xmllayoutparser.cpp | 4 +- tizen/src/ui/xmllayoutparser.h | 2 +- 10 files changed, 420 insertions(+), 362 deletions(-) diff --git a/tizen/src/ui/input/keyboardshortcut.cpp b/tizen/src/ui/input/keyboardshortcut.cpp index e23a3fa..c3baebe 100644 --- a/tizen/src/ui/input/keyboardshortcut.cpp +++ b/tizen/src/ui/input/keyboardshortcut.cpp @@ -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 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 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 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 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 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 KeyboardShortcut::getControllerShortcutList() return controllerShortcutList; } -QList KeyboardShortcut::getPopupMenuShortcutList() -{ - return popupMenuShortcutList; -} - QList KeyboardShortcut::getHwKeyShortcutList() { return hwKeyShortcutList; } -QMap KeyboardShortcut::getPopupMenuShortcutMap() -{ - return popupMenuShortcutMap; -} - QMap KeyboardShortcut::getHwKeyShortcutMap() { return hwKeyShortcutMap; @@ -488,7 +246,6 @@ KeyboardShortcut::~KeyboardShortcut() { removeHwKeyShortcut(); removeControllerShortcut(); - removePopupMenuShortcut(); qDebug("destroy keyboard shortcut"); } diff --git a/tizen/src/ui/input/keyboardshortcut.h b/tizen/src/ui/input/keyboardshortcut.h index c91d9c1..3954487 100644 --- a/tizen/src/ui/input/keyboardshortcut.h +++ b/tizen/src/ui/input/keyboardshortcut.h @@ -36,7 +36,6 @@ #include #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 getControllerShortcutList(); - QList getPopupMenuShortcutList(); QList getHwKeyShortcutList(); - QMap getPopupMenuShortcutMap(); QMap getHwKeyShortcutMap(); QMap 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 hwKeyList; QList controllerKeyList; - QList popupMenuShortcutList; QList controllerShortcutList; QList hwKeyShortcutList; - QMap popupMenuShortcutMap; QMap hwKeyShortcutMap; QMap controllerShortcutMap; }; diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 791ac60..f21d0b3 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -83,20 +83,9 @@ ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent) void ContextMenu::createItems(QMenu *menu, QList &list) { MenuItem *item = NULL; - KeyboardShortcut *keyboardShortcut = parent->getKeyboardShortcut(); - for (int i = 0; i < list.count(); i++) { item = list.at(i); - QMap shortcutMap = item->getShortcutMap(); - if (!shortcutMap.isEmpty()) { - QMap::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 shortcutMap = keyboardShortcut->getPopupMenuShortcutMap(); - QMap::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 shortcutMap = item->getShortcutMap(); + + if (shortcutMap.isEmpty() == false) { + QMap::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 shortcutMap = item->getShortcutMap(); + + if (shortcutMap.isEmpty() == false) { + QMap::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 iter(factorMap); - iter.toBack(); - while(iter.hasPrevious() == true) { - iter.previous(); + QMapIterator 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 shortcutMap = item->getShortcutMap(); + + if (shortcutMap.isEmpty() == false) { + QMap::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 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 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 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 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 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 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, diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h index 57fa534..1d9d3df 100644 --- a/tizen/src/ui/menu/contextmenu.h +++ b/tizen/src/ui/menu/contextmenu.h @@ -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); diff --git a/tizen/src/ui/menu/detailedinfodialog.cpp b/tizen/src/ui/menu/detailedinfodialog.cpp index c54b4c0..0f4f9c0 100644 --- a/tizen/src/ui/menu/detailedinfodialog.cpp +++ b/tizen/src/ui/menu/detailedinfodialog.cpp @@ -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 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::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& map, const QList& list) { @@ -265,7 +298,7 @@ void DetailedInfoDialog::resizeTableToContents(QTableWidget *table) vmInfoTable->resizeColumnsToContents(); } -void DetailedInfoDialog::insertTableRow(QTableWidget* table, +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(QTableWidget* table, +void DetailedInfoDialog::insertTableRow(QTableWidget *table, const QString& key, const QString& value) { insertTableRow(table, QString(key), QString(value), QString()); diff --git a/tizen/src/ui/menu/detailedinfodialog.h b/tizen/src/ui/menu/detailedinfodialog.h index a7e64f3..0191752 100644 --- a/tizen/src/ui/menu/detailedinfodialog.h +++ b/tizen/src/ui/menu/detailedinfodialog.h @@ -33,6 +33,7 @@ #include #include +#include "menu/menuitem.h" #include "input/keyboardshortcut.h" class DetailedInfoDialog : public QDialog @@ -44,11 +45,13 @@ public: ~DetailedInfoDialog(); void updateShortcutTableItems(); + void insertMenuShortcutInfo(QList list); + void setShortcutInfoTable(const QMap& map, const QList& list); - void insertTableRow(QTableWidget* table, const QString& key, + void insertTableRow(QTableWidget *table, const QString& key, const QString& value, const QString& tooltip); - void insertTableRow(QTableWidget* table, const QString& key, + void insertTableRow(QTableWidget *table, const QString& key, const QString& value); void removeTableRows(QTableWidget *table, int startIndex, int lastIndex); diff --git a/tizen/src/ui/menu/menuitem.cpp b/tizen/src/ui/menu/menuitem.cpp index b8090fa..097d9de 100644 --- a/tizen/src/ui/menu/menuitem.cpp +++ b/tizen/src/ui/menu/menuitem.cpp @@ -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 &MenuItem::getShortcutMap() +QMap &MenuItem::getShortcutMap() { return shortcutMap; } +void MenuItem::setAction(QAction *action) +{ + this->action = action; +} + +QAction *MenuItem::getAction() +{ + return action; +} + MenuItem::~MenuItem() { /* do nothing */ diff --git a/tizen/src/ui/menu/menuitem.h b/tizen/src/ui/menu/menuitem.h index f4629b7..f5dcea1 100644 --- a/tizen/src/ui/menu/menuitem.h +++ b/tizen/src/ui/menu/menuitem.h @@ -31,6 +31,7 @@ #define MENUITEM_H #include +#include #include namespace MenuItemType @@ -61,12 +62,15 @@ public: int getType(); QString getName(); - QMap &getShortcutMap(); + QMap &getShortcutMap(); + void setAction(QAction *action); + QAction *getAction(); private: int type; QString name; - QMap shortcutMap; + QMap shortcutMap; + QAction *action; }; #endif // MENUITEM_H diff --git a/tizen/src/ui/xmllayoutparser.cpp b/tizen/src/ui/xmllayoutparser.cpp index 82ed1df..c884cbc 100644 --- a/tizen/src/ui/xmllayoutparser.cpp +++ b/tizen/src/ui/xmllayoutparser.cpp @@ -357,10 +357,10 @@ int XmlLayoutParser::parseFactorList( } int XmlLayoutParser::parseShortcut( - QXmlStreamReader &xml, QMap &map) + QXmlStreamReader &xml, QMap &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(); } diff --git a/tizen/src/ui/xmllayoutparser.h b/tizen/src/ui/xmllayoutparser.h index 6e01a02..bf7cd1c 100644 --- a/tizen/src/ui/xmllayoutparser.h +++ b/tizen/src/ui/xmllayoutparser.h @@ -61,7 +61,7 @@ private: int parseMainFormList(QXmlStreamReader &xml, QList &list); int parseFactorList(QXmlStreamReader &xml, QMap &map, int *defaultFactor); - int parseShortcut(QXmlStreamReader &xml, QMap &map); + int parseShortcut(QXmlStreamReader &xml, QMap &map); AdvancedMenuItem *parseAdvancedMenuItem(QXmlStreamReader &xml); ScaleMenuItem *parseScaleMenuItem(QXmlStreamReader &xml); MenuItem *parseGeneralMenuItem(QXmlStreamReader &xml, int menuType); -- 2.7.4