*/
#include "displaybase.h"
-#include "resource/ui_strings.h"
#include "mainwindow.h"
+#include "resource/ui_strings.h"
extern "C" {
#include "util/ui_operations.h"
void qt5_graphic_hw_invalidate(void);
void req_set_sensor_accel_angle(int angle);
-void maru_tablet_event(int event_type, int x, int y, int btn, int btn_status);
}
uint32_t qt5_window_width = 0;
this->offGuide = NULL;
this->offGuideShown = false;
- this->isTouch = is_touchscreen_enabled();
+ this->isTsEnabled = is_touchscreen_enabled();
/* touch screen */
this->tsHelper = new TouchScreenHelper(this);
+ win->getMainView()->getKbdHelper()->setMtTracker(tsHelper->getMtTracker());
/* mouse */
- this->prevX = 0;
- this->prevY = 0;
- this->lastMouseTime.tv_sec = 0;
- this->mouseStatus = MOUSE_LEAVE;
+ this->mouseHelper = new MouseHelper(this, resolution);
- win->getMainView()->getKbdHelper()->setMtTracker(tsHelper->getMtTracker());
-
- loadGuideImg();
+ loadOffGuideImg();
+ req_set_sensor_accel_angle(rotateAngle); /* update sensor */
updateGeometry();
-
- /* update sensor */
- req_set_sensor_accel_angle(rotateAngle);
}
-void DisplayBase::loadGuideImg()
+void DisplayBase::loadOffGuideImg()
{
QString offImage = QDir(QCoreApplication::applicationDirPath() +
QDir::separator() + SDK_EMULATOR_IMAGES_PATH +
rect = displayForm->getRect();
maskImage = displayForm->getMask();
- /* update sensor */
- req_set_sensor_accel_angle(rotateAngle);
-
+ req_set_sensor_accel_angle(rotateAngle); /* update sensor */
updateGeometry();
- update();
+ update();
widget->repaint();
}
this->scaleFactor = scaleFactor;
updateGeometry();
- update();
+ update();
widget->repaint();
}
return tsHelper;
}
+MouseHelper *DisplayBase::getMouseHelper()
+{
+ return mouseHelper;
+}
+
void DisplayBase::handleMousePress(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
isDragging = true;
- if (isTouch) {
+ if (isTsEnabled == true) {
tsHelper->mousePressed(event, getGuestPos(event->pos()));
} else {
- do_mouse_event(1, PS2_PRESS, 0, 0, 0, 0, 0);
+ mouseHelper->mousePressed(event);
}
}
}
void DisplayBase::handleMouseRelease(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
- if (isDragging) {
+ if (isDragging == true) {
isDragging = false;
}
- if (isTouch) {
+ if (isTsEnabled == true) {
tsHelper->mouseReleased(event, getGuestPos(event->pos()));
} else {
- do_mouse_event(1, PS2_RELEASE, 0, 0, 0, 0, 0);
+ mouseHelper->mouseReleased(event);
}
}
}
void DisplayBase::handleMouseMove(QMouseEvent *event)
{
- if (isTouch) { /* touch device */
+ if (isTsEnabled == true) { /* touch device */
if (isDragging == true) {
int hostPosX = event->x();
int hostPosY = event->y();
tsHelper->mouseMoved(event, getGuestPos(event->pos()));
}
}
- } else {
- int event_type = MOUSE_MOVE;
- int clientX = event->x();
- int clientY = event->y();
+ } else { /* mouse device */
+ const int hostPosX = event->x();
+ const int hostPosY = event->y();
- if (clientX < 0 || clientX > widget->width() ||
- clientY < 0 || clientY > widget->height()) {
+ if (hostPosX < 0 || hostPosX > widget->width() ||
+ hostPosY < 0 || hostPosY > widget->height()) {
if (isDragging == true) {
+ qDebug("drag out: auto release");
+
isDragging = false;
- qDebug("auto released...");
- do_mouse_event(1, PS2_RELEASE, 0, 0, 0, 0, 0);
+ mouseHelper->mouseReleased(event);
return;
- } else {
- /* do nothing */
}
}
- sendMouseEvent(event_type, clientX, clientY);
- }
-}
-void DisplayBase::handleMouseInit(QMouseEvent *event)
-{
- do_mouse_event(1, MOUSE_MOVE, -widget->width()/scaleFactor,
- -widget->height()/scaleFactor,
- -widget->width()/scaleFactor,
- -widget->height()/scaleFactor, 0);
- prevX = 0;
- prevY = 0;
+ mouseHelper->mouseMoved(event,
+ event->pos(), getGuestPos(event->pos()));
+ }
}
void DisplayBase::handleMouseEnter(QEvent *event)
{
- if (!isTouch) {
- if (mouseStatus == MOUSE_LEAVE) {
- mouseStatus = MOUSE_ENTER;
- }
+ if (isTsEnabled == false) {
+ mouseHelper->mouseEnter(event);
}
}
void DisplayBase::handleMouseLeave(QEvent *event)
{
- if (!isTouch) {
- mouseStatus = MOUSE_LEAVE;
+ if (isTsEnabled == false) {
+ mouseHelper->mouseLeave(event);
}
}
-void DisplayBase::sendMouseEvent(int eventType, int clientX, int clientY)
-{
- int xx = clientX / scaleFactor;
- int yy = clientY / scaleFactor;
- int absX = xx;
- int absY = yy;
-
- /* TODO: x*cos(rad)-y*sin(rad) */
- switch(rotateAngle) {
- case 90: /* Reverse Landscape */
- absX = yy;
- absY = resolution.height() - xx;
- break;
- case 180: /* Reverse Portrait */
- absX = resolution.width() - xx;
- absY = resolution.height() - yy;
- break;
- case 270: /* Landscape */
- absX = resolution.width() - yy;
- absY = xx;
- break;
- case 0:
- default:
- break;
- }
-
- /* Because the TV usb mouse pointer is moved to center after a couple of seconds.
- * Also the mouse pointer can be entered before emulator skin is initialized.
- */
- struct timeval tv;
- gettimeofday(&tv, NULL);
- if (tv.tv_sec - lastMouseTime.tv_sec > CURSOR_RESET_TIME || mouseStatus != MOUSE_ENTERED) {
- maru_tablet_event(INPUT_MOVE, absX, absY, 0, 0);
- prevX = absX;
- prevY = absY;
- mouseStatus = MOUSE_ENTERED;
- }
- gettimeofday(&lastMouseTime, NULL);
-
- prevX = (prevX > resolution.width()) ? resolution.width() : prevX;
- prevX = (prevX < 0) ? 0 : prevX;
-
- prevY = (prevY > resolution.height()) ? resolution.height() : prevY;
- prevY = (prevY < 0) ? 0 : prevY;
-
- int relX = absX - prevX;
- int relY = absY - prevY;
-
- do_mouse_event(1, MOUSE_MOVE, clientX, clientY, relX, relY, 0);
- prevX = absX;
- prevY = absY;
-}
-
DisplayBase::~DisplayBase()
{
qDebug("destroy display");
if (tsHelper != NULL) {
delete tsHelper;
}
+ if (mouseHelper != NULL) {
+ delete mouseHelper;
+ }
}
#include <QLabel>
#include <QImage>
#include <QPixmap>
-#include <sys/time.h>
#include "layout/displaytype.h"
#include "input/touchscreenhelper.h"
+#include "input/mousehelper.h"
class MainWindow;
-enum {
- TOUCH_PRESS = 1,
- TOUCH_RELEASE = 2,
- PS2_MOVE = 6,
- PS2_PRESS = 8,
- PS2_RELEASE = 9,
-};
-
-enum {
- MOUSE_LEAVE = 0,
- MOUSE_ENTER = 1,
- MOUSE_ENTERED = 2,
-};
-
-/* keep it consistent with emulator-kernel tablet definition */
-enum {
- INPUT_MOVE = 1,
- INPUT_BTN = 2,
-};
-
-#define CURSOR_RESET_TIME 6 /* TV spec (sec) */
-
class DisplayBase
{
public:
QPoint getGuestPos(QPoint hostPos);
TouchScreenHelper *getTouchScreenHelper();
+ MouseHelper *getMouseHelper();
protected:
DisplayBase(DisplayType *displayForm, QSize resolution, qreal scaleFactor, QWidget *w);
void handleMousePress(QMouseEvent *event);
void handleMouseRelease(QMouseEvent *event);
void handleMouseMove(QMouseEvent *event);
- void handleMouseInit(QMouseEvent *event);
void handleMouseEnter(QEvent *event);
void handleMouseLeave(QEvent *event);
bool isDragging;
private:
- void loadGuideImg();
-
- void sendMouseEvent(int eventType, int clientX, int clientY);
+ void loadOffGuideImg();
QSize resolution;
- bool isTouch;
-
- int prevX;
- int prevY;
- int mouseStatus;
- struct timeval lastMouseTime;
+ bool isTsEnabled;
MainWindow *win;
QWidget *widget; /* child */
QRect rect;
QPixmap maskImage;
+
TouchScreenHelper *tsHelper;
+ MouseHelper *mouseHelper;
QLabel *offGuide;
QPixmap offGuideImg;
obj-$(CONFIG_QT) += touchscreenhelper.o
obj-$(CONFIG_QT) += multitouchtracker.o
+obj-$(CONFIG_QT) += mousehelper.o
obj-$(CONFIG_QT) += keyboardhelper.o
obj-$(CONFIG_QT) += keyboardshortcut.o moc_keyboardshortcut.o
--- /dev/null
+/*
+ * Qt mouse helper
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@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 <QMouseEvent>
+
+#include "mousehelper.h"
+
+extern "C" {
+#include "emul_state.h"
+#include "util/ui_operations.h"
+
+void maru_tablet_event(int event_type, int x, int y, int btn, int btn_status);
+}
+
+#define CURSOR_RESET_TIME (6) /* TV spec (sec) */
+
+MouseHelper::MouseHelper(void *parent, QSize resolution)
+{
+ this->parent = parent;
+ this->resolution = resolution;
+
+ this->prevX = 0;
+ this->prevY = 0;
+ this->mouseStatus = MOUSE_LEAVE;
+ this->lastMouseTime.tv_sec = 0;
+}
+
+void *MouseHelper::getParent()
+{
+ return parent;
+}
+
+void MouseHelper::mousePressed(QMouseEvent *event)
+{
+ Q_UNUSED(event);
+
+ do_mouse_event(1, PS2_PRESS, 0, 0, 0, 0, 0);
+}
+
+void MouseHelper::mouseReleased(QMouseEvent *event)
+{
+ Q_UNUSED(event);
+
+ do_mouse_event(1, PS2_RELEASE, 0, 0, 0, 0, 0);
+}
+
+void MouseHelper::mouseMoved(QMouseEvent *event,
+ QPoint hostPos, QPoint guestPos)
+{
+ const int absX = guestPos.x();
+ const int absY = guestPos.y();
+
+ /* Because the TV usb mouse pointer is moved to center after a couple of seconds.
+ * Also the mouse pointer can be entered before emulator skin is initialized.
+ */
+
+ gettimeofday(&tv, NULL);
+ if (tv.tv_sec - lastMouseTime.tv_sec > CURSOR_RESET_TIME ||
+ mouseStatus != MOUSE_ENTERED)
+ {
+ maru_tablet_event(INPUT_MOVE, absX, absY, 0, 0);
+ prevX = absX;
+ prevY = absY;
+ mouseStatus = MOUSE_ENTERED;
+ }
+ gettimeofday(&lastMouseTime, NULL);
+
+ prevX = qMin(resolution.width(), prevX);
+ prevX = qMax(0, prevX);
+ prevY = qMin(resolution.height(), prevY);
+ prevY = qMax(0, prevY);
+
+ /* relative positioning */
+ const int relX = absX - prevX;
+ const int relY = absY - prevY;
+
+ do_mouse_event(1, MOUSE_MOVE, hostPos.x(), hostPos.y(), relX, relY, 0);
+
+ prevX = absX;
+ prevY = absY;
+}
+
+void MouseHelper::mouseEnter(QEvent *event)
+{
+ Q_UNUSED(event);
+
+ if (mouseStatus == MOUSE_LEAVE) {
+ mouseStatus = MOUSE_ENTER;
+ }
+}
+
+void MouseHelper::mouseLeave(QEvent *event)
+{
+ Q_UNUSED(event);
+
+ mouseStatus = MOUSE_LEAVE;
+}
+
+MouseHelper::~MouseHelper()
+{
+ qDebug("destroy mouse helper");
+}
--- /dev/null
+/*
+ * Qt mouse helper
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@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 MOUSEHELPER_H
+#define MOUSEHELPER_H
+
+#include <sys/time.h>
+
+enum {
+ PS2_MOVE = 6,
+ PS2_PRESS = 8,
+ PS2_RELEASE = 9,
+};
+
+enum {
+ MOUSE_LEAVE = 0,
+ MOUSE_ENTER = 1,
+ MOUSE_ENTERED = 2,
+};
+
+/* keep it consistent with emulator-kernel tablet definition */
+enum {
+ INPUT_MOVE = 1,
+ INPUT_BTN = 2,
+};
+
+class MouseHelper
+{
+public:
+ MouseHelper(void *parent, QSize resolution);
+ ~MouseHelper();
+
+ void *getParent();
+
+ void mousePressed(QMouseEvent *event);
+ void mouseReleased(QMouseEvent *event);
+ void mouseMoved(QMouseEvent *event, QPoint hostPos, QPoint guestPos);
+
+ void mouseEnter(QEvent *event);
+ void mouseLeave(QEvent *event);
+
+private:
+ void *parent;
+ QSize resolution;
+
+ int prevX;
+ int prevY;
+ int mouseStatus;
+ struct timeval tv;
+ struct timeval lastMouseTime;
+};
+
+#endif // MOUSEHELPER_H