From 6ce81fcbe6c4b47b215852b4f33fc20bfcddf51a Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Tue, 28 Apr 2015 14:57:06 +0900 Subject: [PATCH] touch: added touch screen helper Change-Id: I8d870b979320cbffdcede599dca711f71de5f42a Signed-off-by: GiWoong Kim --- tizen/src/ui/displaybase.cpp | 101 +++++++++++++++++-------------- tizen/src/ui/displaybase.h | 11 ++-- tizen/src/ui/input/Makefile.objs | 1 + tizen/src/ui/input/touchscreenhelper.cpp | 70 +++++++++++++++++++++ tizen/src/ui/input/touchscreenhelper.h | 46 ++++++++++++++ 5 files changed, 176 insertions(+), 53 deletions(-) create mode 100644 tizen/src/ui/input/touchscreenhelper.cpp create mode 100644 tizen/src/ui/input/touchscreenhelper.h diff --git a/tizen/src/ui/displaybase.cpp b/tizen/src/ui/displaybase.cpp index 7eefafd..7b0ccb9 100644 --- a/tizen/src/ui/displaybase.cpp +++ b/tizen/src/ui/displaybase.cpp @@ -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; + } } diff --git a/tizen/src/ui/displaybase.h b/tizen/src/ui/displaybase.h index ed1ccfd..8728bd5 100644 --- a/tizen/src/ui/displaybase.h +++ b/tizen/src/ui/displaybase.h @@ -33,15 +33,12 @@ #include +#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 diff --git a/tizen/src/ui/input/Makefile.objs b/tizen/src/ui/input/Makefile.objs index 315eb09..71484d4 100644 --- a/tizen/src/ui/input/Makefile.objs +++ b/tizen/src/ui/input/Makefile.objs @@ -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 index 0000000..cd11e1f --- /dev/null +++ b/tizen/src/ui/input/touchscreenhelper.cpp @@ -0,0 +1,70 @@ +/* + * Qt touch screen helper + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * Sangho Park + * + * 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 + +#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 index 0000000..90745a2 --- /dev/null +++ b/tizen/src/ui/input/touchscreenhelper.h @@ -0,0 +1,46 @@ +/* + * Qt touch screen helper + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * Sangho Park + * + * 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 -- 2.7.4