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)
committerGiWoong Kim <giwoong.kim@samsung.com>
Wed, 16 Dec 2015 01:40:11 +0000 (10:40 +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>
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 bceb6414cc9906010c21d3dae8b8159824be80fc..224b9fba1a813491bc96eceb0458ffaf151cef55 100644 (file)
@@ -28,6 +28,8 @@
  *
  */
 
+#include "config-host.h"
+
 #include "xmllayoutparser.h"
 #include "xmllayoutkeyword.h"
 #include "skinpainter.h"
@@ -242,7 +244,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();
             }
@@ -421,11 +423,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 e6bcf80b9407613e18fa29d3cec0fd408821469a..6ad579ae49a917efdce9df407486be47ea598bd2 100644 (file)
@@ -66,6 +66,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);