hwkey: define additional attribute schema of XML for HW key long pressing
authorGiWoong Kim <giwoong.kim@samsung.com>
Fri, 31 Jul 2015 07:19:21 +0000 (16:19 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 31 Jul 2015 12:29:46 +0000 (21:29 +0900)
<key>
    ...
    <keycode longPress="22"> 11 </keycode>
    ...
</key>

Change-Id: I21a3aa86fa30d96809e3b15f61801e09a54686b1
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
12 files changed:
tizen/src/display/xmllayoutkeyword.h
tizen/src/display/xmllayoutparser.cpp
tizen/src/display/xmllayoutparser.h
tizen/src/ui/controller/hwkeybutton.cpp
tizen/src/ui/input/keyboardshortcut.cpp
tizen/src/ui/layout/Makefile.objs
tizen/src/ui/layout/hardwarekey.cpp
tizen/src/ui/layout/hardwarekey.h
tizen/src/ui/layout/keycodetype.cpp [new file with mode: 0644]
tizen/src/ui/layout/keycodetype.h [new file with mode: 0644]
tizen/src/ui/skinkeyitem.cpp
tizen/src/ui/skinkeyitem.h

index 4392ad81cca01658384f1b231ce1d280d9b2a6cd..dd84f762c6b0c69d9237dfb39e360f3e5e4e4630 100644 (file)
@@ -40,6 +40,7 @@
 #define REGION_TOP_ATTR_KEYWORD "top"
 #define REGION_WIDTH_ATTR_KEYWORD "width"
 #define REGION_HEIGHT_ATTR_KEYWORD "height"
+#define KEYCODE_LONGPRESS_ATTR_KEYWORD "longPress"
 
 #define EMULATOR_UI_KEYWORD "EmulatorUI"
 #define CONTROLLER_UI_KEYWORD "ControllerUI"
index 0ce779efea961ad28b66c6850a2bf745a0dd1612..82ed1dfb9b287af4511058498c0314ac27fceadc 100644 (file)
@@ -30,6 +30,7 @@
 #include "xmllayoutparser.h"
 #include "xmllayoutkeyword.h"
 #include "skinpainter.h"
+#include "layout/keycodetype.h"
 #include "controller/generalpurposecon.h"
 
 /* Qt Qlayout has a minimum size */
@@ -158,10 +159,22 @@ DisplayType *XmlLayoutParser::parseDisplay(QXmlStreamReader &xml)
     return new DisplayType(displayRect, angle, maskImage);
 }
 
+KeycodeType *XmlLayoutParser::parseKeycode(QXmlStreamReader &xml)
+{
+    int longPress = -1, shortPress = 0;
+
+    /* attribute */
+    longPress = xml.attributes().value(KEYCODE_LONGPRESS_ATTR_KEYWORD).toString().toInt();
+
+    shortPress = xml.readElementText().toInt();
+
+    return new KeycodeType(shortPress, longPress);
+}
+
 HardwareKey *XmlLayoutParser::parseKey(QXmlStreamReader &xml)
 {
     QRect keyRegion;
-    int keycode = 0;
+    KeycodeType *keycodeType = NULL;
     QString keyTooptip;
     QString keySequence;
 
@@ -179,7 +192,7 @@ HardwareKey *XmlLayoutParser::parseKey(QXmlStreamReader &xml)
                 keyRegion = parseRegion(xml);
             } else if (xml.name() == KEYCODE_KEYWORD) {
                 /* keycode */
-                keycode = xml.readElementText().toInt();
+                keycodeType = parseKeycode(xml);
             } else if (xml.name() == TOOLTIP_KEYWORD) {
                 /* tooltip */
                 keyTooptip = xml.readElementText();
@@ -192,7 +205,7 @@ HardwareKey *XmlLayoutParser::parseKey(QXmlStreamReader &xml)
         token = xml.readNext();
     }
 
