summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-10-01 08:49:58 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-10-01 09:03:58 +0300
commit0ca1f153007c1cce62f3ad5fd7b7ed1d10fa5b35 (patch)
tree7baa94a3a84cb29e970ff3f096f3c7f69b37dd43
parent822a19d3e2650c7a9326b69ff4621ccd556e16cc (diff)
Touch support fixed (draft)
Task-number: QTRD-2345 - might need some more tweaking - currently requires hard-coded compile-time change for non-android devices Change-Id: Id891178f5abd29a2c3f58ce33a661999947c7363 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r--src/datavisualization/engine/abstract3dcontroller.cpp12
-rw-r--r--src/datavisualization/engine/q3dcamera.h1
-rw-r--r--src/datavisualization/engine/q3dcamera_p.h1
-rw-r--r--src/datavisualization/engine/q3dwindow.cpp6
-rw-r--r--src/datavisualization/input/q3dinputhandler.cpp11
-rw-r--r--src/datavisualization/input/qtouch3dinputhandler.cpp124
-rw-r--r--src/datavisualization/input/qtouch3dinputhandler.h3
7 files changed, 76 insertions, 82 deletions
diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp
index 4d02fc13..61c9115a 100644
--- a/src/datavisualization/engine/abstract3dcontroller.cpp
+++ b/src/datavisualization/engine/abstract3dcontroller.cpp
@@ -67,12 +67,14 @@ Abstract3DController::Abstract3DController(QRect boundRect, QObject *parent) :
// Create initial default input handler
QAbstract3DInputHandler *inputHandler;
#if defined(Q_OS_ANDROID)
- inputHandler = new QTouch3DInputHandler();
+ inputHandler = new QTouch3DInputHandler();
#else
- inputHandler = new Q3DInputHandler();
+ inputHandler = new Q3DInputHandler();
#endif
- inputHandler->d_ptr->m_isDefaultHandler = true;
- setActiveInputHandler(inputHandler);
+ inputHandler->d_ptr->m_isDefaultHandler = true;
+ setActiveInputHandler(inputHandler);
+ connect(inputHandler, &QAbstract3DInputHandler::inputStateChanged, this,
+ &Abstract3DController::emitNeedRender);
}
Abstract3DController::~Abstract3DController()
@@ -673,7 +675,7 @@ void Abstract3DController::setCameraPosition(GLfloat horizontal, GLfloat vertica
m_verticalRotation = qBound(0.0f, vertical, 90.0f);
m_scene->activeCamera()->setZoomLevel(qBound(10, distance, 500));
m_scene->activeCamera()->setRotations(QPointF(m_horizontalRotation,
- m_verticalRotation));
+ m_verticalRotation));
//qDebug() << "camera rotation set to" << m_horizontalRotation << m_verticalRotation;
emitNeedRender();
}
diff --git a/src/datavisualization/engine/q3dcamera.h b/src/datavisualization/engine/q3dcamera.h
index 60910786..8e7a9a23 100644
--- a/src/datavisualization/engine/q3dcamera.h
+++ b/src/datavisualization/engine/q3dcamera.h
@@ -80,6 +80,7 @@ private:
friend class Scatter3DRenderer;
friend class SelectionPointer;
friend class Q3DInputHandler;
+ friend class QTouch3DInputHandler;
friend class QMac3DInputHandler;
};
diff --git a/src/datavisualization/engine/q3dcamera_p.h b/src/datavisualization/engine/q3dcamera_p.h
index cf6e9c66..8c160d8c 100644
--- a/src/datavisualization/engine/q3dcamera_p.h
+++ b/src/datavisualization/engine/q3dcamera_p.h
@@ -67,6 +67,7 @@ public:
friend class Scatter3DRenderer;
friend class SelectionPointer;
friend class Q3DInputHandler;
+ friend class QTouch3DInputHandler;
friend class QMac3DInputHandler;
};
diff --git a/src/datavisualization/engine/q3dwindow.cpp b/src/datavisualization/engine/q3dwindow.cpp
index 16202179..9b607e1d 100644
--- a/src/datavisualization/engine/q3dwindow.cpp
+++ b/src/datavisualization/engine/q3dwindow.cpp
@@ -142,6 +142,12 @@ bool Q3DWindow::event(QEvent *event)
case QEvent::UpdateRequest:
renderNow();
return true;
+ case QEvent::TouchBegin:
+ case QEvent::TouchCancel:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ d_ptr->m_visualController->touchEvent(static_cast<QTouchEvent *>(event));
+ return true;
default:
return QWindow::event(event);
}
diff --git a/src/datavisualization/input/q3dinputhandler.cpp b/src/datavisualization/input/q3dinputhandler.cpp
index 6fd5f08b..17f08cc6 100644
--- a/src/datavisualization/input/q3dinputhandler.cpp
+++ b/src/datavisualization/input/q3dinputhandler.cpp
@@ -18,7 +18,6 @@
#include "datavisualizationglobal_p.h"
#include "q3dinputhandler.h"
-#include "q3dcamera.h"
#include "q3dcamera_p.h"
#include "q3dlight.h"
@@ -80,8 +79,6 @@ void Q3DInputHandler::mousePressEvent(QMouseEvent *event, const QPoint &mousePos
setInputState(QDataVis::InputOnScene);
// update mouse positions to prevent jumping when releasing or repressing a button
setInputPosition(mousePos);
- // TODO: Get rid of these (QTRD-2307)
- emit selectionAtPoint(mousePos);
}
} else if (Qt::MiddleButton == event->button()) {
// reset rotations
@@ -120,11 +117,11 @@ void Q3DInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos)
if (QDataVis::InputRotating == inputState()) {
// Calculate mouse movement since last frame
QPointF rotations = scene()->activeCamera()->rotations();
- GLfloat xRotation = rotations.x();
- GLfloat yRotation = rotations.y();
- GLfloat mouseMoveX = GLfloat(inputPosition().x() - mousePos.x())
+ float xRotation = rotations.x();
+ float yRotation = rotations.y();
+ float mouseMoveX = float(inputPosition().x() - mousePos.x())
/ (scene()->viewport().width() / rotationSpeed);
- GLfloat mouseMoveY = GLfloat(inputPosition().y() - mousePos.y())
+ float mouseMoveY = float(inputPosition().y() - mousePos.y())
/ (scene()->viewport().height() / rotationSpeed);
// Apply to rotations
xRotation -= mouseMoveX;
diff --git a/src/datavisualization/input/qtouch3dinputhandler.cpp b/src/datavisualization/input/qtouch3dinputhandler.cpp
index de5ba843..14ba36dd 100644
--- a/src/datavisualization/input/qtouch3dinputhandler.cpp
+++ b/src/datavisualization/input/qtouch3dinputhandler.cpp
@@ -17,13 +17,17 @@
****************************************************************************/
#include "qtouch3dinputhandler_p.h"
-#include "q3dcamera.h"
+#include "q3dcamera_p.h"
#include <QTimer>
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
-const qreal maxTapAndHoldJitter = 10;
+const qreal maxTapAndHoldJitter = 20;
const int tapAndHoldTime = 250;
+const float rotationSpeed = 200.0f;
+const int zoomRateFar = 9;
+const int zoomRateMid = 5;
+const int zoomRateNear = 1;
/*!
\class QTouch3DInputHandler
@@ -51,22 +55,6 @@ QTouch3DInputHandler::~QTouch3DInputHandler()
{
}
-// Input event listeners
-/*!
- * Override this to change handling of mouse double click events.
- * Mouse double click event is given in the \a event.
- */
-void QTouch3DInputHandler::mouseDoubleClickEvent(QMouseEvent *event)
-{
- if (!scene()->isSlicingActive()) {
- setInputState(QDataVis::InputOnScene);
- // update mouse positions to prevent jumping when releasing or repressing a button
- setInputPosition(event->pos());
- // TODO: Get rid of these (QTRD-2307)
- emit selectionAtPoint(inputPosition());
- }
-}
-
/*!
* Override this to change handling of touch events.
* Touch event is given in the \a event.
@@ -83,10 +71,12 @@ void QTouch3DInputHandler::touchEvent(QTouchEvent *event)
QPointF distance = points.at(0).pos() - points.at(1).pos();
int newDistance = distance.manhattanLength();
- int zoomRate = 1;
+ int zoomRate = zoomRateFar;
int zoomLevel = scene()->activeCamera()->zoomLevel();
- if (zoomLevel > 100)
- zoomRate = 5;
+ if (zoomLevel > 250)
+ zoomRate = zoomRateNear;
+ else if (zoomLevel > 100)
+ zoomRate = zoomRateMid;
if (newDistance > prevDistance())
zoomLevel += zoomRate;
else
@@ -97,58 +87,60 @@ void QTouch3DInputHandler::touchEvent(QTouchEvent *event)
zoomLevel = 10;
scene()->activeCamera()->setZoomLevel(zoomLevel);
setPrevDistance(newDistance);
- } else if (!scene()->isSlicingActive() && points.count() == 1) {
+ } else if (points.count() == 1) {
+ QPointF pointerPos = points.at(0).pos();
if (event->type() == QEvent::TouchBegin) {
- // Tap-and-hold selection start
- d_ptr->m_startHoldPos = points.at(0).pos();
- d_ptr->m_touchHoldPos = d_ptr->m_startHoldPos;
- d_ptr->m_holdTimer->start();
+ if (scene()->isSlicingActive()) {
+ if (scene()->isPointInPrimarySubView(pointerPos.toPoint()))
+ setInputState(QDataVis::InputOnOverview);
+ else if (scene()->isPointInSecondarySubView(pointerPos.toPoint()))
+ setInputState(QDataVis::InputOnSlice);
+ else
+ setInputState(QDataVis::InputNone);
+ } else {
+ // Possible tap-and-hold selection start
+ d_ptr->m_startHoldPos = pointerPos;
+ d_ptr->m_touchHoldPos = d_ptr->m_startHoldPos;
+ d_ptr->m_holdTimer->start();
+ // Set state to rotating
+ setInputState(QDataVis::InputRotating);
+ // update pointer positions to prevent jumping when releasing or repressing a button
+ setInputPosition(pointerPos.toPoint());
+ }
} else if (event->type() == QEvent::TouchEnd) {
d_ptr->m_holdTimer->stop();
+ setInputState(QDataVis::InputNone);
+ // update pointer positions to prevent jumping when releasing or repressing a button
+ setPreviousInputPos(pointerPos.toPoint());
} else if (event->type() == QEvent::TouchUpdate) {
- d_ptr->m_touchHoldPos = points.at(0).pos();
+ if (!scene()->isSlicingActive()) {
+ d_ptr->m_touchHoldPos = pointerPos;
+ if (QDataVis::InputRotating == inputState()) {
+ // Calculate mouse movement since last frame
+ QPointF rotations = scene()->activeCamera()->rotations();
+ float xRotation = rotations.x();
+ float yRotation = rotations.y();
+ // TODO: Replace with event's previous position functionality?
+ float mouseMoveX = float(inputPosition().x() - pointerPos.x())
+ / (scene()->viewport().width() / rotationSpeed);
+ float mouseMoveY = float(inputPosition().y() - pointerPos.y())
+ / (scene()->viewport().height() / rotationSpeed);
+ // Apply to rotations
+ xRotation -= mouseMoveX;
+ yRotation -= mouseMoveY;
+ scene()->activeCamera()->setRotations(QPointF(xRotation, yRotation));
+ scene()->activeCamera()->d_ptr->updateViewMatrix(1.0f);
+
+ setPreviousInputPos(inputPosition());
+ setInputPosition(pointerPos.toPoint());
+ }
+ }
}
} else {
d_ptr->m_holdTimer->stop();
}
}
-/*!
- * Override this to change handling of mouse press events.
- * Mouse press event is given in the \a event and the mouse position in \a mousePos.
- * \warning This method is subject to change or removal.
- */
-void QTouch3DInputHandler::mousePressEvent(QMouseEvent *event, const QPoint &mousePos)
-{
- // TODO: This code needs revisiting with new Qt releases and possibly move to using touch events for these as well.
- if (Qt::LeftButton == event->button()) {
- if (scene()->isSlicingActive()) {
- if (scene()->isPointInPrimarySubView(mousePos)) {
- setInputState(QDataVis::InputOnOverview);
- //qDebug() << "Mouse pressed on overview";
- } else if (scene()->isPointInSecondarySubView(mousePos)) {
- setInputState(QDataVis::InputOnSlice);
- //qDebug() << "Mouse pressed on zoom";
- } else {
- setInputState(QDataVis::InputNone);
- }
- } else {
- setInputState(QDataVis::InputRotating);
- // update mouse positions to prevent jumping when releasing or repressing a button
- setInputPosition(mousePos);
- //qDebug() << "Mouse pressed on scene";
- }
- } else if (Qt::MiddleButton == event->button()) {
- // reset rotations
- setInputPosition(QPoint(0, 0));
- } else if (Qt::RightButton == event->button()) {
- // disable rotating when in slice view
- setInputState(QDataVis::InputOnScene);
- // update mouse positions to prevent jumping when releasing or repressing a button
- setInputPosition(mousePos);
- }
-}
-
QTouch3DInputHandlerPrivate::QTouch3DInputHandlerPrivate(QTouch3DInputHandler *q)
: q_ptr(q),
m_holdTimer(0)
@@ -156,7 +148,7 @@ QTouch3DInputHandlerPrivate::QTouch3DInputHandlerPrivate(QTouch3DInputHandler *q
m_holdTimer = new QTimer();
m_holdTimer->setSingleShot(true);
m_holdTimer->setInterval(tapAndHoldTime);
- QObject::connect(m_holdTimer, &QTimer::timeout, this, &QTouch3DInputHandlerPrivate::tapAndHold);
+ connect(m_holdTimer, &QTimer::timeout, this, &QTouch3DInputHandlerPrivate::tapAndHold);
}
QTouch3DInputHandlerPrivate::~QTouch3DInputHandlerPrivate()
@@ -169,10 +161,8 @@ void QTouch3DInputHandlerPrivate::tapAndHold()
{
QPointF distance = m_startHoldPos - m_touchHoldPos;
if (distance.manhattanLength() < maxTapAndHoldJitter) {
- q_ptr->setInputPosition(QPoint(int(m_touchHoldPos.x()), int(m_touchHoldPos.y())));
+ q_ptr->setInputPosition(m_touchHoldPos.toPoint());
q_ptr->setInputState(QDataVis::InputOnScene);
- // TODO: Get rid of these (QTRD-2307)
- emit q_ptr->selectionAtPoint(q_ptr->inputPosition());
}
}
diff --git a/src/datavisualization/input/qtouch3dinputhandler.h b/src/datavisualization/input/qtouch3dinputhandler.h
index d33807a6..1c366926 100644
--- a/src/datavisualization/input/qtouch3dinputhandler.h
+++ b/src/datavisualization/input/qtouch3dinputhandler.h
@@ -20,7 +20,6 @@
#define QTOUCH3DINPUTHANDLER_H
#include <QtDataVisualization/q3dinputhandler.h>
-#include "q3dcamera.h"
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -35,9 +34,7 @@ public:
virtual ~QTouch3DInputHandler();
// Input event listeners
- virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void touchEvent(QTouchEvent *event);
- virtual void mousePressEvent(QMouseEvent *event, const QPoint &mousePos);
private:
Q_DISABLE_COPY(QTouch3DInputHandler)