From 91c9f6791af049b873b7c60a88aa226eaec70c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kera=CC=88nen=20Pasi?= Date: Thu, 28 Nov 2013 23:44:22 +0200 Subject: InputHandler C++ Example Documentation. Task-id: QTRD-2634 Change-Id: I486f210ed9c87079d6bc93ec10ab1f1831254d3f Reviewed-by: Miikka Heikkinen --- examples/custominput/custominputhandler.cpp | 5 +++ examples/custominput/doc/src/custominput.qdoc | 44 +++++++++++++++++++++++++-- examples/custominput/scatterdatamodifier.cpp | 9 +++++- 3 files changed, 55 insertions(+), 3 deletions(-) (limited to 'examples/custominput') diff --git a/examples/custominput/custominputhandler.cpp b/examples/custominput/custominputhandler.cpp index dad7c851..3b050fda 100644 --- a/examples/custominput/custominputhandler.cpp +++ b/examples/custominput/custominputhandler.cpp @@ -25,11 +25,15 @@ CustomInputHandler::CustomInputHandler(QObject *parent) : { } +//! [0] void CustomInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) { + Q_UNUSED(event) setInputPosition(mousePos); } +//! [0] +//! [1] void CustomInputHandler::wheelEvent(QWheelEvent *event) { // Adjust zoom level based on what zoom range we're in. @@ -47,3 +51,4 @@ void CustomInputHandler::wheelEvent(QWheelEvent *event) scene()->activeCamera()->setZoomLevel(zoomLevel); } +//! [1] diff --git a/examples/custominput/doc/src/custominput.qdoc b/examples/custominput/doc/src/custominput.qdoc index 69333d96..9bb5607f 100644 --- a/examples/custominput/doc/src/custominput.qdoc +++ b/examples/custominput/doc/src/custominput.qdoc @@ -22,9 +22,49 @@ \ingroup qtdatavisualization_examples \brief Implementing custom input handler in a widget application. - TBD... + The Custom Input example shows how to customize the 3D graph controls in a widget application using a custom graph input handler to capture and process mouse events. + The code in this example shows also how the camera is controlled by using QPropertyAnimation to animate the camera and item selection + is done on mouseover rather than clicking any mouse buttons. Also the code shows how to implement similar zoom with mouse wheel functionality as the default + input handler implements. \image custominput-example.png - TBD... + \section1 Replacing default input handling + + The default input handling mechanism is replaced by setting the active input handler of \l Q3DScatter + to \c CustomInputHandler that implements the custom behavior. + + \snippet ../examples/custominput/scatterdatamodifier.cpp 0 + + \section1 Implementing custom selection handling + + The on mouseover selection handling is implemented in the \c CustomInputHandler that captures the mouse events. + It then stores the last known coordinates to the \l QAbstract3DInputHandler::inputPosition property. + + \snippet ../examples/custominput/custominputhandler.cpp 0 + + As the selection is one shot, and is cleared each time a 3D frame is rendered, a timer is setup to retrigger selection so that the selection moves to the item + currently under the mouse cursor as the camera animates around the graph even when the mouse cursor is not moving. + + \snippet ../examples/custominput/scatterdatamodifier.cpp 1 + + \section1 Implementing custom zoom handling + + The camera has a zoom factor that represents amount of zoom in percentages. In this example the zoom range is limited + between 10% and 500%. This range is then divided to four subranges where \c angleDelta is scaled to different amount of zoom change + based on the current subrange. + + \snippet ../examples/custominput/custominputhandler.cpp 1 + + \section1 Implementing custom camera handling + + The camera is animated to constantly rotate around the graph with two animations. The rotation around the graph is done with + a simple QPropertyAnimation that just increments during 20 seconds from 0 degrees to 360 degrees and sets the \l Q3DCamera::xRotation property. + + \snippet ../examples/custominput/scatterdatamodifier.cpp 2 + + The camera movement up and down is implemented with a QSequentialAnimationGroup that varies the \l Q3DCamera::yRotation property of the camera + from 5 degrees to 45 degrees and back with in and out easing. + + \snippet ../examples/custominput/scatterdatamodifier.cpp 3 */ diff --git a/examples/custominput/scatterdatamodifier.cpp b/examples/custominput/scatterdatamodifier.cpp index fbe44f58..6d7abf4f 100644 --- a/examples/custominput/scatterdatamodifier.cpp +++ b/examples/custominput/scatterdatamodifier.cpp @@ -45,12 +45,15 @@ ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter) series->setMesh(QAbstract3DSeries::MeshCube); m_graph->addSeries(series); + //! [2] m_animationCameraX = new QPropertyAnimation(m_graph->scene()->activeCamera(), "xRotation"); m_animationCameraX->setDuration(20000); m_animationCameraX->setStartValue(QVariant::fromValue(0.0f)); m_animationCameraX->setEndValue(QVariant::fromValue(360.0f)); m_animationCameraX->setLoopCount(-1); + //! [2] + //! [3] QPropertyAnimation *upAnimation = new QPropertyAnimation(m_graph->scene()->activeCamera(), "yRotation"); upAnimation->setDuration(9000); upAnimation->setStartValue(QVariant::fromValue(5.0f)); @@ -65,20 +68,24 @@ ScatterDataModifier::ScatterDataModifier(Q3DScatter *scatter) m_animationCameraY->setLoopCount(-1); m_animationCameraY->addAnimation(upAnimation); m_animationCameraY->addAnimation(downAnimation); + //! [3] m_animationCameraX->start(); m_animationCameraY->start(); // Give ownership of the handler to the graph and make it the active handler + //! [0] m_graph->setActiveInputHandler(m_inputHandler); + //! [0] + //! [1] m_selectionTimer = new QTimer(this); m_selectionTimer->setInterval(10); m_selectionTimer->setSingleShot(false); QObject::connect(m_selectionTimer, &QTimer::timeout, this, &ScatterDataModifier::triggerSelection); - m_selectionTimer->start(); + //! [1] } ScatterDataModifier::~ScatterDataModifier() -- cgit v1.2.3