| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qmltest/quicktestevent.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 test suite of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 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 Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "quicktestevent_p.h" | - | ||||||||||||
| 41 | #include <QtTest/qtestkeyboard.h> | - | ||||||||||||
| 42 | #include <QtQml/qqml.h> | - | ||||||||||||
| 43 | #include <QtQuick/qquickitem.h> | - | ||||||||||||
| 44 | #include <QtQuick/qquickwindow.h> | - | ||||||||||||
| 45 | #include <qpa/qwindowsysteminterface.h> | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | namespace QTest { | - | ||||||||||||
| 50 | extern int Q_TESTLIB_EXPORT defaultMouseDelay(); | - | ||||||||||||
| 51 | } | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | QuickTestEvent::QuickTestEvent(QObject *parent) | - | ||||||||||||
| 54 | : QObject(parent) | - | ||||||||||||
| 55 | { | - | ||||||||||||
| 56 | } executed 32 times by 4 tests: end of blockExecuted by:
| 32 | ||||||||||||
| 57 | - | |||||||||||||
| 58 | QuickTestEvent::~QuickTestEvent() | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | int QuickTestEvent::defaultMouseDelay() const | - | ||||||||||||
| 63 | { | - | ||||||||||||
| 64 | return QTest::defaultMouseDelay(); never executed: return QTest::defaultMouseDelay(); | 0 | ||||||||||||
| 65 | } | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | bool QuickTestEvent::keyPress(int key, int modifiers, int delay) | - | ||||||||||||
| 68 | { | - | ||||||||||||
| 69 | QWindow *window = activeWindow(); | - | ||||||||||||
| 70 | if (!window)
| 0 | ||||||||||||
| 71 | return false; never executed: return false; | 0 | ||||||||||||
| 72 | QTest::keyPress(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay); | - | ||||||||||||
| 73 | return true; never executed: return true; | 0 | ||||||||||||
| 74 | } | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | bool QuickTestEvent::keyRelease(int key, int modifiers, int delay) | - | ||||||||||||
| 77 | { | - | ||||||||||||
| 78 | QWindow *window = activeWindow(); | - | ||||||||||||
| 79 | if (!window)
| 0 | ||||||||||||
| 80 | return false; never executed: return false; | 0 | ||||||||||||
| 81 | QTest::keyRelease(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay); | - | ||||||||||||
| 82 | return true; never executed: return true; | 0 | ||||||||||||
| 83 | } | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | bool QuickTestEvent::keyClick(int key, int modifiers, int delay) | - | ||||||||||||
| 86 | { | - | ||||||||||||
| 87 | QWindow *window = activeWindow(); | - | ||||||||||||
| 88 | if (!window)
| 0 | ||||||||||||
| 89 | return false; never executed: return false; | 0 | ||||||||||||
| 90 | QTest::keyClick(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay); | - | ||||||||||||
| 91 | return true; never executed: return true; | 0 | ||||||||||||
| 92 | } | - | ||||||||||||
| 93 | - | |||||||||||||
| 94 | bool QuickTestEvent::keyPressChar(const QString &character, int modifiers, int delay) | - | ||||||||||||
| 95 | { | - | ||||||||||||
| 96 | QTEST_ASSERT(character.length() == 1); never executed: qt_assert("character.length() == 1",__FILE__,96);
| 0 | ||||||||||||
| 97 | QWindow *window = activeWindow(); | - | ||||||||||||
| 98 | if (!window)
| 0 | ||||||||||||
| 99 | return false; never executed: return false; | 0 | ||||||||||||
| 100 | QTest::keyPress(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay); | - | ||||||||||||
| 101 | return true; never executed: return true; | 0 | ||||||||||||
| 102 | } | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | bool QuickTestEvent::keyReleaseChar(const QString &character, int modifiers, int delay) | - | ||||||||||||
| 105 | { | - | ||||||||||||
| 106 | QTEST_ASSERT(character.length() == 1); never executed: qt_assert("character.length() == 1",__FILE__,106);
| 0 | ||||||||||||
| 107 | QWindow *window = activeWindow(); | - | ||||||||||||
| 108 | if (!window)
| 0 | ||||||||||||
| 109 | return false; never executed: return false; | 0 | ||||||||||||
| 110 | QTest::keyRelease(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay); | - | ||||||||||||
| 111 | return true; never executed: return true; | 0 | ||||||||||||
| 112 | } | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | bool QuickTestEvent::keyClickChar(const QString &character, int modifiers, int delay) | - | ||||||||||||
| 115 | { | - | ||||||||||||
| 116 | QTEST_ASSERT(character.length() == 1); never executed: qt_assert("character.length() == 1",__FILE__,116);
| 0 | ||||||||||||
| 117 | QWindow *window = activeWindow(); | - | ||||||||||||
| 118 | if (!window)
| 0 | ||||||||||||
| 119 | return false; never executed: return false; | 0 | ||||||||||||
| 120 | QTest::keyClick(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay); | - | ||||||||||||
| 121 | return true; never executed: return true; | 0 | ||||||||||||
| 122 | } | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | // valueToKeySequence() is copied from qquickshortcut.cpp | - | ||||||||||||
| 125 | static QKeySequence valueToKeySequence(const QVariant &value) | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | if (value.type() == QVariant::Int)
| 0 | ||||||||||||
| 128 | return QKeySequence(static_cast<QKeySequence::StandardKey>(value.toInt())); never executed: return QKeySequence(static_cast<QKeySequence::StandardKey>(value.toInt())); | 0 | ||||||||||||
| 129 | return QKeySequence::fromString(value.toString()); never executed: return QKeySequence::fromString(value.toString()); | 0 | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | bool QuickTestEvent::keySequence(const QVariant &keySequence) | - | ||||||||||||
| 133 | { | - | ||||||||||||
| 134 | QWindow *window = activeWindow(); | - | ||||||||||||
| 135 | if (!window)
| 0 | ||||||||||||
| 136 | return false; never executed: return false; | 0 | ||||||||||||
| 137 | QTest::keySequence(window, valueToKeySequence(keySequence)); | - | ||||||||||||
| 138 | return true; never executed: return true; | 0 | ||||||||||||
| 139 | } | - | ||||||||||||
| 140 | - | |||||||||||||
| 141 | namespace QtQuickTest | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | enum MouseAction { MousePress, MouseRelease, MouseClick, MouseDoubleClick, MouseMove, MouseDoubleClickSequence }; | - | ||||||||||||
| 144 | - | |||||||||||||
| 145 | int lastMouseTimestamp = 0; | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | static void mouseEvent(MouseAction action, QWindow *window, | - | ||||||||||||
| 148 | QObject *item, Qt::MouseButton button, | - | ||||||||||||
| 149 | Qt::KeyboardModifiers stateKey, const QPointF &_pos, int delay=-1) | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | QTEST_ASSERT(window); never executed: qt_assert("window",__FILE__,151);
| 0 | ||||||||||||
| 152 | QTEST_ASSERT(item); never executed: qt_assert("item",__FILE__,152);
| 0 | ||||||||||||
| 153 | - | |||||||||||||
| 154 | if (delay == -1 || delay < QTest::defaultMouseDelay())
| 0 | ||||||||||||
| 155 | delay = QTest::defaultMouseDelay(); never executed: delay = QTest::defaultMouseDelay(); | 0 | ||||||||||||
| 156 | if (delay > 0) {
| 0 | ||||||||||||
| 157 | QTest::qWait(delay); | - | ||||||||||||
| 158 | lastMouseTimestamp += delay; | - | ||||||||||||
| 159 | } never executed: end of block | 0 | ||||||||||||
| 160 | - | |||||||||||||
| 161 | if (action == MouseClick) {
| 0 | ||||||||||||
| 162 | mouseEvent(MousePress, window, item, button, stateKey, _pos); | - | ||||||||||||
| 163 | mouseEvent(MouseRelease, window, item, button, stateKey, _pos); | - | ||||||||||||
| 164 | return; never executed: return; | 0 | ||||||||||||
| 165 | } | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | if (action == MouseDoubleClickSequence) {
| 0 | ||||||||||||
| 168 | mouseEvent(MousePress, window, item, button, stateKey, _pos); | - | ||||||||||||
| 169 | mouseEvent(MouseRelease, window, item, button, stateKey, _pos); | - | ||||||||||||
| 170 | mouseEvent(MousePress, window, item, button, stateKey, _pos); | - | ||||||||||||
| 171 | mouseEvent(MouseDoubleClick, window, item, button, stateKey, _pos); | - | ||||||||||||
| 172 | mouseEvent(MouseRelease, window, item, button, stateKey, _pos); | - | ||||||||||||
| 173 | return; never executed: return; | 0 | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | QPoint pos = _pos.toPoint(); | - | ||||||||||||
| 177 | QQuickItem *sgitem = qobject_cast<QQuickItem *>(item); | - | ||||||||||||
| 178 | if (sgitem)
| 0 | ||||||||||||
| 179 | pos = sgitem->mapToScene(_pos).toPoint(); never executed: pos = sgitem->mapToScene(_pos).toPoint(); | 0 | ||||||||||||
| 180 | QTEST_ASSERT(button == Qt::NoButton || button & Qt::MouseButtonMask); never executed: qt_assert("button == Qt::NoButton || button & Qt::MouseButtonMask",__FILE__,180);
| 0 | ||||||||||||
| 181 | QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask); never executed: qt_assert("stateKey == 0 || stateKey & Qt::KeyboardModifierMask",__FILE__,181);
| 0 | ||||||||||||
| 182 | - | |||||||||||||
| 183 | stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask); | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey); | - | ||||||||||||
| 186 | switch (action) | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | case MousePress: never executed: case MousePress: | 0 | ||||||||||||
| 189 | me = QMouseEvent(QEvent::MouseButtonPress, pos, window->mapToGlobal(pos), button, button, stateKey); | - | ||||||||||||
| 190 | me.setTimestamp(++lastMouseTimestamp); | - | ||||||||||||
| 191 | break; never executed: break; | 0 | ||||||||||||
| 192 | case MouseRelease: never executed: case MouseRelease: | 0 | ||||||||||||
| 193 | me = QMouseEvent(QEvent::MouseButtonRelease, pos, window->mapToGlobal(pos), button, nullptr, stateKey); | - | ||||||||||||
| 194 | me.setTimestamp(++lastMouseTimestamp); | - | ||||||||||||
| 195 | lastMouseTimestamp += 500; // avoid double clicks being generated | - | ||||||||||||
| 196 | break; never executed: break; | 0 | ||||||||||||
| 197 | case MouseDoubleClick: never executed: case MouseDoubleClick: | 0 | ||||||||||||
| 198 | me = QMouseEvent(QEvent::MouseButtonDblClick, pos, window->mapToGlobal(pos), button, button, stateKey); | - | ||||||||||||
| 199 | me.setTimestamp(++lastMouseTimestamp); | - | ||||||||||||
| 200 | break; never executed: break; | 0 | ||||||||||||
| 201 | case MouseMove: never executed: case MouseMove: | 0 | ||||||||||||
| 202 | // with move event the button is NoButton, but 'buttons' holds the currently pressed buttons | - | ||||||||||||
| 203 | me = QMouseEvent(QEvent::MouseMove, pos, window->mapToGlobal(pos), Qt::NoButton, button, stateKey); | - | ||||||||||||
| 204 | me.setTimestamp(++lastMouseTimestamp); | - | ||||||||||||
| 205 | break; never executed: break; | 0 | ||||||||||||
| 206 | default: never executed: default: | 0 | ||||||||||||
| 207 | QTEST_ASSERT(false); never executed: qt_assert("false",__FILE__,207);
| 0 | ||||||||||||
| 208 | } never executed: end of block | 0 | ||||||||||||
| 209 | QSpontaneKeyEvent::setSpontaneous(&me); | - | ||||||||||||
| 210 | if (!qApp->notify(window, &me)) {
| 0 | ||||||||||||
| 211 | static const char *mouseActionNames[] = | - | ||||||||||||
| 212 | { "MousePress", "MouseRelease", "MouseClick", "MouseDoubleClick", "MouseMove", "MouseDoubleClickSequence" }; | - | ||||||||||||
| 213 | QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving window"); | - | ||||||||||||
| 214 | QWARN(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toLatin1().data()); | - | ||||||||||||
| 215 | } never executed: end of block | 0 | ||||||||||||
| 216 | } never executed: end of block | 0 | ||||||||||||
| 217 | - | |||||||||||||
| 218 | #if QT_CONFIG(wheelevent) | - | ||||||||||||
| 219 | static void mouseWheel(QWindow* window, QObject* item, Qt::MouseButtons buttons, | - | ||||||||||||
| 220 | Qt::KeyboardModifiers stateKey, | - | ||||||||||||
| 221 | QPointF _pos, int xDelta, int yDelta, int delay = -1) | - | ||||||||||||
| 222 | { | - | ||||||||||||
| 223 | QTEST_ASSERT(window); never executed: qt_assert("window",__FILE__,223);
| 0 | ||||||||||||
| 224 | QTEST_ASSERT(item); never executed: qt_assert("item",__FILE__,224);
| 0 | ||||||||||||
| 225 | if (delay == -1 || delay < QTest::defaultMouseDelay())
| 0 | ||||||||||||
| 226 | delay = QTest::defaultMouseDelay(); never executed: delay = QTest::defaultMouseDelay(); | 0 | ||||||||||||
| 227 | if (delay > 0)
| 0 | ||||||||||||
| 228 | QTest::qWait(delay); never executed: QTest::qWait(delay); | 0 | ||||||||||||
| 229 | - | |||||||||||||
| 230 | QPoint pos; | - | ||||||||||||
| 231 | QQuickItem *sgitem = qobject_cast<QQuickItem *>(item); | - | ||||||||||||
| 232 | if (sgitem)
| 0 | ||||||||||||
| 233 | pos = sgitem->mapToScene(_pos).toPoint(); never executed: pos = sgitem->mapToScene(_pos).toPoint(); | 0 | ||||||||||||
| 234 | - | |||||||||||||
| 235 | QTEST_ASSERT(buttons == Qt::NoButton || buttons & Qt::MouseButtonMask); never executed: qt_assert("buttons == Qt::NoButton || buttons & Qt::MouseButtonMask",__FILE__,235);
| 0 | ||||||||||||
| 236 | QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask); never executed: qt_assert("stateKey == 0 || stateKey & Qt::KeyboardModifierMask",__FILE__,236);
| 0 | ||||||||||||
| 237 | - | |||||||||||||
| 238 | stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask); | - | ||||||||||||
| 239 | QWheelEvent we(pos, window->mapToGlobal(pos), QPoint(0, 0), QPoint(xDelta, yDelta), 0, Qt::Vertical, buttons, stateKey); | - | ||||||||||||
| 240 | - | |||||||||||||
| 241 | QSpontaneKeyEvent::setSpontaneous(&we); // hmmmm | - | ||||||||||||
| 242 | if (!qApp->notify(window, &we))
| 0 | ||||||||||||
| 243 | QTest::qWarn("Wheel event not accepted by receiving window"); never executed: QTest::qWarn("Wheel event not accepted by receiving window"); | 0 | ||||||||||||
| 244 | } never executed: end of block | 0 | ||||||||||||
| 245 | #endif | - | ||||||||||||
| 246 | }; | - | ||||||||||||
| 247 | - | |||||||||||||
| 248 | bool QuickTestEvent::mousePress | - | ||||||||||||
| 249 | (QObject *item, qreal x, qreal y, int button, | - | ||||||||||||
| 250 | int modifiers, int delay) | - | ||||||||||||
| 251 | { | - | ||||||||||||
| 252 | QWindow *view = eventWindow(item); | - | ||||||||||||
| 253 | if (!view)
| 0 | ||||||||||||
| 254 | return false; never executed: return false; | 0 | ||||||||||||
| 255 | QtQuickTest::mouseEvent(QtQuickTest::MousePress, view, item, | - | ||||||||||||
| 256 | Qt::MouseButton(button), | - | ||||||||||||
| 257 | Qt::KeyboardModifiers(modifiers), | - | ||||||||||||
| 258 | QPointF(x, y), delay); | - | ||||||||||||
| 259 | return true; never executed: return true; | 0 | ||||||||||||
| 260 | } | - | ||||||||||||
| 261 | - | |||||||||||||
| 262 | #if QT_CONFIG(wheelevent) | - | ||||||||||||
| 263 | bool QuickTestEvent::mouseWheel( | - | ||||||||||||
| 264 | QObject *item, qreal x, qreal y, int buttons, | - | ||||||||||||
| 265 | int modifiers, int xDelta, int yDelta, int delay) | - | ||||||||||||
| 266 | { | - | ||||||||||||
| 267 | QWindow *view = eventWindow(item); | - | ||||||||||||
| 268 | if (!view)
| 0 | ||||||||||||
| 269 | return false; never executed: return false; | 0 | ||||||||||||
| 270 | QtQuickTest::mouseWheel(view, item, Qt::MouseButtons(buttons), | - | ||||||||||||
| 271 | Qt::KeyboardModifiers(modifiers), | - | ||||||||||||
| 272 | QPointF(x, y), xDelta, yDelta, delay); | - | ||||||||||||
| 273 | return true; never executed: return true; | 0 | ||||||||||||
| 274 | } | - | ||||||||||||
| 275 | #endif | - | ||||||||||||
| 276 | - | |||||||||||||
| 277 | bool QuickTestEvent::mouseRelease | - | ||||||||||||
| 278 | (QObject *item, qreal x, qreal y, int button, | - | ||||||||||||
| 279 | int modifiers, int delay) | - | ||||||||||||
| 280 | { | - | ||||||||||||
| 281 | QWindow *view = eventWindow(item); | - | ||||||||||||
| 282 | if (!view)
| 0 | ||||||||||||
| 283 | return false; never executed: return false; | 0 | ||||||||||||
| 284 | QtQuickTest::mouseEvent(QtQuickTest::MouseRelease, view, item, | - | ||||||||||||
| 285 | Qt::MouseButton(button), | - | ||||||||||||
| 286 | Qt::KeyboardModifiers(modifiers), | - | ||||||||||||
| 287 | QPointF(x, y), delay); | - | ||||||||||||
| 288 | return true; never executed: return true; | 0 | ||||||||||||
| 289 | } | - | ||||||||||||
| 290 | - | |||||||||||||
| 291 | bool QuickTestEvent::mouseClick | - | ||||||||||||
| 292 | (QObject *item, qreal x, qreal y, int button, | - | ||||||||||||
| 293 | int modifiers, int delay) | - | ||||||||||||
| 294 | { | - | ||||||||||||
| 295 | QWindow *view = eventWindow(item); | - | ||||||||||||
| 296 | if (!view)
| 0 | ||||||||||||
| 297 | return false; never executed: return false; | 0 | ||||||||||||
| 298 | QtQuickTest::mouseEvent(QtQuickTest::MouseClick, view, item, | - | ||||||||||||
| 299 | Qt::MouseButton(button), | - | ||||||||||||
| 300 | Qt::KeyboardModifiers(modifiers), | - | ||||||||||||
| 301 | QPointF(x, y), delay); | - | ||||||||||||
| 302 | return true; never executed: return true; | 0 | ||||||||||||
| 303 | } | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | bool QuickTestEvent::mouseDoubleClick | - | ||||||||||||
| 306 | (QObject *item, qreal x, qreal y, int button, | - | ||||||||||||
| 307 | int modifiers, int delay) | - | ||||||||||||
| 308 | { | - | ||||||||||||
| 309 | QWindow *view = eventWindow(item); | - | ||||||||||||
| 310 | if (!view)
| 0 | ||||||||||||
| 311 | return false; never executed: return false; | 0 | ||||||||||||
| 312 | QtQuickTest::mouseEvent(QtQuickTest::MouseDoubleClick, view, item, | - | ||||||||||||
| 313 | Qt::MouseButton(button), | - | ||||||||||||
| 314 | Qt::KeyboardModifiers(modifiers), | - | ||||||||||||
| 315 | QPointF(x, y), delay); | - | ||||||||||||
| 316 | return true; never executed: return true; | 0 | ||||||||||||
| 317 | } | - | ||||||||||||
| 318 | - | |||||||||||||
| 319 | bool QuickTestEvent::mouseDoubleClickSequence | - | ||||||||||||
| 320 | (QObject *item, qreal x, qreal y, int button, | - | ||||||||||||
| 321 | int modifiers, int delay) | - | ||||||||||||
| 322 | { | - | ||||||||||||
| 323 | QWindow *view = eventWindow(item); | - | ||||||||||||
| 324 | if (!view)
| 0 | ||||||||||||
| 325 | return false; never executed: return false; | 0 | ||||||||||||
| 326 | QtQuickTest::mouseEvent(QtQuickTest::MouseDoubleClickSequence, view, item, | - | ||||||||||||
| 327 | Qt::MouseButton(button), | - | ||||||||||||
| 328 | Qt::KeyboardModifiers(modifiers), | - | ||||||||||||
| 329 | QPointF(x, y), delay); | - | ||||||||||||
| 330 | return true; never executed: return true; | 0 | ||||||||||||
| 331 | } | - | ||||||||||||
| 332 | - | |||||||||||||
| 333 | bool QuickTestEvent::mouseMove | - | ||||||||||||
| 334 | (QObject *item, qreal x, qreal y, int delay, int buttons) | - | ||||||||||||
| 335 | { | - | ||||||||||||
| 336 | QWindow *view = eventWindow(item); | - | ||||||||||||
| 337 | if (!view)
| 0 | ||||||||||||
| 338 | return false; never executed: return false; | 0 | ||||||||||||
| 339 | QtQuickTest::mouseEvent(QtQuickTest::MouseMove, view, item, | - | ||||||||||||
| 340 | Qt::MouseButton(buttons), Qt::NoModifier, | - | ||||||||||||
| 341 | QPointF(x, y), delay); | - | ||||||||||||
| 342 | return true; never executed: return true; | 0 | ||||||||||||
| 343 | } | - | ||||||||||||
| 344 | - | |||||||||||||
| 345 | QWindow *QuickTestEvent::eventWindow(QObject *item) | - | ||||||||||||
| 346 | { | - | ||||||||||||
| 347 | QWindow * window = qobject_cast<QWindow *>(item); | - | ||||||||||||
| 348 | if (window)
| 0 | ||||||||||||
| 349 | return window; never executed: return window; | 0 | ||||||||||||
| 350 | - | |||||||||||||
| 351 | QQuickItem *quickItem = qobject_cast<QQuickItem *>(item); | - | ||||||||||||
| 352 | if (quickItem)
| 0 | ||||||||||||
| 353 | return quickItem->window(); never executed: return quickItem->window(); | 0 | ||||||||||||
| 354 | - | |||||||||||||
| 355 | QQuickItem *testParentitem = qobject_cast<QQuickItem *>(parent()); | - | ||||||||||||
| 356 | if (testParentitem)
| 0 | ||||||||||||
| 357 | return testParentitem->window(); never executed: return testParentitem->window(); | 0 | ||||||||||||
| 358 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||
| 359 | } | - | ||||||||||||
| 360 | - | |||||||||||||
| 361 | QWindow *QuickTestEvent::activeWindow() | - | ||||||||||||
| 362 | { | - | ||||||||||||
| 363 | if (QWindow *window = QGuiApplication::focusWindow())
| 0 | ||||||||||||
| 364 | return window; never executed: return window; | 0 | ||||||||||||
| 365 | return eventWindow(); never executed: return eventWindow(); | 0 | ||||||||||||
| 366 | } | - | ||||||||||||
| 367 | - | |||||||||||||
| 368 | QQuickTouchEventSequence::QQuickTouchEventSequence(QuickTestEvent *testEvent, QObject *item) | - | ||||||||||||
| 369 | : QObject(testEvent) | - | ||||||||||||
| 370 | , m_sequence(QTest::touchEvent(testEvent->eventWindow(item), testEvent->touchDevice())) | - | ||||||||||||
| 371 | , m_testEvent(testEvent) | - | ||||||||||||
| 372 | { | - | ||||||||||||
| 373 | } never executed: end of block | 0 | ||||||||||||
| 374 | - | |||||||||||||
| 375 | QObject *QQuickTouchEventSequence::press(int touchId, QObject *item, qreal x, qreal y) | - | ||||||||||||
| 376 | { | - | ||||||||||||
| 377 | QWindow *view = m_testEvent->eventWindow(item); | - | ||||||||||||
| 378 | if (view) {
| 0 | ||||||||||||
| 379 | QPointF pos(x, y); | - | ||||||||||||
| 380 | QQuickItem *quickItem = qobject_cast<QQuickItem *>(item); | - | ||||||||||||
| 381 | if (quickItem) {
| 0 | ||||||||||||
| 382 | pos = quickItem->mapToScene(pos); | - | ||||||||||||
| 383 | } never executed: end of block | 0 | ||||||||||||
| 384 | m_sequence.press(touchId, pos.toPoint(), view); | - | ||||||||||||
| 385 | } never executed: end of block | 0 | ||||||||||||
| 386 | return this; never executed: return this; | 0 | ||||||||||||
| 387 | } | - | ||||||||||||
| 388 | - | |||||||||||||
| 389 | QObject *QQuickTouchEventSequence::move(int touchId, QObject *item, qreal x, qreal y) | - | ||||||||||||
| 390 | { | - | ||||||||||||
| 391 | QWindow *view = m_testEvent->eventWindow(item); | - | ||||||||||||
| 392 | if (view) {
| 0 | ||||||||||||
| 393 | QPointF pos(x, y); | - | ||||||||||||
| 394 | QQuickItem *quickItem = qobject_cast<QQuickItem *>(item); | - | ||||||||||||
| 395 | if (quickItem) {
| 0 | ||||||||||||
| 396 | pos = quickItem->mapToScene(pos); | - | ||||||||||||
| 397 | } never executed: end of block | 0 | ||||||||||||
| 398 | m_sequence.move(touchId, pos.toPoint(), view); | - | ||||||||||||
| 399 | } never executed: end of block | 0 | ||||||||||||
| 400 | return this; never executed: return this; | 0 | ||||||||||||
| 401 | } | - | ||||||||||||
| 402 | - | |||||||||||||
| 403 | QObject *QQuickTouchEventSequence::release(int touchId, QObject *item, qreal x, qreal y) | - | ||||||||||||
| 404 | { | - | ||||||||||||
| 405 | QWindow *view = m_testEvent->eventWindow(item); | - | ||||||||||||
| 406 | if (view) {
| 0 | ||||||||||||
| 407 | QPointF pos(x, y); | - | ||||||||||||
| 408 | QQuickItem *quickItem = qobject_cast<QQuickItem *>(item); | - | ||||||||||||
| 409 | if (quickItem) {
| 0 | ||||||||||||
| 410 | pos = quickItem->mapToScene(pos); | - | ||||||||||||
| 411 | } never executed: end of block | 0 | ||||||||||||
| 412 | m_sequence.release(touchId, pos.toPoint(), view); | - | ||||||||||||
| 413 | } never executed: end of block | 0 | ||||||||||||
| 414 | return this; never executed: return this; | 0 | ||||||||||||
| 415 | } | - | ||||||||||||
| 416 | - | |||||||||||||
| 417 | QObject *QQuickTouchEventSequence::stationary(int touchId) | - | ||||||||||||
| 418 | { | - | ||||||||||||
| 419 | m_sequence.stationary(touchId); | - | ||||||||||||
| 420 | return this; never executed: return this; | 0 | ||||||||||||
| 421 | } | - | ||||||||||||
| 422 | - | |||||||||||||
| 423 | QObject *QQuickTouchEventSequence::commit() | - | ||||||||||||
| 424 | { | - | ||||||||||||
| 425 | m_sequence.commit(); | - | ||||||||||||
| 426 | return this; never executed: return this; | 0 | ||||||||||||
| 427 | } | - | ||||||||||||
| 428 | - | |||||||||||||
| 429 | /*! | - | ||||||||||||
| 430 | Return a simulated touchscreen, creating one if necessary | - | ||||||||||||
| 431 | - | |||||||||||||
| 432 | \internal | - | ||||||||||||
| 433 | */ | - | ||||||||||||
| 434 | - | |||||||||||||
| 435 | QTouchDevice *QuickTestEvent::touchDevice() | - | ||||||||||||
| 436 | { | - | ||||||||||||
| 437 | static QTouchDevice *device(nullptr); | - | ||||||||||||
| 438 | - | |||||||||||||
| 439 | if (!device) {
| 0 | ||||||||||||
| 440 | device = new QTouchDevice; | - | ||||||||||||
| 441 | device->setType(QTouchDevice::TouchScreen); | - | ||||||||||||
| 442 | QWindowSystemInterface::registerTouchDevice(device); | - | ||||||||||||
| 443 | } never executed: end of block | 0 | ||||||||||||
| 444 | return device; never executed: return device; | 0 | ||||||||||||
| 445 | } | - | ||||||||||||
| 446 | - | |||||||||||||
| 447 | /*! | - | ||||||||||||
| 448 | Creates a new QQuickTouchEventSequence. | - | ||||||||||||
| 449 | - | |||||||||||||
| 450 | If valid, \a item determines the QWindow that touch events are sent to. | - | ||||||||||||
| 451 | Test code should use touchEvent() from the QML TestCase type. | - | ||||||||||||
| 452 | - | |||||||||||||
| 453 | \internal | - | ||||||||||||
| 454 | */ | - | ||||||||||||
| 455 | QQuickTouchEventSequence *QuickTestEvent::touchEvent(QObject *item) | - | ||||||||||||
| 456 | { | - | ||||||||||||
| 457 | return new QQuickTouchEventSequence(this, item); never executed: return new QQuickTouchEventSequence(this, item); | 0 | ||||||||||||
| 458 | } | - | ||||||||||||
| 459 | - | |||||||||||||
| 460 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |