From 0b46b42d5279505a7ed888def0f371e41ddc01fe Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Tue, 15 Dec 2015 20:01:07 +0900 Subject: [PATCH] shortcut: make default shortcut keys with "Control key" on MacOS QKeySequence Note - On Mac OS X, references to "Ctrl", Qt::CTRL, Qt::Control and Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard, and references to "Meta", Qt::META, Qt::Meta and Qt::MetaModifier correspond to the Control keys. Developers on Mac OS X can use the same shortcut descriptions across all platforms, and their applications will automatically work as expected on Mac OS X. According to Qt note, "Ctrl" will be treated as command key. This is not what we want. To be recognized as control key on MacOS, XML Parser should replace "Ctrl" with "Meta" text. Change-Id: Id26972ba7236df1b33d7d2409fcf58115ebf163c Signed-off-by: GiWoong Kim (cherry picked from commit 957b11ee3720a0161ad5e79abe2382f154be78ac) --- tizen/src/ui/menu/detailedinfodialog.cpp | 11 +++++++--- tizen/src/ui/resource/ui_strings.h | 4 ++++ tizen/src/ui/xmllayoutparser.cpp | 28 ++++++++++++++++++++++-- tizen/src/ui/xmllayoutparser.h | 1 + 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/tizen/src/ui/menu/detailedinfodialog.cpp b/tizen/src/ui/menu/detailedinfodialog.cpp index 41d57bb810..19ec13de0f 100644 --- a/tizen/src/ui/menu/detailedinfodialog.cpp +++ b/tizen/src/ui/menu/detailedinfodialog.cpp @@ -277,7 +277,7 @@ void DetailedInfoDialog::insertMenuShortcutInfo(QList &list) QString keySequence = iter.value().toString(); #ifdef CONFIG_DARWIN - keySequence.replace("Ctrl", "Cmd"); + keySequence.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING); #endif insertTableRow(menuShortcutTable, function, keySequence); @@ -296,8 +296,13 @@ void DetailedInfoDialog::insertHwKeyShortcutInfo( hwKey = list.at(i); if (hwKey && hwKey->getKeySequence().isEmpty() == false && hwKey->getName().isEmpty() == false) { - insertTableRow(keyShortcutTable, - hwKey->getName() + source, hwKey->getKeySequence().toString()); + + QString keySequence = hwKey->getKeySequence().toString(); +#ifdef CONFIG_DARWIN + keySequence.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING); +#endif + + insertTableRow(keyShortcutTable, hwKey->getName() + source, keySequence); } } } diff --git a/tizen/src/ui/resource/ui_strings.h b/tizen/src/ui/resource/ui_strings.h index fde5c69fce..691bd13e6c 100644 --- a/tizen/src/ui/resource/ui_strings.h +++ b/tizen/src/ui/resource/ui_strings.h @@ -131,6 +131,10 @@ #define STYLE_TOOLTIP "QToolTip {"\ "color: black; background-color: white; border: 1px solid black; }" +/* ETC */ +#define XML_QT_CTRLKEY_STRING "Ctrl" +#define XML_QT_METAKEY_STRING "Meta" + /* messages */ #define MSG_SDB_NOT_READY "SDB is not ready.\nPlease wait until the emulator is completely boot up." #define MSG_SDB_NOT_EXIST "SDB file does not exist in the following path.\n" diff --git a/tizen/src/ui/xmllayoutparser.cpp b/tizen/src/ui/xmllayoutparser.cpp index 5e87848108..baaa313db4 100644 --- a/tizen/src/ui/xmllayoutparser.cpp +++ b/tizen/src/ui/xmllayoutparser.cpp @@ -28,6 +28,8 @@ * */ +#include "config-host.h" + #include "xmllayoutparser.h" #include "xmllayoutkeyword.h" #include "skinpainter.h" @@ -225,7 +227,7 @@ HardwareKey *XmlLayoutParser::parseKey(QXmlStreamReader &xml, const int depth) keyTooptip = xml.readElementText(); } else if (xml.name() == SHORTCUT_KEYWORD) { /* shortcut */ - keySequence = QKeySequence::fromString(xml.readElementText()); + keySequence = parseShortcut(xml, depth + 1); } else { QWARN_INDENT(depth + 1) << "undefined element: " << xml.name(); } @@ -404,11 +406,33 @@ int XmlLayoutParser::parseFactorList(QXmlStreamReader &xml, return map.count(); } +QKeySequence XmlLayoutParser::parseShortcut(QXmlStreamReader &xml, const int depth) +{ + QString keyString = xml.readElementText(); + +#ifdef CONFIG_DARWIN + /* QKeySequence Note: On Mac OS X, references to "Ctrl", Qt::CTRL, Qt::Control and + * Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard, + * and references to "Meta", Qt::META, Qt::Meta and Qt::MetaModifier correspond to + * the Control keys. Developers on Mac OS X can use the same shortcut descriptions + * across all platforms, and their applications will automatically work as expected + * on Mac OS X. */ + + /* According to Qt note, "Ctrl" will be treated as command key. This is not what we + * want. To be recognized as control key on MacOS, XML Parser should replace "Ctrl" + * with "Meta" text. */ + + keyString.replace(XML_QT_CTRLKEY_STRING, XML_QT_METAKEY_STRING); +#endif + + return QKeySequence::fromString(keyString); +} + int XmlLayoutParser::parseShortcuts(QXmlStreamReader &xml, const int depth, QMap &map) { QString key = xml.attributes().value(PROP_ATTR_KEYWORD).toString(); - map.insert(key, QKeySequence::fromString(xml.readElementText())); + map.insert(key, parseShortcut(xml, depth + 1)); return map.count(); } diff --git a/tizen/src/ui/xmllayoutparser.h b/tizen/src/ui/xmllayoutparser.h index 16213e0a64..67eef2726b 100644 --- a/tizen/src/ui/xmllayoutparser.h +++ b/tizen/src/ui/xmllayoutparser.h @@ -65,6 +65,7 @@ private: int parseFactorList(QXmlStreamReader &xml, const int depth, QMap &map, int *defaultFactor); + QKeySequence parseShortcut(QXmlStreamReader &xml, const int depth); int parseShortcuts(QXmlStreamReader &xml, const int depth, QMap &map); AdvancedMenuItem *parseAdvancedMenuItem(QXmlStreamReader &xml, const int depth); -- 2.34.1