shortcut: make default shortcut keys with "Control key" on MacOS
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 15 Dec 2015 11:01:07 +0000 (20:01 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 18 Dec 2015 07:08:28 +0000 (16:08 +0900)
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 <giwoong.kim@samsung.com>
(cherry picked from commit 957b11ee3720a0161ad5e79abe2382f154be78ac)

tizen/src/ui/menu/detailedinfodialog.cpp
tizen/src/ui/resource/ui_strings.h
tizen/src/ui/xmllayoutparser.cpp
tizen/src/ui/xmllayoutparser.h

index 41d57bb810623fddcea6d8ae8e4b280e7d9cae01..19ec13de0fa518ac3197032ed2f48787bd792a10 100644 (file)
@@ -277,7 +277,7 @@ void DetailedInfoDialog::insertMenuShortcutInfo(QList<MenuItem *> &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);
         }
     }
 }
index fde5c69fce605f25f8f7aaed96bac88ce343a369..691bd13e6c388c27935153811b186d2dd9bac24a 100644 (file)
 #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"
index 5e87848108dc481f02aa6ef88ca724971c0dc5c0..baaa313db467afab68f4927a6b5996624cb740e4 100644 (file)
@@ -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<QString, QKeySequence> &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();
 }
index 16213e0a6437990883bee7268af582ba611591b7..67eef2726b38ea03f650e0ebda064d33d9c53be4 100644 (file)
@@ -65,6 +65,7 @@ private:
 
     int parseFactorList(QXmlStreamReader &xml,
         const int depth, QMap<int, QString> &map, int *defaultFactor);
+    QKeySequence parseShortcut(QXmlStreamReader &xml, const int depth);
     int parseShortcuts(QXmlStreamReader &xml,
         const int depth, QMap<QString, QKeySequence> &map);
     AdvancedMenuItem *parseAdvancedMenuItem(QXmlStreamReader &xml, const int depth);