summaryrefslogtreecommitdiffstats
path: root/examples/datavisualization/qmlcustominput/doc/src/qmlcustominput.qdoc
blob: 5c29939ffe5b3c1f26d643cb352eb4895baa3e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Data Visualization module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example qmlcustominput
    \title Qt Quick 2 Custom Input Example
    \ingroup qtdatavisualization_examples
    \brief Customizing input in a QML application.

    The Qt Quick 2 Custom Input example shows how to customize the 3D graph controls from Qt Quick 2 using the MouseArea to capture and process mouse events in QML.
    Custom input handling code in this example shows how the camera is now controlled by using NumberAnimation 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 qmlcustominput-example.png

    \include examples-run.qdocinc

    \section1 Removing Default Input Handling

    The default input handling mechanism is disabled by setting the inputHandler property to null.

    \snippet qmlcustominput/qml/qmlcustominput/main.qml 0
    \dots 0
    \snippet qmlcustominput/qml/qmlcustominput/main.qml 1
    \dots 0

    \section1 Implementing Custom Selection Handling

    The on mouseover selection handling is implemented using standard MouseArea to capture the mouse events.
    The mouse area is configured to capture hover events and has two custom properties for \c mouseX and \c mouseY
    to store the last known mouse coordinates.

    \snippet qmlcustominput/qml/qmlcustominput/main.qml 2

    Whenever a pointer movement related signal is received the code updates the \c mouseX and \c mouseY properties.

    \snippet qmlcustominput/qml/qmlcustominput/main.qml 3

    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 qmlcustominput/qml/qmlcustominput/main.qml 4

    \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 angleDelta is scaled to different amount of zoom change
    based on the current subrange.

    \dots
    \snippet qmlcustominput/qml/qmlcustominput/main.qml 5
    \dots

    \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 NumberAnimation that just increments during 20 seconds from 0 degrees to 360 degrees and sets the \l Q3DCamera::xRotation property.

    \snippet qmlcustominput/qml/qmlcustominput/main.qml 6

    The camera movement up and down is implemented with a SequentialAnimation that varies the \l Q3DCamera::yRotation property of the camera
    from 5 degrees to 45 degrees and back with in and out easing.

    \snippet qmlcustominput/qml/qmlcustominput/main.qml 7
*/