this->rotateAngle = angle;
this->scaleFactor = scaleFactor;
this->isDragging = false;
+ this->tsHelper = new TouchScreenHelper();
updateGeometry();
}
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()));
}
}
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;
+ }
}
#include <QWidget>
+#include "input/touchscreenhelper.h"
+
extern "C" {
void qt5_graphic_hw_invalidate(void);
}
-enum {
- TOUCH_PRESS = 1,
- TOUCH_RELEASE = 2,
-};
-
class DisplayBase
{
public:
void scale(qreal scaleFactor);
void update();
void updateGeometry();
+ QPoint getGuestPos(QPoint hostPos);
protected:
DisplayBase(QRect rect, int angle, qreal scaleFactor, QWidget *w);
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
+obj-$(CONFIG_QT) += touchscreenhelper.o
obj-$(CONFIG_QT) += keyboardhelper.o
obj-$(CONFIG_QT) += keyboardshortcut.o moc_keyboardshortcut.o
--- /dev/null
+/*
+ * 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");
+}
--- /dev/null
+/*
+ * 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