touch: added touch screen helper
authorGiWoong Kim <giwoong.kim@samsung.com>
Tue, 28 Apr 2015 05:57:06 +0000 (14:57 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 28 Apr 2015 07:43:30 +0000 (16:43 +0900)
Change-Id: I8d870b979320cbffdcede599dca711f71de5f42a
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/displaybase.cpp
tizen/src/ui/displaybase.h
tizen/src/ui/input/Makefile.objs
tizen/src/ui/input/touchscreenhelper.cpp [new file with mode: 0644]
tizen/src/ui/input/touchscreenhelper.h [new file with mode: 0644]

index 7eefafd..7b0ccb9 100644 (file)
@@ -42,6 +42,7 @@ DisplayBase::DisplayBase(QRect rect, int angle, qreal scaleFactor,
     this->rotateAngle = angle;
     this->scaleFactor = scaleFactor;
     this->isDragging = false;
+    this->tsHelper = new TouchScreenHelper();
 
     updateGeometry();
 }
@@ -97,12 +98,41 @@ void DisplayBase::handleResize(QResizeEvent *event)
     qt5_graphic_hw_invalidate();
 }
 
+QPoint DisplayBase::getGuestPos(QPoint hostPos)
+{
+    QPoint guestPos = hostPos / scaleFactor;
+
+    const int guestPosX = guestPos.x();
+    const int guestPosY = guestPos.y();
+
+    /* TODO: calculate for all angle (x*cos(rad)-y*sin(rad)) */
+    switch(rotateAngle) {
+    case 90: /* Reverse Landscape */
+        guestPos.setX(guestPosY);
+        guestPos.setY(rect.height() - guestPosX);
+        break;
+    case 180: /* Reverse Portrait */
+        guestPos.setX(rect.width() - guestPosX);
+        guestPos.setY(rect.height() - guestPosY);
+        break;
+    case 270: /* Landscape */
+        guestPos.setX(rect.width() - guestPosY);
+        guestPos.setY(guestPosX);
+        break;
+    case 0:
+    default:
+        break;
+    }
+
+    return guestPos;
+}
+
 void DisplayBase::handleMousePress(QMouseEvent *event)
 {
     if (event->button() == Qt::LeftButton) {
         isDragging = true;
 
-        sendTouchEvent(TOUCH_PRESS, event->x(), event->y());
+        tsHelper->mousePressed(event, getGuestPos(event->pos()));
     }
 }
 
@@ -113,71 +143,50 @@ void DisplayBase::handleMouseRelease(QMouseEvent *event)
             isDragging = false;
         }
 
