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