From f45398a5eb1c19405282b5590d7c3f8f250c1eef Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Thu, 4 Feb 2016 16:28:21 +0900 Subject: touch: minor cleanup for touch event - remove dependency with emul_state - modify function and variable names Change-Id: I675bc802ea9ee54e7b587f7f5441623cdd71ac12 Signed-off-by: GiWoong Kim --- tizen/src/emul_state.c | 11 ----- tizen/src/emul_state.h | 4 -- tizen/src/ui/displaybase.cpp | 9 ++-- tizen/src/ui/input/keyboardhelper.cpp | 39 ++++++++-------- tizen/src/ui/input/multitouchtracker.cpp | 79 +++++++++++++++++++------------- tizen/src/ui/input/multitouchtracker.h | 24 ++++++---- tizen/src/ui/input/touchscreenhelper.cpp | 28 +++++------ tizen/src/ui/input/touchscreenhelper.h | 6 +-- 8 files changed, 102 insertions(+), 98 deletions(-) (limited to 'tizen') diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index 862a5b8c40..22d9dd5238 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -94,17 +94,6 @@ void set_emulator_condition(int state) _emul_state.emulator_condition = state; } -/* emulator multi-touch */ -void set_multi_touch_enable(int mode) -{ - _emul_state.multitouch_enable = mode; -} - -int get_multi_touch_enable(void) -{ - return _emul_state.multitouch_enable; -} - void set_emuld_connection(bool connected) { _emul_state.emuld_connection = connected; diff --git a/tizen/src/emul_state.h b/tizen/src/emul_state.h index 988d748ad8..90cccf1b7e 100644 --- a/tizen/src/emul_state.h +++ b/tizen/src/emul_state.h @@ -112,10 +112,6 @@ bool get_emuld_connection(void); bool get_sdb_connection(void); int get_max_touch_point(void); -/* multi-touch */ -void set_multi_touch_enable(int mode); -int get_multi_touch_enable(void); - // cleaned-up extern const char *launch_conf_file; extern const char *bin_path; diff --git a/tizen/src/ui/displaybase.cpp b/tizen/src/ui/displaybase.cpp index 6db630a0c6..f74364bf3a 100644 --- a/tizen/src/ui/displaybase.cpp +++ b/tizen/src/ui/displaybase.cpp @@ -280,7 +280,7 @@ void DisplayBase::handleMousePress(QMouseEvent *event) isDragging = true; if (tsHelper != NULL) { - tsHelper->mousePressed(event, getGuestPos(event->pos())); + tsHelper->touchPressed(event->pos(), getGuestPos(event->pos())); } if (mouseHelper != NULL) { mouseHelper->mousePressed(); @@ -308,7 +308,7 @@ void DisplayBase::handleMouseRelease(QMouseEvent *event) } if (tsHelper != NULL) { - tsHelper->mouseReleased(event, getGuestPos(event->pos())); + tsHelper->touchReleased(event->pos(), getGuestPos(event->pos())); } if (mouseHelper != NULL) { mouseHelper->mouseReleased(); @@ -354,10 +354,9 @@ void DisplayBase::handleMouseMove(QMouseEvent *event) QPoint clientPos(hostPosX, hostPosY); qDebug() << "drag out of touch screen:" << clientPos; - // TODO: modify event - tsHelper->mouseReleased(event, getGuestPos(clientPos)); + tsHelper->touchReleased(event->pos(), getGuestPos(clientPos)); } else { - tsHelper->mouseMoved(event, getGuestPos(event->pos())); + tsHelper->touchMoved(event->pos(), getGuestPos(event->pos())); } } } diff --git a/tizen/src/ui/input/keyboardhelper.cpp b/tizen/src/ui/input/keyboardhelper.cpp index 30c2e5d50c..57560cb130 100644 --- a/tizen/src/ui/input/keyboardhelper.cpp +++ b/tizen/src/ui/input/keyboardhelper.cpp @@ -230,20 +230,23 @@ void KeyboardHelper::autoKeyRelease(void) keyCodeList.removeLast(); } - /* disable multi-touch mode */ - if (get_multi_touch_enable() != MultiTouchTracker::MT_OFF) { - qDebug() << "disable multi-touch"; + if (mtTracker != NULL) { + /* disable multi-touch mode */ + if (mtTracker->getMtMode() != MultiTouchTracker::MT_OFF) { + qDebug() << "disable multi-touch"; - set_multi_touch_enable(MultiTouchTracker::MT_OFF); - mtTracker->finishTracking(); + mtTracker->finishTracking(); + } } } int KeyboardHelper::keyCodeOperation(QKeyEvent *event, int keyCode) { /* keypad and specialKey translation */ - if (!hostNumLockState && (event->modifiers() == (Qt::KeypadModifier | Qt::ShiftModifier))) { + if (!hostNumLockState && + (event->modifiers() == (Qt::KeypadModifier | Qt::ShiftModifier))) { QMap::iterator keypadIter = keypadMap.find(keyCode); + while (keypadIter != keypadMap.end()) { if (keypadIter.key() == keyCode) { keyCode = keypadIter.value(); @@ -298,37 +301,36 @@ void KeyboardHelper::pressFilterMtChecking(QKeyEvent *event) case Qt::Key_Alt: if (event->modifiers() == (Qt::ControlModifier | Qt::AltModifier)) { qDebug() << "enable multi-touch mode: SYMM"; - set_multi_touch_enable(MultiTouchTracker::MT_SYMM); + mtTracker->setMtMode(MultiTouchTracker::MT_SYMM); - mtTracker->leaveTouchPoint(MT_SYMM_MAX_POINT); + mtTracker->limitTouchCnt(MT_SYMM_MAX_POINT); } break; case Qt::Key_Shift: if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) { qDebug() << "enable multi-touch mode: PARA"; - set_multi_touch_enable(MultiTouchTracker::MT_PARA); + mtTracker->setMtMode(MultiTouchTracker::MT_PARA); } else if (event->modifiers() == Qt::ShiftModifier) { qDebug() << "enable multi-touch mode: SEPA"; - set_multi_touch_enable(MultiTouchTracker::MT_SEPA); + mtTracker->setMtMode(MultiTouchTracker::MT_SEPA); } break; case Qt::Key_Control: if (event->modifiers() == Qt::ControlModifier) { qDebug() << "enable multi-touch mode: SEPA"; - set_multi_touch_enable(MultiTouchTracker::MT_SEPA); + mtTracker->setMtMode(MultiTouchTracker::MT_SEPA); } else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) { qDebug() << "enable multi-touch mode: PARA"; - set_multi_touch_enable(MultiTouchTracker::MT_PARA); + mtTracker->setMtMode(MultiTouchTracker::MT_PARA); } break; default: - if (get_multi_touch_enable() != MultiTouchTracker::MT_OFF) { + if (mtTracker->getMtMode() != MultiTouchTracker::MT_OFF) { qDebug() << "disable multi-touch"; - set_multi_touch_enable(MultiTouchTracker::MT_OFF); mtTracker->finishTracking(); } @@ -473,11 +475,10 @@ void KeyboardHelper::releaseFilterMtChecking(QKeyEvent *event) case Qt::Key_Alt: if (event->modifiers() == Qt::ControlModifier) { qDebug() << "enabled multi-touch mode: SYMM -> SEPA"; - set_multi_touch_enable(MultiTouchTracker::MT_SEPA); + mtTracker->setMtMode(MultiTouchTracker::MT_SEPA); } else { qDebug() << "disable multi-touch"; - set_multi_touch_enable(MultiTouchTracker::MT_OFF); mtTracker->finishTracking(); } @@ -485,11 +486,10 @@ void KeyboardHelper::releaseFilterMtChecking(QKeyEvent *event) case Qt::Key_Shift: if (event->modifiers() == Qt::ControlModifier) { qDebug() << "enabled multi-touch mode: PARA -> SEPA"; - set_multi_touch_enable(MultiTouchTracker::MT_SEPA); + mtTracker->setMtMode(MultiTouchTracker::MT_SEPA); } else { qDebug() << "disable multi-touch"; - set_multi_touch_enable(MultiTouchTracker::MT_OFF); mtTracker->finishTracking(); } @@ -497,11 +497,10 @@ void KeyboardHelper::releaseFilterMtChecking(QKeyEvent *event) case Qt::Key_Control: if (event->modifiers() == Qt::ShiftModifier) { qDebug() << "enabled multi-touch mode: PARA -> SEPA"; - set_multi_touch_enable(MultiTouchTracker::MT_SEPA); + mtTracker->setMtMode(MultiTouchTracker::MT_SEPA); } else { qDebug() << "disable multi-touch"; - set_multi_touch_enable(MultiTouchTracker::MT_OFF); mtTracker->finishTracking(); } diff --git a/tizen/src/ui/input/multitouchtracker.cpp b/tizen/src/ui/input/multitouchtracker.cpp index 67d82e4879..04594f58f5 100644 --- a/tizen/src/ui/input/multitouchtracker.cpp +++ b/tizen/src/ui/input/multitouchtracker.cpp @@ -5,7 +5,8 @@ * * Contact: * GiWoong Kim - * Sangho Park + * SeokYeon Hwang + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -91,13 +92,16 @@ MultiTouchTracker::MultiTouchTracker( this->parent = parent; this->maxTouchPoint = maxTouchPoint; this->pointRadius = 16; // TODO: - this->grabTouchPoint = NULL; + + this->mtMode = MT_OFF; + this->selectedTouchPoint = NULL; mtProcessingFunc[MT_OFF] = &MultiTouchTracker::processingOff; mtProcessingFunc[MT_SEPA] = &MultiTouchTracker::processingSepa; mtProcessingFunc[MT_PARA] = &MultiTouchTracker::processingPara; mtProcessingFunc[MT_SYMM] = &MultiTouchTracker::processingSymm; + /* touch point image */ touchPointImage.fill(Qt::transparent); QPainter painter(&touchPointImage); @@ -142,6 +146,16 @@ bool MultiTouchTracker::isTrackingReady() return virtio_touchscreen_ready(); } +void MultiTouchTracker::setMtMode(MultiTouchMode mode) +{ + mtMode = mode; +} + +int MultiTouchTracker::getMtMode() +{ + return mtMode; +} + int MultiTouchTracker::addTouchPoint(QPoint hostPos, QPoint guestPos) { const int touchCnt = touchPointList.count(); @@ -205,15 +219,15 @@ TouchPoint *MultiTouchTracker::searchTouchPoint(int targetID) return NULL; } -int MultiTouchTracker::leaveTouchPoint(int remainCnt) +int MultiTouchTracker::limitTouchCnt(int max) { - releaseGrabTouchPoint(); + releaseSelectedTouchPoint(); const int beforeCnt = touchPointList.count(); TouchPoint *point = NULL; - int diff; + int diff = 0; - while (touchPointList.count() > remainCnt) { + while (touchPointList.count() > max) { point = touchPointList.last(); if (point != NULL) { qDebug() << "ID" << point->getID() << "point releasing"; @@ -224,7 +238,6 @@ int MultiTouchTracker::leaveTouchPoint(int remainCnt) delete point; } - touchPointList.removeLast(); qt5_mt_count--; @@ -239,12 +252,12 @@ int MultiTouchTracker::leaveTouchPoint(int remainCnt) return diff; } -void MultiTouchTracker::mtProcessing(int mode, QPoint hostPos, QPoint guestPos) +void MultiTouchTracker::mtProcessing(QPoint hostPos, QPoint guestPos) { - if (mode >= MT_OFF && mode < MT_MAX) { - (this->*(mtProcessingFunc[mode]))(hostPos, guestPos); + if (mtMode >= MT_OFF && mtMode < MT_MAX) { + (this->*(mtProcessingFunc[mtMode]))(hostPos, guestPos); } else { - qWarning() << "invalid MT mode:" << mode; + qWarning() << "invalid MT mode:" << mtMode; } } @@ -261,11 +274,11 @@ void MultiTouchTracker::processingSepa(QPoint hostPos, QPoint guestPos) TouchPoint *point = NULL; const int touchCnt = touchPointList.count(); - if (grabTouchPoint != NULL) { - grabTouchPoint->updatePos(hostPos, guestPos); + if (selectedTouchPoint != NULL) { + selectedTouchPoint->updatePos(hostPos, guestPos); virtio_touchscreen_event(guestPos.x(), guestPos.y(), - grabTouchPoint->getID() - 1, 1); + selectedTouchPoint->getID() - 1, 1); return; } @@ -279,7 +292,7 @@ void MultiTouchTracker::processingSepa(QPoint hostPos, QPoint guestPos) virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1); } else if ((point = searchTouchPoint(hostPos)) != NULL) { /* grab a touch */ qDebug() << "ID" << point->getID() << "point is taken"; - grabTouchPoint = point; + selectedTouchPoint = point; } else if (touchCnt == getMaxTouchPoint()) { /* last touch */ point = touchPointList.last(); if (point != NULL) { @@ -312,9 +325,9 @@ void MultiTouchTracker::processingPara(QPoint hostPos, QPoint guestPos) TouchPoint *point = NULL; const int touchCnt = touchPointList.count(); - if (grabTouchPoint != NULL) { - const int hostPosDiffX = hostPos.x() - grabTouchPoint->getHostPos().x(); - const int hostPosDiffY = hostPos.y() - grabTouchPoint->getHostPos().y(); + if (selectedTouchPoint != NULL) { + const int hostPosDiffX = hostPos.x() - selectedTouchPoint->getHostPos().x(); + const int hostPosDiffY = hostPos.y() - selectedTouchPoint->getHostPos().y(); /* out of bounds checking */ const QRect screenRect(QPoint(0, 0), @@ -370,7 +383,7 @@ void MultiTouchTracker::processingPara(QPoint hostPos, QPoint guestPos) virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1); } else if ((point = searchTouchPoint(hostPos)) != NULL) { /* grab a touch */ qDebug() << "ID" << point->getID() << "point is taken"; - grabTouchPoint = point; + selectedTouchPoint = point; } else if (touchCnt == getMaxTouchPoint()) { /* last touch */ /* do nothing */ return; @@ -391,14 +404,14 @@ void MultiTouchTracker::processingSymm(QPoint hostPos, QPoint guestPos) TouchPoint *point = NULL; const int touchCnt = touchPointList.count(); - if (grabTouchPoint != NULL) { - const int hostPosDiffX = hostPos.x() - grabTouchPoint->getHostPos().x(); - const int hostPosDiffY = hostPos.y() - grabTouchPoint->getHostPos().y(); + if (selectedTouchPoint != NULL) { + const int hostPosDiffX = hostPos.x() - selectedTouchPoint->getHostPos().x(); + const int hostPosDiffY = hostPos.y() - selectedTouchPoint->getHostPos().y(); /* move selected point */ - grabTouchPoint->updatePos(hostPos, guestPos); + selectedTouchPoint->updatePos(hostPos, guestPos); virtio_touchscreen_event(guestPos.x(), guestPos.y(), - grabTouchPoint->getID() - 1, 1); + selectedTouchPoint->getID() - 1, 1); /* out of bounds checking */ const QRect screenRect(QPoint(0, 0), @@ -408,7 +421,7 @@ void MultiTouchTracker::processingSymm(QPoint hostPos, QPoint guestPos) for (int i = 0; i < touchPointList.count(); i++) { point = touchPointList.at(i); - if (point != NULL && point != grabTouchPoint) { + if (point != NULL && point != selectedTouchPoint) { if (screenRegion.isNull() == false && screenRegion.contains(QPoint( point->getHostPos().x() - hostPosDiffX, @@ -427,7 +440,7 @@ void MultiTouchTracker::processingSymm(QPoint hostPos, QPoint guestPos) /* move other points */ for (int i = 0; i < touchPointList.count(); i++) { point = touchPointList.at(i); - if (point != NULL && point != grabTouchPoint) { + if (point != NULL && point != selectedTouchPoint) { const QPoint hostMovedPos( point->getHostPos().x() - hostPosDiffX, point->getHostPos().y() - hostPosDiffY); @@ -454,7 +467,7 @@ void MultiTouchTracker::processingSymm(QPoint hostPos, QPoint guestPos) virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1); } else if ((point = searchTouchPoint(hostPos)) != NULL) { /* grab a touch */ qDebug() << "ID" << point->getID() << "point is taken"; - grabTouchPoint = point; + selectedTouchPoint = point; } else if (touchCnt >= MT_SYMM_MAX_POINT) { /* last touch */ /* supports up to 2 touch points */ point = touchPointList.last(); @@ -482,17 +495,19 @@ void MultiTouchTracker::processingSymm(QPoint hostPos, QPoint guestPos) } } -void MultiTouchTracker::releaseGrabTouchPoint() +void MultiTouchTracker::releaseSelectedTouchPoint() { - if (grabTouchPoint != NULL) { - qDebug() << "ID" << grabTouchPoint->getID() << "point let go"; - grabTouchPoint = NULL; + if (selectedTouchPoint != NULL) { + qDebug() << "ID" << selectedTouchPoint->getID() << "point let go"; + selectedTouchPoint = NULL; } } void MultiTouchTracker::finishTracking() { - releaseGrabTouchPoint(); + setMtMode(MT_OFF); + + releaseSelectedTouchPoint(); TouchPoint *point = NULL; for (int i = 0; i < touchPointList.count(); i++) { diff --git a/tizen/src/ui/input/multitouchtracker.h b/tizen/src/ui/input/multitouchtracker.h index bbf3d3f8e4..1f6361c435 100644 --- a/tizen/src/ui/input/multitouchtracker.h +++ b/tizen/src/ui/input/multitouchtracker.h @@ -65,14 +65,6 @@ public: QList getTouchPointList(); bool isTrackingReady(); - int addTouchPoint(QPoint hostPos, QPoint guestPos); - TouchPoint *searchTouchPoint(QPoint targetPos); - TouchPoint *searchTouchPoint(int targetID); - int leaveTouchPoint(int remainCnt); - void releaseGrabTouchPoint(); - void finishTracking(); - - void mtProcessing(int mode, QPoint, QPoint); enum MultiTouchMode { MT_OFF = 0, MT_SEPA, @@ -80,6 +72,17 @@ public: MT_SYMM, MT_MAX }; + void setMtMode(MultiTouchMode mode); + int getMtMode(); + + int addTouchPoint(QPoint hostPos, QPoint guestPos); + TouchPoint *searchTouchPoint(QPoint targetPos); + TouchPoint *searchTouchPoint(int targetID); + int limitTouchCnt(int remainCnt); + + void mtProcessing(QPoint hostPos, QPoint guestPos); + void releaseSelectedTouchPoint(); + void finishTracking(); private: void processingOff(QPoint hostPos, QPoint guestPos); @@ -91,10 +94,11 @@ private: TouchScreenHelper *parent; int maxTouchPoint; int pointRadius; + QImage touchPointImage; - TouchPoint *grabTouchPoint; + int mtMode; + TouchPoint *selectedTouchPoint; QList touchPointList; - QImage touchPointImage; }; #endif // MULTITOUCHTRACKER_H diff --git a/tizen/src/ui/input/touchscreenhelper.cpp b/tizen/src/ui/input/touchscreenhelper.cpp index e690e680d2..a0c56d7d94 100644 --- a/tizen/src/ui/input/touchscreenhelper.cpp +++ b/tizen/src/ui/input/touchscreenhelper.cpp @@ -5,7 +5,8 @@ * * Contact: * GiWoong Kim - * Sangho Park + * SeokYeon Hwang + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -55,37 +56,39 @@ MultiTouchTracker *TouchScreenHelper::getMtTracker() return mtTracker; } -void TouchScreenHelper::mousePressed(QMouseEvent *event, QPoint guestPos) +void TouchScreenHelper::touchPressed(QPoint hostPos, QPoint guestPos) { /* multi-touch processing */ - const int mtMode = get_multi_touch_enable(); - if (mtMode != MultiTouchTracker::MT_OFF) { - mtTracker->mtProcessing(mtMode, QPoint(event->x(), event->y()), guestPos); + if (mtTracker->getMtMode() != MultiTouchTracker::MT_OFF) { + mtTracker->mtProcessing(hostPos, guestPos); return; } + /* single-touch processing */ virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1); } -void TouchScreenHelper::mouseReleased(QMouseEvent *event, QPoint guestPos) +void TouchScreenHelper::touchReleased(QPoint hostPos, QPoint guestPos) { - if (get_multi_touch_enable() != MultiTouchTracker::MT_OFF) { - mtTracker->releaseGrabTouchPoint(); + /* multi-touch processing */ + if (mtTracker->getMtMode() != MultiTouchTracker::MT_OFF) { + mtTracker->releaseSelectedTouchPoint(); return; } + /* single-touch processing */ virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 0); } -void TouchScreenHelper::mouseMoved(QMouseEvent *event, QPoint guestPos) +void TouchScreenHelper::touchMoved(QPoint hostPos, QPoint guestPos) { /* multi-touch processing */ - const int mtMode = get_multi_touch_enable(); - if (mtMode != MultiTouchTracker::MT_OFF) { - mtTracker->mtProcessing(mtMode, QPoint(event->x(), event->y()), guestPos); + if (mtTracker->getMtMode() != MultiTouchTracker::MT_OFF) { + mtTracker->mtProcessing(hostPos, guestPos); return; } + /* single-touch processing */ virtio_touchscreen_event(guestPos.x(), guestPos.y(), 0, 1); } @@ -95,6 +98,5 @@ TouchScreenHelper::~TouchScreenHelper() if (mtTracker != NULL) { delete mtTracker; - mtTracker = NULL; } } diff --git a/tizen/src/ui/input/touchscreenhelper.h b/tizen/src/ui/input/touchscreenhelper.h index bd33329d8c..8b24342b3a 100644 --- a/tizen/src/ui/input/touchscreenhelper.h +++ b/tizen/src/ui/input/touchscreenhelper.h @@ -41,9 +41,9 @@ public: void *getParent(); MultiTouchTracker *getMtTracker(); - void mousePressed(QMouseEvent *event, QPoint guestPos); - void mouseReleased(QMouseEvent *event, QPoint guestPos); - void mouseMoved(QMouseEvent *event, QPoint guestPos); + void touchPressed(QPoint hostPos, QPoint guestPos); + void touchReleased(QPoint hostPos, QPoint guestPos); + void touchMoved(QPoint hostPos, QPoint guestPos); private: void *parent; -- cgit v1.2.3