-        sendTouchEvent(TOUCH_RELEASE, event->x(), event->y());
+        tsHelper->mouseReleased(event, getGuestPos(event->pos()));
     }
 }
 
 void DisplayBase::handleMouseMove(QMouseEvent *event)
 {
     if (isDragging == true) {
-        int event_type = TOUCH_PRESS;
-        int clientX = event->x();
-        int clientY = event->y();
+        int hostPosX = event->x();
+        int hostPosY = event->y();
 
-        if (clientX < 0) {
-            event_type = TOUCH_RELEASE;
-            clientX = 0;
+        /* bounds checking */
+        if (hostPosX < 0) {
+            hostPosX = 0;
             isDragging = false;
-        } else if (clientX >= widget->width()) {
-            event_type = TOUCH_RELEASE;
-            clientX = widget->width() - 1;
+        } else if (hostPosX >= widget->width()) {
+            hostPosX = widget->width() - 1;
             isDragging = false;
         }
 
-        if (clientY < 0) {
-            event_type = TOUCH_RELEASE;
-            clientY = 0;
+        if (hostPosY < 0) {
+            hostPosY = 0;
             isDragging = false;
-        } else if (clientY >= widget->height()) {
-            event_type = TOUCH_RELEASE;
-            clientY = widget->height() - 1;
+        } else if (hostPosY >= widget->height()) {
+            hostPosY = widget->height() - 1;
             isDragging = false;
         }
 
-        sendTouchEvent(event_type, clientX, clientY);
-    }
-}
-
-void DisplayBase::sendTouchEvent(int eventType, int clientX, int clientY)
-{
-    int xx = clientX / scaleFactor;
-    int yy = clientY / scaleFactor;
-    int absX = xx;
-    int absY = yy;
+        if (isDragging == false) {
+            QPoint clientPos(hostPosX, hostPosY);
+            qDebug() << "drag out of touch screen :" << clientPos;
 
-    /* TODO: x*cos(rad)-y*sin(rad) */
-    switch(rotateAngle) {
-    case 90: /* Reverse Landscape */
-        absX = yy;
-        absY = rect.height() - xx;
-        break;
-    case 180: /* Reverse Portrait */
-        absX = rect.width() - xx;
-        absY = rect.height() - yy;
-        break;
-    case 270: /* Landscape */
-        absX = rect.width() - yy;
-        absY = xx;
-        break;
-    case 0:
-    default:
-        break;
+            // TODO: modify event
+            tsHelper->mouseReleased(event, getGuestPos(clientPos));
+        } else {
+            tsHelper->mouseMoved(event, getGuestPos(event->pos()));
+        }
     }
-
-    do_mouse_event(0, eventType, clientX, clientY, absX, absY, 0);
 }
 
 DisplayBase::~DisplayBase()
 {
     qDebug("destroy display");
+
+    if (tsHelper != NULL) {
+        delete tsHelper;
+    }
 }
index ed1ccfd..8728bd5 100644 (file)
 
 #include <QWidget>
 
+#include "input/touchscreenhelper.h"
+
 extern "C" {
 void qt5_graphic_hw_invalidate(void);
 }
 
-enum {
-    TOUCH_PRESS = 1,
-    TOUCH_RELEASE = 2,
-};
-
 class DisplayBase
 {
 public:
@@ -49,6 +46,7 @@ public:
     void scale(qreal scaleFactor);
     void update();
     void updateGeometry();
+    QPoint getGuestPos(QPoint hostPos);
 
 protected:
     DisplayBase(QRect rect, int angle, qreal scaleFactor, QWidget *w);
@@ -62,14 +60,13 @@ protected:
     void handleMouseMove(QMouseEvent *event);
 
 private:
-    void sendTouchEvent(int eventType, int clientX, int clientY);
-
     QWidget *widget;
     QRect rect;
     int rotateAngle;
     qreal scaleFactor;
 
     bool isDragging;
+    TouchScreenHelper *tsHelper;
 };
 
 #endif
index 315eb09..71484d4 100644 (file)
@@ -1,3 +1,4 @@
+obj-$(CONFIG_QT) += touchscreenhelper.o
 obj-$(CONFIG_QT) += keyboardhelper.o
 obj-$(CONFIG_QT) += keyboardshortcut.o moc_keyboardshortcut.o
 
diff --git a/tizen/src/ui/input/touchscreenhelper.cpp b/tizen/src/ui/input/touchscreenhelper.cpp
new file mode 100644 (file)
index 0000000..cd11e1f
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Qt touch screen helper
+ *
+ * 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 <QWidget>
+
+#include "touchscreenhelper.h"
+
+extern "C" {
+#include "emul_state.h"
+#include "skin/maruskin_operation.h"
+
+void virtio_touchscreen_event(int x, int y, int z, int buttons_state);
+}
+
+TouchScreenHelper::TouchScreenHelper()
+{
+    /* do nothing */
+}
+
+void TouchScreenHelper::mousePressed(QMouseEvent *event, QPoint guestPos)
+{
+    // TODO: multi-touch
+
+    virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1);
+}
+
+void TouchScreenHelper::mouseReleased(QMouseEvent *event, QPoint guestPos)
+{
+    // TODO: multi-touch
+
+    virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 0);
+}
+
+void TouchScreenHelper::mouseMoved(QMouseEvent *event, QPoint guestPos)
+{
+    // TODO: multi-touch
+
+    virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1);
+}
+
+TouchScreenHelper::~TouchScreenHelper()
+{
+    qDebug("destroy touch screen helper");
+}
diff --git a/tizen/src/ui/input/touchscreenhelper.h b/tizen/src/ui/input/touchscreenhelper.h
new file mode 100644 (file)
index 0000000..90745a2
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Qt touch screen helper
+ *
+ * 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 TOUCHSCREENHELPER_H
+#define TOUCHSCREENHELPER_H
+
+class TouchScreenHelper
+{
+public:
+    TouchScreenHelper();
+    ~TouchScreenHelper();
+
+    void mousePressed(QMouseEvent *event, QPoint guestPos);
+    void mouseReleased(QMouseEvent *event, QPoint guestPos);
+    void mouseMoved(QMouseEvent *event, QPoint guestPos);
+
+private:
+};
+
+#endif // TOUCHSCREENHELPER_H