| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qabstract3dinputhandler_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | /*! |
| 9 | * \class QAbstract3DInputHandler |
| 10 | * \inmodule QtDataVisualization |
| 11 | * \brief The base class for implementations of input handlers. |
| 12 | * \since QtDataVisualization 1.0 |
| 13 | * |
| 14 | * QAbstract3DInputHandler is the base class that is subclassed by different input handling implementations |
| 15 | * that take input events and translate those to camera and light movements. Input handlers also translate |
| 16 | * raw input events to slicing and selection events in the scene. |
| 17 | */ |
| 18 | |
| 19 | /*! |
| 20 | * \enum QAbstract3DInputHandler::InputView |
| 21 | * |
| 22 | * Predefined input views for mouse and touch based input handlers. |
| 23 | * |
| 24 | * \value InputViewNone |
| 25 | * Mouse or touch not on a view. |
| 26 | * \value InputViewOnPrimary |
| 27 | * Mouse or touch input received on the primary view area. If secondary view is displayed when |
| 28 | * inputView becomes InputViewOnPrimary, secondary view is closed. |
| 29 | * \value InputViewOnSecondary |
| 30 | * Mouse or touch input received on the secondary view area. |
| 31 | */ |
| 32 | |
| 33 | /*! |
| 34 | * \qmltype AbstractInputHandler3D |
| 35 | * \inqmlmodule QtDataVisualization |
| 36 | * \since QtDataVisualization 1.0 |
| 37 | * \ingroup datavisualization_qml |
| 38 | * \nativetype QAbstract3DInputHandler |
| 39 | * \brief Base type for all QtDataVisualization input handlers. |
| 40 | * |
| 41 | * This type is uncreatable. |
| 42 | * |
| 43 | * For AbstractInputHandler3D enums, see \l{QAbstract3DInputHandler::InputView}. |
| 44 | */ |
| 45 | |
| 46 | /*! |
| 47 | * Constructs the base class. An optional \a parent parameter can be given |
| 48 | * and is then passed to QObject constructor. |
| 49 | */ |
| 50 | QAbstract3DInputHandler::QAbstract3DInputHandler(QObject *parent) : |
| 51 | QObject(parent), |
| 52 | d_ptr(new QAbstract3DInputHandlerPrivate(this)) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | /*! |
| 57 | * Destroys the base class. |
| 58 | */ |
| 59 | QAbstract3DInputHandler::~QAbstract3DInputHandler() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | // Input event listeners |
| 64 | /*! |
| 65 | * Override this to handle mouse double click events. |
| 66 | * Mouse double click event is given in the \a event. |
| 67 | */ |
| 68 | void QAbstract3DInputHandler::mouseDoubleClickEvent(QMouseEvent *event) |
| 69 | { |
| 70 | Q_UNUSED(event); |
| 71 | } |
| 72 | |
| 73 | /*! |
| 74 | * Override this to handle touch input events. |
| 75 | * Touch event is given in the \a event. |
| 76 | */ |
| 77 | void QAbstract3DInputHandler::touchEvent(QTouchEvent *event) |
| 78 | { |
| 79 | Q_UNUSED(event); |
| 80 | } |
| 81 | |
| 82 | /*! |
| 83 | * Override this to handle mouse press events. |
| 84 | * Mouse press event is given in the \a event and the mouse position in \a mousePos. |
| 85 | */ |
| 86 | void QAbstract3DInputHandler::mousePressEvent(QMouseEvent *event, const QPoint &mousePos) |
| 87 | { |
| 88 | Q_UNUSED(event); |
| 89 | Q_UNUSED(mousePos); |
| 90 | } |
| 91 | |
| 92 | /*! |
| 93 | * Override this to handle mouse release events. |
| 94 | * Mouse release event is given in the \a event and the mouse position in \a mousePos. |
| 95 | */ |
| 96 | void QAbstract3DInputHandler::mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos) |
| 97 | { |
| 98 | Q_UNUSED(event); |
| 99 | Q_UNUSED(mousePos); |
| 100 | } |
| 101 | |
| 102 | /*! |
| 103 | * Override this to handle mouse move events. |
| 104 | * Mouse move event is given in the \a event and the mouse position in \a mousePos. |
| 105 | */ |
| 106 | void QAbstract3DInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) |
| 107 | { |
| 108 | Q_UNUSED(event); |
| 109 | Q_UNUSED(mousePos); |
| 110 | } |
| 111 | |
| 112 | #if QT_CONFIG(wheelevent) |
| 113 | /*! |
| 114 | * Override this to handle wheel events. |
| 115 | * Wheel event is given in the \a event. |
| 116 | */ |
| 117 | void QAbstract3DInputHandler::wheelEvent(QWheelEvent *event) |
| 118 | { |
| 119 | Q_UNUSED(event); |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | // Property get/set |
| 124 | /*! |
| 125 | * \property QAbstract3DInputHandler::inputView |
| 126 | * |
| 127 | * \brief The current enumerated input view based on the view of the processed |
| 128 | * input events. |
| 129 | * |
| 130 | * One of the InputView enum values. |
| 131 | * |
| 132 | * When the view changes, the \c inputViewChanged signal is emitted. |
| 133 | * |
| 134 | * \sa InputView |
| 135 | */ |
| 136 | QAbstract3DInputHandler::InputView QAbstract3DInputHandler::inputView() const |
| 137 | { |
| 138 | return d_ptr->m_inputView; |
| 139 | } |
| 140 | |
| 141 | void QAbstract3DInputHandler::setInputView(InputView inputView) |
| 142 | { |
| 143 | if (inputView != d_ptr->m_inputView) { |
| 144 | d_ptr->m_inputView = inputView; |
| 145 | emit inputViewChanged(view: inputView); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /*! |
| 150 | * \property QAbstract3DInputHandler::inputPosition |
| 151 | * |
| 152 | * \brief The last input position based on the processed input events. |
| 153 | */ |
| 154 | QPoint QAbstract3DInputHandler::inputPosition() const |
| 155 | { |
| 156 | return d_ptr->m_inputPosition; |
| 157 | } |
| 158 | |
| 159 | void QAbstract3DInputHandler::setInputPosition(const QPoint &position) |
| 160 | { |
| 161 | if (position != d_ptr->m_inputPosition) { |
| 162 | d_ptr->m_inputPosition = position; |
| 163 | emit positionChanged(position); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /*! |
| 168 | * Returns the manhattan length between last two input positions. |
| 169 | */ |
| 170 | int QAbstract3DInputHandler::prevDistance() const |
| 171 | { |
| 172 | return d_ptr->m_prevDistance; |
| 173 | } |
| 174 | |
| 175 | /*! |
| 176 | * Sets the \a distance (manhattan length) between last two input positions. |
| 177 | */ |
| 178 | void QAbstract3DInputHandler::setPrevDistance(int distance) |
| 179 | { |
| 180 | d_ptr->m_prevDistance = distance; |
| 181 | } |
| 182 | |
| 183 | /*! |
| 184 | * \property QAbstract3DInputHandler::scene |
| 185 | * |
| 186 | * \brief The 3D scene this abstract input handler is controlling. |
| 187 | * |
| 188 | * One input handler can control one scene. Setting a scene to an input handler |
| 189 | * does not transfer the ownership of the scene. |
| 190 | */ |
| 191 | Q3DScene *QAbstract3DInputHandler::scene() const |
| 192 | { |
| 193 | return d_ptr->m_scene; |
| 194 | } |
| 195 | |
| 196 | void QAbstract3DInputHandler::setScene(Q3DScene *scene) |
| 197 | { |
| 198 | if (scene != d_ptr->m_scene) { |
| 199 | d_ptr->m_scene = scene; |
| 200 | emit sceneChanged(scene); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /*! |
| 205 | * Sets the previous input position to the point given by \a position. |
| 206 | */ |
| 207 | void QAbstract3DInputHandler::setPreviousInputPos(const QPoint &position) |
| 208 | { |
| 209 | d_ptr->m_previousInputPos = position; |
| 210 | } |
| 211 | |
| 212 | /*! |
| 213 | * Returns the previous input position. |
| 214 | */ |
| 215 | QPoint QAbstract3DInputHandler::previousInputPos() const |
| 216 | { |
| 217 | return d_ptr->m_previousInputPos; |
| 218 | } |
| 219 | |
| 220 | QAbstract3DInputHandlerPrivate::QAbstract3DInputHandlerPrivate(QAbstract3DInputHandler *q) : |
| 221 | q_ptr(q), |
| 222 | m_prevDistance(0), |
| 223 | m_previousInputPos(QPoint(0,0)), |
| 224 | m_inputView(QAbstract3DInputHandler::InputViewNone), |
| 225 | m_inputPosition(QPoint(0,0)), |
| 226 | m_scene(0), |
| 227 | m_isDefaultHandler(false) |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | QAbstract3DInputHandlerPrivate::~QAbstract3DInputHandlerPrivate() |
| 232 | { |
| 233 | |
| 234 | } |
| 235 | |
| 236 | QT_END_NAMESPACE |
| 237 | |