-    return new HardwareKey(keyName, keycode, keyRegion, keyTooptip, keySequence);
+    return new HardwareKey(keyName, keycodeType, keyRegion, keyTooptip, keySequence);
 }
 
 int XmlLayoutParser::parseKeyList(
index 3155da9d30692baf77504963f2bfabc6da3f696a..6e01a0231f792cec65a293440d8227c588bacd48 100644 (file)
 #include <QXmlStreamReader>
 
 #include "uiinformation.h"
+#include "layout/keycodetype.h"
 #include "layout/mainform.h"
+#include "layout/controllerform.h"
 #include "menu/menuitem.h"
 #include "menu/advancedmenuitem.h"
 #include "menu/scalemenuitem.h"
-#include "layout/controllerform.h"
+
 
 class XmlLayoutParser
 {
@@ -52,6 +54,7 @@ private:
     HoverType *parseHover(QXmlStreamReader &xml);
     QRect parseRegion(QXmlStreamReader &xml);
     DisplayType *parseDisplay(QXmlStreamReader &xml);
+    KeycodeType *parseKeycode(QXmlStreamReader &xml);
     HardwareKey *parseKey(QXmlStreamReader &xml);
     int parseKeyList(QXmlStreamReader &xml, QList<HardwareKey *> &list);
     MainForm *parseMainForm(QXmlStreamReader &xml);
index ee5eecf6274980001f6a67160cd98dda3d392e36..d443b54d9a8730fa8da8bde15d2b91627a3b3785 100644 (file)
@@ -27,6 +27,8 @@
  *
  */
 
+#include <QDebug>
+
 #include "hwkeybutton.h"
 
 extern "C" {
@@ -58,18 +60,20 @@ HWKeyButton::HWKeyButton(QWidget *parent, HardwareKey *hwKey, QSize size) :
 
 void HWKeyButton::mousePressEvent(QMouseEvent *event)
 {
-    qDebug("HW key button pressed : %s", qPrintable(hwKey->name));
+    const int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
 
-    do_hw_key_event(KEY_PRESSED, hwKey->keycode);
+    qDebug() << hwKey->name << "key button pressed:" << keycode;
+    do_hw_key_event(KEY_PRESSED, keycode);
 
     QPushButton::mousePressEvent(event);
 }
 
 void HWKeyButton::mouseReleaseEvent(QMouseEvent *event)
 {
-    qDebug("HW key button released : %s", qPrintable(hwKey->name));
+    const int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
 
-    do_hw_key_event(KEY_RELEASED, hwKey->keycode);
+    qDebug() << hwKey->name << "key button released:" << keycode;
+    do_hw_key_event(KEY_RELEASED, keycode);
 
     QPushButton::mouseReleaseEvent(event);
 }
index 872a84266aae68b070c40dfe361b339807ad6b52..9b71be3d72fcaa46b28dfb4cf04fac0f335ff1c8 100644 (file)
@@ -411,7 +411,8 @@ int KeyboardShortcut::getHwKeyCode(QString item)
 
     for (index = 0; index < hwKeyList.count(); index++) {
         if (hwKeyList.at(index)->name.compare(item) == 0) {
-            keyCode = hwKeyList.at(index)->keycode;
+            keyCode = hwKeyList.at(index)->
+                getKeycodeType()->getShortPressKeycode();
             break;
         }
     }
@@ -419,7 +420,8 @@ int KeyboardShortcut::getHwKeyCode(QString item)
     if (index == hwKeyList.count()) {
         for (index = 0; index < controllerKeyList.count(); index++) {
             if (controllerKeyList.at(index)->name.compare(item) == 0) {
-                keyCode = controllerKeyList.at(index)->keycode;
+                keyCode = controllerKeyList.at(index)->
+                    getKeycodeType()->getShortPressKeycode();
                 break;
             }
         }
index b10587af567dc1121d581683c1d815084ea236ed..dc0c9ddfc3a1e9e002348dd92c350f15d441e4f7 100644 (file)
@@ -3,4 +3,5 @@ obj-$(CONFIG_QT) += mainform.o
 obj-$(CONFIG_QT) += controllerform.o
 obj-$(CONFIG_QT) += displaytype.o
 obj-$(CONFIG_QT) += hardwarekey.o
-obj-$(CONFIG_QT) += hovertype.o
\ No newline at end of file
+obj-$(CONFIG_QT) += hovertype.o
+obj-$(CONFIG_QT) += keycodetype.o
\ No newline at end of file
index ba09e5081b8016593b766344fb199d3aba44e4bc..4c087ec3e7d6f841f94fd1eace4105d892ee3e85 100644 (file)
 
 #include "hardwarekey.h"
 
-HardwareKey::HardwareKey(QString name, int keycode, QRect region, QString tooltip, QString keySequence)
+HardwareKey::HardwareKey(QString name, KeycodeType *keycodeType,
+    QRect region, QString tooltip, QString keySequence)
 {
     this->name = name;
-    this->keycode = keycode;
+    this->keycodeType = keycodeType;
     this->region = region;
     this->tooltip = tooltip;
     this->keySequence = keySequence;
+
+    if (keycodeType == NULL) {
+        this->keycodeType = new KeycodeType(-1, -1);
+    }
+}
+
+KeycodeType *HardwareKey::getKeycodeType()
+{
+    return keycodeType;
+}
+
+bool HardwareKey::hasLongPressKeycode()
+{
+    return (keycodeType->getLongPressKeycode() > 0);
 }
 
 HardwareKey::~HardwareKey()
 {
-    /* do nothing */
+    if (keycodeType != NULL) {
+        delete keycodeType;
+    }
 }
index 4b85f75161850f986fa6f9e5d5e5a276f829dc2f..ac1a38a20cc593cb8da550c268ba3194999f1664 100644 (file)
 
 #include <QWidget>
 
+#include "layout/keycodetype.h"
+
 class HardwareKey
 {
 public:
-    HardwareKey(QString name, int keycode, QRect region, QString tooltip, QString keySequence);
+    HardwareKey(QString name, KeycodeType *keycodeType,
+        QRect region, QString tooltip, QString keySequence);
     ~HardwareKey();
 
+    KeycodeType *getKeycodeType();
+    bool hasLongPressKeycode();
+
     QString name;
-    int keycode;
     QRect region;
     QString tooltip;
     QString keySequence;
+
+private:
+    KeycodeType *keycodeType;
 };
 
 #endif // HARDWAREKEY_H
diff --git a/tizen/src/ui/layout/keycodetype.cpp b/tizen/src/ui/layout/keycodetype.cpp
new file mode 100644 (file)
index 0000000..5974957
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include <QDebug>
+
+#include "keycodetype.h"
+
+KeycodeType::KeycodeType(int shortPress)
+{
+    this->shortPress = shortPress;
+    this->longPress = -1;
+}
+
+KeycodeType::KeycodeType(int shortPress, int longPress)
+{
+    this->shortPress = shortPress;
+    this->longPress = longPress;
+}
+
+int KeycodeType::getShortPressKeycode()
+{
+    if (shortPress <= 0) {
+        qWarning() << "invalid short press keycode:" << shortPress;
+    }
+
+    return shortPress;
+}
+
+int KeycodeType::getLongPressKeycode()
+{
+    return longPress;
+}
+
+KeycodeType::~KeycodeType()
+{
+    /* do nothing */
+}
diff --git a/tizen/src/ui/layout/keycodetype.h b/tizen/src/ui/layout/keycodetype.h
new file mode 100644 (file)
index 0000000..5de6677
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef KEYCODETYPE_H
+#define KEYCODETYPE_H
+
+#include <QWidget>
+
+class KeycodeType
+{
+public:
+    KeycodeType(int shortPress);
+    KeycodeType(int shortPress, int longPress);
+    ~KeycodeType();
+
+    int getShortPressKeycode();
+    int getLongPressKeycode();
+
+private:
+    int shortPress;
+    int longPress;
+};
+
+#endif // KEYCODETYPE_H
index 6cb5d3630345f65d62e6b9e8fd56bb98fa51f0c3..8431c0f90d9426c1ada9be9961285fd657c8f1ea 100644 (file)
@@ -27,6 +27,8 @@
  *
  */
 
+#include <QDebug>
+
 #include "skinkeyitem.h"
 
 SkinKeyItem::SkinKeyItem(SkinBezelItem *parent,
@@ -62,14 +64,16 @@ void SkinKeyItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
     bezelParent->setHWKeyHandling(isPressed = true);
 
-    if (hwKey->keycode == LONGPRESS_KEYCODE) {
+    if (hwKey->hasLongPressKeycode() == true) {
         /* long press checking first */
         longPressTimer->start();
         return;
     }
 
-    qDebug("HW key pressed: %s", qPrintable(hwKey->name));
-    do_hw_key_event(KEY_PRESSED, hwKey->keycode);
+    const int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
+
+    qDebug() << hwKey->name << "key pressed:" << keycode;
+    do_hw_key_event(KEY_PRESSED, keycode);
 
     hoverPen.setColor(Qt::transparent);
     update();
@@ -80,22 +84,25 @@ void SkinKeyItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
     bezelParent->setHWKeyHandling(isPressed = false);
 
-    const int keyCode = hwKey->keycode;
-    if (keyCode == LONGPRESS_KEYCODE) {
+    int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
+
+    if (hwKey->hasLongPressKeycode() == true) {
         if (longPressTimer->remainingTime() <= 0) {
             /* long press */
-            qDebug("HW key long pressed : %s", qPrintable(hwKey->name));
+            keycode = hwKey->getKeycodeType()->getLongPressKeycode();
+            qDebug() << hwKey->name << "key long pressed:" << keycode;
         } else {
             /* short press */
             longPressTimer->stop();
-            qDebug("HW key short pressed : %s", qPrintable(hwKey->name));
+
+           qDebug() << hwKey->name << "key short pressed:" << keycode;
         }
 
-        do_hw_key_event(KEY_PRESSED, keyCode);
+        do_hw_key_event(KEY_PRESSED, keycode);
     }
 
-    qDebug("HW key released: %s", qPrintable(hwKey->name));
-    do_hw_key_event(KEY_RELEASED, keyCode);
+    qDebug() << hwKey->name << "key released:" << keycode;
+    do_hw_key_event(KEY_RELEASED, keycode);
 
     update();
 }
@@ -137,7 +144,7 @@ void SkinKeyItem::paint(QPainter *painter,
 
 void SkinKeyItem::longPressHook()
 {
-    qDebug("long press detected");
+    qDebug("key long press detected");
 
     /* do nothing */
 }
index 5dad7f74c101074edc7a6409f07d55805fb46e89..85e1e0b71e3f87c325219b26352a670e3722567b 100644 (file)
@@ -43,8 +43,6 @@ extern "C" {
 #include "emul_state.h"
 }
 
-#define LONGPRESS_KEYCODE (-999)
-
 class SkinKeyItem : public QObject, public QGraphicsRectItem
 {
     Q_OBJECT