| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickmousearea.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 QtQuick module 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 "qquickmousearea_p.h" | - | ||||||||||||||||||||||||
| 41 | #include "qquickmousearea_p_p.h" | - | ||||||||||||||||||||||||
| 42 | #include "qquickwindow.h" | - | ||||||||||||||||||||||||
| 43 | #include "qquickdrag_p.h" | - | ||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | #include <private/qqmldata_p.h> | - | ||||||||||||||||||||||||
| 46 | #include <private/qsgadaptationlayer_p.h> | - | ||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||
| 48 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||||||||||||||
| 49 | #include <QtGui/qevent.h> | - | ||||||||||||||||||||||||
| 50 | #include <QtGui/qstylehints.h> | - | ||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | #include <float.h> | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING) never executed: status = Yes;never executed: end of blockexecuted 46 times by 23 tests: end of blockExecuted by:
executed 2012 times by 23 tests: return status == Yes;Executed by:
| 0-2012 | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | Q_DECLARE_LOGGING_CATEGORY(DBG_HOVER_TRACE) | - | ||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | QQuickMouseAreaPrivate::QQuickMouseAreaPrivate() | - | ||||||||||||||||||||||||
| 61 | : enabled(true), scrollGestureEnabled(true), hovered(false), longPress(false), | - | ||||||||||||||||||||||||
| 62 | moved(false), stealMouse(false), doubleClick(false), preventStealing(false), | - | ||||||||||||||||||||||||
| 63 | propagateComposedEvents(false), overThreshold(false), pressed(nullptr), | - | ||||||||||||||||||||||||
| 64 | pressAndHoldInterval(-1) | - | ||||||||||||||||||||||||
| 65 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 66 | , drag(nullptr) | - | ||||||||||||||||||||||||
| 67 | #endif | - | ||||||||||||||||||||||||
| 68 | #if QT_CONFIG(cursor) | - | ||||||||||||||||||||||||
| 69 | , cursor(nullptr) | - | ||||||||||||||||||||||||
| 70 | #endif | - | ||||||||||||||||||||||||
| 71 | { | - | ||||||||||||||||||||||||
| 72 | } executed 2012 times by 23 tests: end of blockExecuted by:
| 2012 | ||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | QQuickMouseAreaPrivate::~QQuickMouseAreaPrivate() | - | ||||||||||||||||||||||||
| 75 | { | - | ||||||||||||||||||||||||
| 76 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 77 | delete drag; | - | ||||||||||||||||||||||||
| 78 | #endif | - | ||||||||||||||||||||||||
| 79 | #if QT_CONFIG(cursor) | - | ||||||||||||||||||||||||
| 80 | delete cursor; | - | ||||||||||||||||||||||||
| 81 | #endif | - | ||||||||||||||||||||||||
| 82 | } executed 1970 times by 21 tests: end of blockExecuted by:
| 1970 | ||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||
| 84 | void QQuickMouseAreaPrivate::init() | - | ||||||||||||||||||||||||
| 85 | { | - | ||||||||||||||||||||||||
| 86 | Q_Q(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 87 | q->setAcceptedMouseButtons(Qt::LeftButton); | - | ||||||||||||||||||||||||
| 88 | q->setAcceptTouchEvents(false); // rely on mouse events synthesized from touch | - | ||||||||||||||||||||||||
| 89 | q->setFiltersChildMouseEvents(true); | - | ||||||||||||||||||||||||
| 90 | if (qmlVisualTouchDebugging()) {
| 0-2012 | ||||||||||||||||||||||||
| 91 | q->setFlag(QQuickItem::ItemHasContents); | - | ||||||||||||||||||||||||
| 92 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 93 | } executed 2012 times by 23 tests: end of blockExecuted by:
| 2012 | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | void QQuickMouseAreaPrivate::saveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 96 | { | - | ||||||||||||||||||||||||
| 97 | lastPos = event->localPos(); | - | ||||||||||||||||||||||||
| 98 | lastScenePos = event->windowPos(); | - | ||||||||||||||||||||||||
| 99 | lastButton = event->button(); | - | ||||||||||||||||||||||||
| 100 | lastButtons = event->buttons(); | - | ||||||||||||||||||||||||
| 101 | lastModifiers = event->modifiers(); | - | ||||||||||||||||||||||||
| 102 | lastFlags = event->flags(); | - | ||||||||||||||||||||||||
| 103 | } executed 953 times by 6 tests: end of blockExecuted by:
| 953 | ||||||||||||||||||||||||
| 104 | - | |||||||||||||||||||||||||
| 105 | bool QQuickMouseAreaPrivate::isPressAndHoldConnected() | - | ||||||||||||||||||||||||
| 106 | { | - | ||||||||||||||||||||||||
| 107 | Q_Q(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 108 | IS_SIGNAL_CONNECTED(q, QQuickMouseArea, pressAndHold, (QQuickMouseEvent *)); executed 26 times by 1 test: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx);Executed by:
| 26 | ||||||||||||||||||||||||
| 109 | } | - | ||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | bool QQuickMouseAreaPrivate::isDoubleClickConnected() | - | ||||||||||||||||||||||||
| 112 | { | - | ||||||||||||||||||||||||
| 113 | Q_Q(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 114 | IS_SIGNAL_CONNECTED(q, QQuickMouseArea, doubleClicked, (QQuickMouseEvent *)); executed 80 times by 2 tests: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx);Executed by:
| 80 | ||||||||||||||||||||||||
| 115 | } | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | bool QQuickMouseAreaPrivate::isClickConnected() | - | ||||||||||||||||||||||||
| 118 | { | - | ||||||||||||||||||||||||
| 119 | Q_Q(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 120 | IS_SIGNAL_CONNECTED(q, QQuickMouseArea, clicked, (QQuickMouseEvent *)); executed 138 times by 4 tests: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx);Executed by:
| 138 | ||||||||||||||||||||||||
| 121 | } | - | ||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | bool QQuickMouseAreaPrivate::isWheelConnected() | - | ||||||||||||||||||||||||
| 124 | { | - | ||||||||||||||||||||||||
| 125 | Q_Q(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 126 | IS_SIGNAL_CONNECTED(q, QQuickMouseArea, wheel, (QQuickWheelEvent *)); executed 2 times by 1 test: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx);Executed by:
| 2 | ||||||||||||||||||||||||
| 127 | } | - | ||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | void QQuickMouseAreaPrivate::propagate(QQuickMouseEvent* event, PropagateType t) | - | ||||||||||||||||||||||||
| 130 | { | - | ||||||||||||||||||||||||
| 131 | Q_Q(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 132 | if (!window || !propagateComposedEvents)
| 2-106 | ||||||||||||||||||||||||
| 133 | return; executed 88 times by 3 tests: return;Executed by:
| 88 | ||||||||||||||||||||||||
| 134 | QPointF scenePos = q->mapToScene(QPointF(event->x(), event->y())); | - | ||||||||||||||||||||||||
| 135 | propagateHelper(event, window->contentItem(), scenePos, t); | - | ||||||||||||||||||||||||
| 136 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||
| 138 | bool QQuickMouseAreaPrivate::propagateHelper(QQuickMouseEvent *ev, QQuickItem *item,const QPointF &sp, PropagateType sig) | - | ||||||||||||||||||||||||
| 139 | { | - | ||||||||||||||||||||||||
| 140 | //Based off of QQuickWindow::deliverInitialMousePressEvent | - | ||||||||||||||||||||||||
| 141 | //But specific to MouseArea, so doesn't belong in window | - | ||||||||||||||||||||||||
| 142 | Q_Q(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 143 | QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); | - | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) {
| 0-92 | ||||||||||||||||||||||||
| 146 | QPointF p = item->mapFromScene(sp); | - | ||||||||||||||||||||||||
| 147 | if (!item->contains(p))
| 0 | ||||||||||||||||||||||||
| 148 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 149 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||
| 151 | QList<QQuickItem *> children = itemPrivate->paintOrderChildItems(); | - | ||||||||||||||||||||||||
| 152 | for (int ii = children.count() - 1; ii >= 0; --ii) {
| 52-72 | ||||||||||||||||||||||||
| 153 | QQuickItem *child = children.at(ii); | - | ||||||||||||||||||||||||
| 154 | if (!child->isVisible() || !child->isEnabled())
| 0-72 | ||||||||||||||||||||||||
| 155 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 156 | if (propagateHelper(ev, child, sp, sig))
| 32-40 | ||||||||||||||||||||||||
| 157 | return true; executed 40 times by 1 test: return true;Executed by:
| 40 | ||||||||||||||||||||||||
| 158 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | QQuickMouseArea* ma = qobject_cast<QQuickMouseArea*>(item); | - | ||||||||||||||||||||||||
| 161 | if (ma && ma != q && ma->isEnabled() && itemPrivate->acceptedMouseButtons() & ev->button()) {
| 2-40 | ||||||||||||||||||||||||
| 162 | switch (sig) { | - | ||||||||||||||||||||||||
| 163 | case Click: executed 10 times by 1 test: case Click:Executed by:
| 10 | ||||||||||||||||||||||||
| 164 | if (!ma->d_func()->isClickConnected())
| 0-10 | ||||||||||||||||||||||||
| 165 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 166 | break; executed 10 times by 1 test: break;Executed by:
| 10 | ||||||||||||||||||||||||
| 167 | case DoubleClick: executed 4 times by 1 test: case DoubleClick:Executed by:
| 4 | ||||||||||||||||||||||||
| 168 | if (!ma->d_func()->isDoubleClickConnected())
| 0-4 | ||||||||||||||||||||||||
| 169 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 170 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||
| 171 | case PressAndHold: executed 4 times by 1 test: case PressAndHold:Executed by:
| 4 | ||||||||||||||||||||||||
| 172 | if (!ma->d_func()->isPressAndHoldConnected())
| 0-4 | ||||||||||||||||||||||||
| 173 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 174 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||
| 175 | } | - | ||||||||||||||||||||||||
| 176 | QPointF p = item->mapFromScene(sp); | - | ||||||||||||||||||||||||
| 177 | if (item->contains(p)) {
| 0-18 | ||||||||||||||||||||||||
| 178 | ev->setX(p.x()); | - | ||||||||||||||||||||||||
| 179 | ev->setY(p.y()); | - | ||||||||||||||||||||||||
| 180 | ev->setAccepted(true);//It is connected, they have to explicitly ignore to let it slide | - | ||||||||||||||||||||||||
| 181 | switch (sig) { | - | ||||||||||||||||||||||||
| 182 | case Click: emit ma->clicked(ev); break; executed 10 times by 1 test: break;Executed by:
executed 10 times by 1 test: case Click:Executed by:
| 10 | ||||||||||||||||||||||||
| 183 | case DoubleClick: emit ma->doubleClicked(ev); break; executed 4 times by 1 test: break;Executed by:
executed 4 times by 1 test: case DoubleClick:Executed by:
| 4 | ||||||||||||||||||||||||
| 184 | case PressAndHold: emit ma->pressAndHold(ev); break; executed 4 times by 1 test: break;Executed by:
executed 4 times by 1 test: case PressAndHold:Executed by:
| 4 | ||||||||||||||||||||||||
| 185 | } | - | ||||||||||||||||||||||||
| 186 | if (ev->isAccepted())
| 2-16 | ||||||||||||||||||||||||
| 187 | return true; executed 16 times by 1 test: return true;Executed by:
| 16 | ||||||||||||||||||||||||
| 188 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 189 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 190 | return false; executed 36 times by 1 test: return false;Executed by:
| 36 | ||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||
| 192 | } | - | ||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | /*! | - | ||||||||||||||||||||||||
| 195 | \qmltype MouseArea | - | ||||||||||||||||||||||||
| 196 | \instantiates QQuickMouseArea | - | ||||||||||||||||||||||||
| 197 | \inqmlmodule QtQuick | - | ||||||||||||||||||||||||
| 198 | \ingroup qtquick-input | - | ||||||||||||||||||||||||
| 199 | \brief Enables simple mouse handling. | - | ||||||||||||||||||||||||
| 200 | \inherits Item | - | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | A MouseArea is an invisible item that is typically used in conjunction with | - | ||||||||||||||||||||||||
| 203 | a visible item in order to provide mouse handling for that item. | - | ||||||||||||||||||||||||
| 204 | By effectively acting as a proxy, the logic for mouse handling can be | - | ||||||||||||||||||||||||
| 205 | contained within a MouseArea item. | - | ||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||
| 207 | The \l enabled property is used to enable and disable mouse handling for | - | ||||||||||||||||||||||||
| 208 | the proxied item. When disabled, the mouse area becomes transparent to | - | ||||||||||||||||||||||||
| 209 | mouse events. | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | MouseArea is an invisible Item, but it has a visible property. | - | ||||||||||||||||||||||||
| 212 | When set to false, the mouse area becomes transparent to mouse events. | - | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | The \l pressed read-only property indicates whether or not the user is | - | ||||||||||||||||||||||||
| 215 | holding down a mouse button over the mouse area. This property is often | - | ||||||||||||||||||||||||
| 216 | used in bindings between properties in a user interface. The containsMouse | - | ||||||||||||||||||||||||
| 217 | read-only property indicates the presence of the mouse cursor over the | - | ||||||||||||||||||||||||
| 218 | mouse area but, by default, only when a mouse button is held down; see | - | ||||||||||||||||||||||||
| 219 | the containsMouse documentation for details. | - | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | Information about the mouse position and button clicks are provided via | - | ||||||||||||||||||||||||
| 222 | signals for which event handler properties are defined. The most commonly | - | ||||||||||||||||||||||||
| 223 | used involved handling mouse presses and clicks: onClicked, onDoubleClicked, | - | ||||||||||||||||||||||||
| 224 | onPressed, onReleased and onPressAndHold. It's also possible to handle mouse | - | ||||||||||||||||||||||||
| 225 | wheel events via the onWheel signal. | - | ||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | If a MouseArea overlaps with the area of other MouseArea items, you can choose | - | ||||||||||||||||||||||||
| 228 | to propagate \c clicked, \c doubleClicked and \c pressAndHold events to these | - | ||||||||||||||||||||||||
| 229 | other items by setting propagateComposedEvents to true and rejecting events | - | ||||||||||||||||||||||||
| 230 | that should be propagated. See the propagateComposedEvents documentation for | - | ||||||||||||||||||||||||
| 231 | details. | - | ||||||||||||||||||||||||
| 232 | - | |||||||||||||||||||||||||
| 233 | By default, MouseArea items only report mouse clicks and not changes to the | - | ||||||||||||||||||||||||
| 234 | position of the mouse cursor. Setting the hoverEnabled property ensures that | - | ||||||||||||||||||||||||
| 235 | handlers defined for onPositionChanged, onEntered and onExited are used and | - | ||||||||||||||||||||||||
| 236 | that the containsMouse property is updated even when no mouse buttons are | - | ||||||||||||||||||||||||
| 237 | pressed. | - | ||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | \section1 Example Usage | - | ||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||
| 241 | \div {class="float-right"} | - | ||||||||||||||||||||||||
| 242 | \inlineimage qml-mousearea-snippet.png | - | ||||||||||||||||||||||||
| 243 | \enddiv | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | The following example uses a MouseArea in a \l Rectangle that changes | - | ||||||||||||||||||||||||
| 246 | the \l Rectangle color to red when clicked: | - | ||||||||||||||||||||||||
| 247 | - | |||||||||||||||||||||||||
| 248 | \snippet qml/mousearea/mousearea.qml import | - | ||||||||||||||||||||||||
| 249 | \codeline | - | ||||||||||||||||||||||||
| 250 | \snippet qml/mousearea/mousearea.qml intro | - | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | \clearfloat | - | ||||||||||||||||||||||||
| 253 | Many MouseArea signals pass a \l{MouseEvent}{mouse} parameter that contains | - | ||||||||||||||||||||||||
| 254 | additional information about the mouse event, such as the position, button, | - | ||||||||||||||||||||||||
| 255 | and any key modifiers. | - | ||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| 257 | Here is an extension of the previous example that produces a different | - | ||||||||||||||||||||||||
| 258 | color when the area is right clicked: | - | ||||||||||||||||||||||||
| 259 | - | |||||||||||||||||||||||||
| 260 | \snippet qml/mousearea/mousearea.qml intro-extended | - | ||||||||||||||||||||||||
| 261 | - | |||||||||||||||||||||||||
| 262 | \sa MouseEvent, {mousearea}{MouseArea example}, | - | ||||||||||||||||||||||||
| 263 | {Important Concepts In Qt Quick - User Input} | - | ||||||||||||||||||||||||
| 264 | */ | - | ||||||||||||||||||||||||
| 265 | - | |||||||||||||||||||||||||
| 266 | /*! | - | ||||||||||||||||||||||||
| 267 | \qmlsignal QtQuick::MouseArea::entered() | - | ||||||||||||||||||||||||
| 268 | - | |||||||||||||||||||||||||
| 269 | This signal is emitted when the mouse enters the mouse area. | - | ||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | By default this signal is only emitted if a button is currently | - | ||||||||||||||||||||||||
| 272 | pressed. Set \l hoverEnabled to true to emit this signal | - | ||||||||||||||||||||||||
| 273 | even when no mouse button is pressed. | - | ||||||||||||||||||||||||
| 274 | - | |||||||||||||||||||||||||
| 275 | \sa hoverEnabled | - | ||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | The corresponding handler is \c onEntered. | - | ||||||||||||||||||||||||
| 278 | */ | - | ||||||||||||||||||||||||
| 279 | - | |||||||||||||||||||||||||
| 280 | /*! | - | ||||||||||||||||||||||||
| 281 | \qmlsignal QtQuick::MouseArea::exited() | - | ||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | This signal is emitted when the mouse exits the mouse area. | - | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | By default this signal is only emitted if a button is currently | - | ||||||||||||||||||||||||
| 286 | pressed. Set \l hoverEnabled to true to emit this signal | - | ||||||||||||||||||||||||
| 287 | even when no mouse button is pressed. | - | ||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||
| 289 | The example below shows a fairly typical relationship between | - | ||||||||||||||||||||||||
| 290 | two MouseAreas, with \c mouseArea2 on top of \c mouseArea1. Moving the | - | ||||||||||||||||||||||||
| 291 | mouse into \c mouseArea2 from \c mouseArea1 will cause \c mouseArea1 | - | ||||||||||||||||||||||||
| 292 | to emit the \c exited signal. | - | ||||||||||||||||||||||||
| 293 | \qml | - | ||||||||||||||||||||||||
| 294 | Rectangle { | - | ||||||||||||||||||||||||
| 295 | width: 400; height: 400 | - | ||||||||||||||||||||||||
| 296 | MouseArea { | - | ||||||||||||||||||||||||
| 297 | id: mouseArea1 | - | ||||||||||||||||||||||||
| 298 | anchors.fill: parent | - | ||||||||||||||||||||||||
| 299 | hoverEnabled: true | - | ||||||||||||||||||||||||
| 300 | } | - | ||||||||||||||||||||||||
| 301 | MouseArea { | - | ||||||||||||||||||||||||
| 302 | id: mouseArea2 | - | ||||||||||||||||||||||||
| 303 | width: 100; height: 100 | - | ||||||||||||||||||||||||
| 304 | anchors.centerIn: parent | - | ||||||||||||||||||||||||
| 305 | hoverEnabled: true | - | ||||||||||||||||||||||||
| 306 | } | - | ||||||||||||||||||||||||
| 307 | } | - | ||||||||||||||||||||||||
| 308 | \endqml | - | ||||||||||||||||||||||||
| 309 | - | |||||||||||||||||||||||||
| 310 | If instead you give the two MouseAreas a parent-child relationship, | - | ||||||||||||||||||||||||
| 311 | moving the mouse into \c mouseArea2 from \c mouseArea1 will \b not | - | ||||||||||||||||||||||||
| 312 | cause \c mouseArea1 to emit \c exited. Instead, they will | - | ||||||||||||||||||||||||
| 313 | both be considered to be simultaneously hovered. | - | ||||||||||||||||||||||||
| 314 | - | |||||||||||||||||||||||||
| 315 | \sa hoverEnabled | - | ||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | The corresponding handler is \c onExited. | - | ||||||||||||||||||||||||
| 318 | */ | - | ||||||||||||||||||||||||
| 319 | - | |||||||||||||||||||||||||
| 320 | /*! | - | ||||||||||||||||||||||||
| 321 | \qmlsignal QtQuick::MouseArea::positionChanged(MouseEvent mouse) | - | ||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | This signal is emitted when the mouse position changes. | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | The \l {MouseEvent}{mouse} parameter provides information about the mouse, including the x and y | - | ||||||||||||||||||||||||
| 326 | position, and any buttons currently pressed. | - | ||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||
| 328 | By default this signal is only emitted if a button is currently | - | ||||||||||||||||||||||||
| 329 | pressed. Set \l hoverEnabled to true to emit this signal | - | ||||||||||||||||||||||||
| 330 | even when no mouse button is pressed. | - | ||||||||||||||||||||||||
| 331 | - | |||||||||||||||||||||||||
| 332 | When handling this signal, changing the \l {MouseEvent::}{accepted} property of the \a mouse | - | ||||||||||||||||||||||||
| 333 | parameter has no effect. | - | ||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||
| 335 | The corresponding handler is \c onPositionChanged. | - | ||||||||||||||||||||||||
| 336 | */ | - | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | /*! | - | ||||||||||||||||||||||||
| 339 | \qmlsignal QtQuick::MouseArea::clicked(MouseEvent mouse) | - | ||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||
| 341 | This signal is emitted when there is a click. A click is defined as a press followed by a release, | - | ||||||||||||||||||||||||
| 342 | both inside the MouseArea (pressing, moving outside the MouseArea, and then moving back inside and | - | ||||||||||||||||||||||||
| 343 | releasing is also considered a click). | - | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y | - | ||||||||||||||||||||||||
| 346 | position of the release of the click, and whether the click was held. | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | When handling this signal, changing the \l {MouseEvent::}{accepted} property of the \a mouse | - | ||||||||||||||||||||||||
| 349 | parameter has no effect, unless the \l propagateComposedEvents property is \c true. | - | ||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||
| 351 | The corresponding handler is \c onClicked. | - | ||||||||||||||||||||||||
| 352 | */ | - | ||||||||||||||||||||||||
| 353 | - | |||||||||||||||||||||||||
| 354 | /*! | - | ||||||||||||||||||||||||
| 355 | \qmlsignal QtQuick::MouseArea::pressed(MouseEvent mouse) | - | ||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||
| 357 | This signal is emitted when there is a press. | - | ||||||||||||||||||||||||
| 358 | The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y | - | ||||||||||||||||||||||||
| 359 | position and which button was pressed. | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | When handling this signal, use the \l {MouseEvent::}{accepted} property of the \a mouse | - | ||||||||||||||||||||||||
| 362 | parameter to control whether this MouseArea handles the press and all future mouse events until | - | ||||||||||||||||||||||||
| 363 | release. The default is to accept the event and not allow other MouseAreas beneath this one to | - | ||||||||||||||||||||||||
| 364 | handle the event. If \e accepted is set to false, no further events will be sent to this MouseArea | - | ||||||||||||||||||||||||
| 365 | until the button is next pressed. | - | ||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | The corresponding handler is \c onPressed. | - | ||||||||||||||||||||||||
| 368 | */ | - | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | /*! | - | ||||||||||||||||||||||||
| 371 | \qmlsignal QtQuick::MouseArea::released(MouseEvent mouse) | - | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | This signal is emitted when there is a release. | - | ||||||||||||||||||||||||
| 374 | The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y | - | ||||||||||||||||||||||||
| 375 | position of the release of the click, and whether the click was held. | - | ||||||||||||||||||||||||
| 376 | - | |||||||||||||||||||||||||
| 377 | When handling this signal, changing the \l {MouseEvent::}{accepted} property of the \a mouse | - | ||||||||||||||||||||||||
| 378 | parameter has no effect. | - | ||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||
| 380 | The corresponding handler is \c onReleased. | - | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | \sa canceled | - | ||||||||||||||||||||||||
| 383 | */ | - | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | /*! | - | ||||||||||||||||||||||||
| 386 | \qmlsignal QtQuick::MouseArea::pressAndHold(MouseEvent mouse) | - | ||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | This signal is emitted when there is a long press (currently 800ms). | - | ||||||||||||||||||||||||
| 389 | The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y | - | ||||||||||||||||||||||||
| 390 | position of the press, and which button is pressed. | - | ||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||
| 392 | When handling this signal, changing the \l {MouseEvent::}{accepted} property of the \a mouse | - | ||||||||||||||||||||||||
| 393 | parameter has no effect, unless the \l propagateComposedEvents property is \c true. | - | ||||||||||||||||||||||||
| 394 | - | |||||||||||||||||||||||||
| 395 | The corresponding handler is \c onPressAndHold. | - | ||||||||||||||||||||||||
| 396 | */ | - | ||||||||||||||||||||||||
| 397 | - | |||||||||||||||||||||||||
| 398 | /*! | - | ||||||||||||||||||||||||
| 399 | \qmlsignal QtQuick::MouseArea::doubleClicked(MouseEvent mouse) | - | ||||||||||||||||||||||||
| 400 | - | |||||||||||||||||||||||||
| 401 | This signal is emitted when there is a double-click (a press followed by a release followed by a press). | - | ||||||||||||||||||||||||
| 402 | The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y | - | ||||||||||||||||||||||||
| 403 | position of the release of the click, and whether the click was held. | - | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | When handling this signal, if the \l {MouseEvent::}{accepted} property of the \a mouse | - | ||||||||||||||||||||||||
| 406 | parameter is set to false, the pressed/released/clicked signals will be emitted for the second | - | ||||||||||||||||||||||||
| 407 | click; otherwise they are suppressed. The \c accepted property defaults to true. | - | ||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||
| 409 | The corresponding handler is \c onDoubleClicked. | - | ||||||||||||||||||||||||
| 410 | */ | - | ||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||
| 412 | /*! | - | ||||||||||||||||||||||||
| 413 | \qmlsignal QtQuick::MouseArea::canceled() | - | ||||||||||||||||||||||||
| 414 | - | |||||||||||||||||||||||||
| 415 | This signal is emitted when mouse events have been canceled, because another item stole the mouse event handling. | - | ||||||||||||||||||||||||
| 416 | - | |||||||||||||||||||||||||
| 417 | This signal is for advanced use: it is useful when there is more than one MouseArea | - | ||||||||||||||||||||||||
| 418 | that is handling input, or when there is a MouseArea inside a \l Flickable. In the latter | - | ||||||||||||||||||||||||
| 419 | case, if you execute some logic in the \c onPressed signal handler and then start dragging, the | - | ||||||||||||||||||||||||
| 420 | \l Flickable will steal the mouse handling from the MouseArea. In these cases, to reset | - | ||||||||||||||||||||||||
| 421 | the logic when the MouseArea has lost the mouse handling to the \l Flickable, | - | ||||||||||||||||||||||||
| 422 | \c canceled should be handled in addition to \l released. | - | ||||||||||||||||||||||||
| 423 | - | |||||||||||||||||||||||||
| 424 | The corresponding handler is \c onCanceled. | - | ||||||||||||||||||||||||
| 425 | */ | - | ||||||||||||||||||||||||
| 426 | - | |||||||||||||||||||||||||
| 427 | /*! | - | ||||||||||||||||||||||||
| 428 | \qmlsignal QtQuick::MouseArea::wheel(WheelEvent wheel) | - | ||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | This signal is emitted in response to both mouse wheel and trackpad scroll gestures. | - | ||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | The \l {WheelEvent}{wheel} parameter provides information about the event, including the x and y | - | ||||||||||||||||||||||||
| 433 | position, any buttons currently pressed, and information about the wheel movement, including | - | ||||||||||||||||||||||||
| 434 | angleDelta and pixelDelta. | - | ||||||||||||||||||||||||
| 435 | - | |||||||||||||||||||||||||
| 436 | The corresponding handler is \c onWheel. | - | ||||||||||||||||||||||||
| 437 | */ | - | ||||||||||||||||||||||||
| 438 | - | |||||||||||||||||||||||||
| 439 | QQuickMouseArea::QQuickMouseArea(QQuickItem *parent) | - | ||||||||||||||||||||||||
| 440 | : QQuickItem(*(new QQuickMouseAreaPrivate), parent) | - | ||||||||||||||||||||||||
| 441 | { | - | ||||||||||||||||||||||||
| 442 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 443 | d->init(); | - | ||||||||||||||||||||||||
| 444 | #if QT_CONFIG(cursor) | - | ||||||||||||||||||||||||
| 445 | // Explcitly call setCursor on QQuickItem since | - | ||||||||||||||||||||||||
| 446 | // it internally keeps a boolean hasCursor that doesn't | - | ||||||||||||||||||||||||
| 447 | // get set to true unless you call setCursor | - | ||||||||||||||||||||||||
| 448 | setCursor(Qt::ArrowCursor); | - | ||||||||||||||||||||||||
| 449 | #endif | - | ||||||||||||||||||||||||
| 450 | } executed 2012 times by 23 tests: end of blockExecuted by:
| 2012 | ||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||
| 452 | QQuickMouseArea::~QQuickMouseArea() | - | ||||||||||||||||||||||||
| 453 | { | - | ||||||||||||||||||||||||
| 454 | } | - | ||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||
| 456 | /*! | - | ||||||||||||||||||||||||
| 457 | \qmlproperty real QtQuick::MouseArea::mouseX | - | ||||||||||||||||||||||||
| 458 | \qmlproperty real QtQuick::MouseArea::mouseY | - | ||||||||||||||||||||||||
| 459 | These properties hold the coordinates of the mouse cursor. | - | ||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||
| 461 | If the hoverEnabled property is false then these properties will only be valid | - | ||||||||||||||||||||||||
| 462 | while a button is pressed, and will remain valid as long as the button is held | - | ||||||||||||||||||||||||
| 463 | down even if the mouse is moved outside the area. | - | ||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||
| 465 | By default, this property is false. | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | If hoverEnabled is true then these properties will be valid when: | - | ||||||||||||||||||||||||
| 468 | \list | - | ||||||||||||||||||||||||
| 469 | \li no button is pressed, but the mouse is within the MouseArea (containsMouse is true). | - | ||||||||||||||||||||||||
| 470 | \li a button is pressed and held, even if it has since moved out of the area. | - | ||||||||||||||||||||||||
| 471 | \endlist | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | The coordinates are relative to the MouseArea. | - | ||||||||||||||||||||||||
| 474 | */ | - | ||||||||||||||||||||||||
| 475 | qreal QQuickMouseArea::mouseX() const | - | ||||||||||||||||||||||||
| 476 | { | - | ||||||||||||||||||||||||
| 477 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 478 | return d->lastPos.x(); executed 64 times by 3 tests: return d->lastPos.x();Executed by:
| 64 | ||||||||||||||||||||||||
| 479 | } | - | ||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | qreal QQuickMouseArea::mouseY() const | - | ||||||||||||||||||||||||
| 482 | { | - | ||||||||||||||||||||||||
| 483 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 484 | return d->lastPos.y(); executed 64 times by 3 tests: return d->lastPos.y();Executed by:
| 64 | ||||||||||||||||||||||||
| 485 | } | - | ||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | /*! | - | ||||||||||||||||||||||||
| 488 | \qmlproperty bool QtQuick::MouseArea::enabled | - | ||||||||||||||||||||||||
| 489 | This property holds whether the item accepts mouse events. | - | ||||||||||||||||||||||||
| 490 | - | |||||||||||||||||||||||||
| 491 | \note Due to historical reasons, this property is not equivalent to | - | ||||||||||||||||||||||||
| 492 | Item.enabled. It only affects mouse events, and its effect does not | - | ||||||||||||||||||||||||
| 493 | propagate to child items. | - | ||||||||||||||||||||||||
| 494 | - | |||||||||||||||||||||||||
| 495 | By default, this property is true. | - | ||||||||||||||||||||||||
| 496 | */ | - | ||||||||||||||||||||||||
| 497 | bool QQuickMouseArea::isEnabled() const | - | ||||||||||||||||||||||||
| 498 | { | - | ||||||||||||||||||||||||
| 499 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 500 | return d->enabled; executed 48 times by 2 tests: return d->enabled;Executed by:
| 48 | ||||||||||||||||||||||||
| 501 | } | - | ||||||||||||||||||||||||
| 502 | - | |||||||||||||||||||||||||
| 503 | void QQuickMouseArea::setEnabled(bool a) | - | ||||||||||||||||||||||||
| 504 | { | - | ||||||||||||||||||||||||
| 505 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 506 | if (a != d->enabled) {
| 10-112 | ||||||||||||||||||||||||
| 507 | d->enabled = a; | - | ||||||||||||||||||||||||
| 508 | emit enabledChanged(); | - | ||||||||||||||||||||||||
| 509 | } executed 112 times by 3 tests: end of blockExecuted by:
| 112 | ||||||||||||||||||||||||
| 510 | } executed 122 times by 3 tests: end of blockExecuted by:
| 122 | ||||||||||||||||||||||||
| 511 | - | |||||||||||||||||||||||||
| 512 | /*! | - | ||||||||||||||||||||||||
| 513 | \qmlproperty bool QtQuick::MouseArea::scrollGestureEnabled | - | ||||||||||||||||||||||||
| 514 | \since 5.5 | - | ||||||||||||||||||||||||
| 515 | - | |||||||||||||||||||||||||
| 516 | This property controls whether this MouseArea responds to scroll gestures | - | ||||||||||||||||||||||||
| 517 | from non-mouse devices, such as the 2-finger flick gesture on a trackpad. | - | ||||||||||||||||||||||||
| 518 | If set to false, the \l wheel signal be emitted only when the wheel event | - | ||||||||||||||||||||||||
| 519 | comes from an actual mouse with a wheel, while scroll gesture events will | - | ||||||||||||||||||||||||
| 520 | pass through to any other Item that will handle them. For example, the user | - | ||||||||||||||||||||||||
| 521 | might perform a flick gesture while the cursor is over an item containing a | - | ||||||||||||||||||||||||
| 522 | MouseArea, intending to interact with a Flickable which is underneath. | - | ||||||||||||||||||||||||
| 523 | Setting this property to false will allow the PinchArea to handle the mouse | - | ||||||||||||||||||||||||
| 524 | wheel or the pinch gesture, while the Flickable handles the flick gesture. | - | ||||||||||||||||||||||||
| 525 | - | |||||||||||||||||||||||||
| 526 | By default, this property is true. | - | ||||||||||||||||||||||||
| 527 | */ | - | ||||||||||||||||||||||||
| 528 | bool QQuickMouseArea::isScrollGestureEnabled() const | - | ||||||||||||||||||||||||
| 529 | { | - | ||||||||||||||||||||||||
| 530 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 531 | return d->scrollGestureEnabled; executed 26 times by 2 tests: return d->scrollGestureEnabled;Executed by:
| 26 | ||||||||||||||||||||||||
| 532 | } | - | ||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||
| 534 | void QQuickMouseArea::setScrollGestureEnabled(bool e) | - | ||||||||||||||||||||||||
| 535 | { | - | ||||||||||||||||||||||||
| 536 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 537 | if (e != d->scrollGestureEnabled) {
| 0 | ||||||||||||||||||||||||
| 538 | d->scrollGestureEnabled = e; | - | ||||||||||||||||||||||||
| 539 | emit scrollGestureEnabledChanged(); | - | ||||||||||||||||||||||||
| 540 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 541 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||
| 543 | /*! | - | ||||||||||||||||||||||||
| 544 | \qmlproperty bool QtQuick::MouseArea::preventStealing | - | ||||||||||||||||||||||||
| 545 | This property holds whether the mouse events may be stolen from this | - | ||||||||||||||||||||||||
| 546 | MouseArea. | - | ||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||
| 548 | If a MouseArea is placed within an item that filters child mouse | - | ||||||||||||||||||||||||
| 549 | events, such as Flickable, the mouse | - | ||||||||||||||||||||||||
| 550 | events may be stolen from the MouseArea if a gesture is recognized | - | ||||||||||||||||||||||||
| 551 | by the parent item, e.g. a flick gesture. If preventStealing is | - | ||||||||||||||||||||||||
| 552 | set to true, no item will steal the mouse events. | - | ||||||||||||||||||||||||
| 553 | - | |||||||||||||||||||||||||
| 554 | Note that setting preventStealing to true once an item has started | - | ||||||||||||||||||||||||
| 555 | stealing events will have no effect until the next press event. | - | ||||||||||||||||||||||||
| 556 | - | |||||||||||||||||||||||||
| 557 | By default this property is false. | - | ||||||||||||||||||||||||
| 558 | */ | - | ||||||||||||||||||||||||
| 559 | bool QQuickMouseArea::preventStealing() const | - | ||||||||||||||||||||||||
| 560 | { | - | ||||||||||||||||||||||||
| 561 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 562 | return d->preventStealing; executed 24 times by 1 test: return d->preventStealing;Executed by:
| 24 | ||||||||||||||||||||||||
| 563 | } | - | ||||||||||||||||||||||||
| 564 | - | |||||||||||||||||||||||||
| 565 | void QQuickMouseArea::setPreventStealing(bool prevent) | - | ||||||||||||||||||||||||
| 566 | { | - | ||||||||||||||||||||||||
| 567 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 568 | if (prevent != d->preventStealing) {
| 2-6 | ||||||||||||||||||||||||
| 569 | d->preventStealing = prevent; | - | ||||||||||||||||||||||||
| 570 | setKeepMouseGrab(d->preventStealing && d->enabled); | - | ||||||||||||||||||||||||
| 571 | emit preventStealingChanged(); | - | ||||||||||||||||||||||||
| 572 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 573 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 574 | - | |||||||||||||||||||||||||
| 575 | - | |||||||||||||||||||||||||
| 576 | /*! | - | ||||||||||||||||||||||||
| 577 | \qmlproperty bool QtQuick::MouseArea::propagateComposedEvents | - | ||||||||||||||||||||||||
| 578 | This property holds whether composed mouse events will automatically propagate to | - | ||||||||||||||||||||||||
| 579 | other MouseAreas that overlap with this MouseArea but are lower in the visual stacking order. | - | ||||||||||||||||||||||||
| 580 | By default, this property is false. | - | ||||||||||||||||||||||||
| 581 | - | |||||||||||||||||||||||||
| 582 | MouseArea contains several composed events: \c clicked, \c doubleClicked and \c pressAndHold. | - | ||||||||||||||||||||||||
| 583 | These are composed of basic mouse events, like \c pressed, and can be propagated differently | - | ||||||||||||||||||||||||
| 584 | in comparison to basic events. | - | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | If propagateComposedEvents is set to true, then composed events will be automatically | - | ||||||||||||||||||||||||
| 587 | propagated to other MouseAreas in the same location in the scene. Each event is propagated | - | ||||||||||||||||||||||||
| 588 | to the next \l enabled MouseArea beneath it in the stacking order, propagating down this visual | - | ||||||||||||||||||||||||
| 589 | hierarchy until a MouseArea accepts the event. Unlike \c pressed events, composed events will | - | ||||||||||||||||||||||||
| 590 | not be automatically accepted if no handler is present. | - | ||||||||||||||||||||||||
| 591 | - | |||||||||||||||||||||||||
| 592 | For example, below is a yellow \l Rectangle that contains a blue \l Rectangle. The blue | - | ||||||||||||||||||||||||
| 593 | rectangle is the top-most item in the hierarchy of the visual stacking order; it will | - | ||||||||||||||||||||||||
| 594 | visually rendered above the yellow rectangle. Since the blue rectangle sets | - | ||||||||||||||||||||||||
| 595 | propagateComposedEvents to true, and also sets \l MouseEvent::accepted to false for all | - | ||||||||||||||||||||||||
| 596 | received \c clicked events, any \c clicked events it receives are propagated to the | - | ||||||||||||||||||||||||
| 597 | MouseArea of the yellow rectangle beneath it. | - | ||||||||||||||||||||||||
| 598 | - | |||||||||||||||||||||||||
| 599 | \qml | - | ||||||||||||||||||||||||
| 600 | import QtQuick 2.0 | - | ||||||||||||||||||||||||
| 601 | - | |||||||||||||||||||||||||
| 602 | Rectangle { | - | ||||||||||||||||||||||||
| 603 | color: "yellow" | - | ||||||||||||||||||||||||
| 604 | width: 100; height: 100 | - | ||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||
| 606 | MouseArea { | - | ||||||||||||||||||||||||
| 607 | anchors.fill: parent | - | ||||||||||||||||||||||||
| 608 | onClicked: console.log("clicked yellow") | - | ||||||||||||||||||||||||
| 609 | } | - | ||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||
| 611 | Rectangle { | - | ||||||||||||||||||||||||
| 612 | color: "blue" | - | ||||||||||||||||||||||||
| 613 | width: 50; height: 50 | - | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | MouseArea { | - | ||||||||||||||||||||||||
| 616 | anchors.fill: parent | - | ||||||||||||||||||||||||
| 617 | propagateComposedEvents: true | - | ||||||||||||||||||||||||
| 618 | onClicked: { | - | ||||||||||||||||||||||||
| 619 | console.log("clicked blue") | - | ||||||||||||||||||||||||
| 620 | mouse.accepted = false | - | ||||||||||||||||||||||||
| 621 | } | - | ||||||||||||||||||||||||
| 622 | } | - | ||||||||||||||||||||||||
| 623 | } | - | ||||||||||||||||||||||||
| 624 | } | - | ||||||||||||||||||||||||
| 625 | \endqml | - | ||||||||||||||||||||||||
| 626 | - | |||||||||||||||||||||||||
| 627 | Clicking on the blue rectangle will cause the \c onClicked handler of its child MouseArea to | - | ||||||||||||||||||||||||
| 628 | be invoked; the event will then be propagated to the MouseArea of the yellow rectangle, causing | - | ||||||||||||||||||||||||
| 629 | its own \c onClicked handler to be invoked. | - | ||||||||||||||||||||||||
| 630 | - | |||||||||||||||||||||||||
| 631 | This property greatly simplifies the usecase of when you want to have overlapping MouseAreas | - | ||||||||||||||||||||||||
| 632 | handling the composed events together. For example: if you want one MouseArea to handle \c clicked | - | ||||||||||||||||||||||||
| 633 | signals and the other to handle \c pressAndHold, or if you want one MouseArea to handle \c clicked most | - | ||||||||||||||||||||||||
| 634 | of the time, but pass it through when certain conditions are met. | - | ||||||||||||||||||||||||
| 635 | */ | - | ||||||||||||||||||||||||
| 636 | bool QQuickMouseArea::propagateComposedEvents() const | - | ||||||||||||||||||||||||
| 637 | { | - | ||||||||||||||||||||||||
| 638 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 639 | return d->propagateComposedEvents; executed 24 times by 1 test: return d->propagateComposedEvents;Executed by:
| 24 | ||||||||||||||||||||||||
| 640 | } | - | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | void QQuickMouseArea::setPropagateComposedEvents(bool prevent) | - | ||||||||||||||||||||||||
| 643 | { | - | ||||||||||||||||||||||||
| 644 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 645 | if (prevent != d->propagateComposedEvents) {
| 0-60 | ||||||||||||||||||||||||
| 646 | d->propagateComposedEvents = prevent; | - | ||||||||||||||||||||||||
| 647 | setKeepMouseGrab(d->propagateComposedEvents && d->enabled); | - | ||||||||||||||||||||||||
| 648 | emit propagateComposedEventsChanged(); | - | ||||||||||||||||||||||||
| 649 | } executed 60 times by 1 test: end of blockExecuted by:
| 60 | ||||||||||||||||||||||||
| 650 | } executed 60 times by 1 test: end of blockExecuted by:
| 60 | ||||||||||||||||||||||||
| 651 | - | |||||||||||||||||||||||||
| 652 | /*! | - | ||||||||||||||||||||||||
| 653 | \qmlproperty MouseButtons QtQuick::MouseArea::pressedButtons | - | ||||||||||||||||||||||||
| 654 | This property holds the mouse buttons currently pressed. | - | ||||||||||||||||||||||||
| 655 | - | |||||||||||||||||||||||||
| 656 | It contains a bitwise combination of: | - | ||||||||||||||||||||||||
| 657 | \list | - | ||||||||||||||||||||||||
| 658 | \li Qt.LeftButton | - | ||||||||||||||||||||||||
| 659 | \li Qt.RightButton | - | ||||||||||||||||||||||||
| 660 | \li Qt.MiddleButton | - | ||||||||||||||||||||||||
| 661 | \endlist | - | ||||||||||||||||||||||||
| 662 | - | |||||||||||||||||||||||||
| 663 | The code below displays "right" when the right mouse buttons is pressed: | - | ||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||
| 665 | \snippet qml/mousearea/mousearea.qml mousebuttons | - | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | \note this property only handles buttons specified in \l acceptedButtons. | - | ||||||||||||||||||||||||
| 668 | - | |||||||||||||||||||||||||
| 669 | \sa acceptedButtons | - | ||||||||||||||||||||||||
| 670 | */ | - | ||||||||||||||||||||||||
| 671 | Qt::MouseButtons QQuickMouseArea::pressedButtons() const | - | ||||||||||||||||||||||||
| 672 | { | - | ||||||||||||||||||||||||
| 673 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 674 | return d->pressed; executed 60 times by 3 tests: return d->pressed;Executed by:
| 60 | ||||||||||||||||||||||||
| 675 | } | - | ||||||||||||||||||||||||
| 676 | - | |||||||||||||||||||||||||
| 677 | void QQuickMouseArea::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 678 | { | - | ||||||||||||||||||||||||
| 679 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 680 | d->moved = false; | - | ||||||||||||||||||||||||
| 681 | d->stealMouse = d->preventStealing; | - | ||||||||||||||||||||||||
| 682 | d->overThreshold = false; | - | ||||||||||||||||||||||||
| 683 | if (!d->enabled || !(event->button() & acceptedMouseButtons())) {
| 0-292 | ||||||||||||||||||||||||
| 684 | QQuickItem::mousePressEvent(event); | - | ||||||||||||||||||||||||
| 685 | } else { executed 98 times by 2 tests: end of blockExecuted by:
| 98 | ||||||||||||||||||||||||
| 686 | d->longPress = false; | - | ||||||||||||||||||||||||
| 687 | d->saveEvent(event); | - | ||||||||||||||||||||||||
| 688 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 689 | if (d->drag)
| 80-212 | ||||||||||||||||||||||||
| 690 | d->drag->setActive(false); executed 80 times by 4 tests: d->drag->setActive(false);Executed by:
| 80 | ||||||||||||||||||||||||
| 691 | #endif | - | ||||||||||||||||||||||||
| 692 | setHovered(true); | - | ||||||||||||||||||||||||
| 693 | d->startScene = event->windowPos(); | - | ||||||||||||||||||||||||
| 694 | setKeepMouseGrab(d->stealMouse); | - | ||||||||||||||||||||||||
| 695 | event->setAccepted(setPressed(event->button(), true, event->source())); | - | ||||||||||||||||||||||||
| 696 | if (event->isAccepted())
| 16-276 | ||||||||||||||||||||||||
| 697 | d->pressAndHoldTimer.start(pressAndHoldInterval(), this); executed 276 times by 6 tests: d->pressAndHoldTimer.start(pressAndHoldInterval(), this);Executed by:
| 276 | ||||||||||||||||||||||||
| 698 | } executed 292 times by 6 tests: end of blockExecuted by:
| 292 | ||||||||||||||||||||||||
| 699 | } | - | ||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||
| 701 | void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 702 | { | - | ||||||||||||||||||||||||
| 703 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 704 | if (!d->enabled && !d->pressed) {
| 0-397 | ||||||||||||||||||||||||
| 705 | QQuickItem::mouseMoveEvent(event); | - | ||||||||||||||||||||||||
| 706 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 707 | } | - | ||||||||||||||||||||||||
| 708 | - | |||||||||||||||||||||||||
| 709 | d->saveEvent(event); | - | ||||||||||||||||||||||||
| 710 | - | |||||||||||||||||||||||||
| 711 | // ### we should skip this if these signals aren't used | - | ||||||||||||||||||||||||
| 712 | // ### can GV handle this for us? | - | ||||||||||||||||||||||||
| 713 | setHovered(contains(d->lastPos)); | - | ||||||||||||||||||||||||
| 714 | - | |||||||||||||||||||||||||
| 715 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 716 | if (d->drag && d->drag->target()) {
| 0-338 | ||||||||||||||||||||||||
| 717 | if (!d->moved) {
| 82-256 | ||||||||||||||||||||||||
| 718 | d->targetStartPos = d->drag->target()->parentItem()
| 0-82 | ||||||||||||||||||||||||
| 719 | ? d->drag->target()->parentItem()->mapToScene(d->drag->target()->position()) | - | ||||||||||||||||||||||||
| 720 | : d->drag->target()->position(); | - | ||||||||||||||||||||||||
| 721 | } executed 82 times by 4 tests: end of blockExecuted by:
| 82 | ||||||||||||||||||||||||
| 722 | - | |||||||||||||||||||||||||
| 723 | QPointF startLocalPos; | - | ||||||||||||||||||||||||
| 724 | QPointF curLocalPos; | - | ||||||||||||||||||||||||
| 725 | if (drag()->target()->parentItem()) {
| 0-338 | ||||||||||||||||||||||||
| 726 | startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); | - | ||||||||||||||||||||||||
| 727 | curLocalPos = drag()->target()->parentItem()->mapFromScene(event->windowPos()); | - | ||||||||||||||||||||||||
| 728 | } else { executed 338 times by 4 tests: end of blockExecuted by:
| 338 | ||||||||||||||||||||||||
| 729 | startLocalPos = d->startScene; | - | ||||||||||||||||||||||||
| 730 | curLocalPos = event->windowPos(); | - | ||||||||||||||||||||||||
| 731 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | if (keepMouseGrab() && d->stealMouse && d->overThreshold && !d->drag->active())
| 0-232 | ||||||||||||||||||||||||
| 734 | d->drag->setActive(true); executed 60 times by 4 tests: d->drag->setActive(true);Executed by:
| 60 | ||||||||||||||||||||||||
| 735 | - | |||||||||||||||||||||||||
| 736 | QPointF startPos = d->drag->target()->parentItem()
| 0-338 | ||||||||||||||||||||||||
| 737 | ? d->drag->target()->parentItem()->mapFromScene(d->targetStartPos) | - | ||||||||||||||||||||||||
| 738 | : d->targetStartPos; | - | ||||||||||||||||||||||||
| 739 | - | |||||||||||||||||||||||||
| 740 | bool dragX = drag()->axis() & QQuickDrag::XAxis; | - | ||||||||||||||||||||||||
| 741 | bool dragY = drag()->axis() & QQuickDrag::YAxis; | - | ||||||||||||||||||||||||
| 742 | - | |||||||||||||||||||||||||
| 743 | QPointF dragPos = d->drag->target()->position(); | - | ||||||||||||||||||||||||
| 744 | QPointF boundedDragPos = dragPos; | - | ||||||||||||||||||||||||
| 745 | if (dragX) {
| 14-324 | ||||||||||||||||||||||||
| 746 | dragPos.setX(startPos.x() + curLocalPos.x() - startLocalPos.x()); | - | ||||||||||||||||||||||||
| 747 | boundedDragPos.setX(qBound( | - | ||||||||||||||||||||||||
| 748 | d->drag->xmin(), | - | ||||||||||||||||||||||||
| 749 | dragPos.x(), | - | ||||||||||||||||||||||||
| 750 | d->drag->xmax())); | - | ||||||||||||||||||||||||
| 751 | } executed 324 times by 4 tests: end of blockExecuted by:
| 324 | ||||||||||||||||||||||||
| 752 | if (dragY) {
| 20-318 | ||||||||||||||||||||||||
| 753 | dragPos.setY(startPos.y() + curLocalPos.y() - startLocalPos.y()); | - | ||||||||||||||||||||||||
| 754 | boundedDragPos.setY(qBound( | - | ||||||||||||||||||||||||
| 755 | d->drag->ymin(), | - | ||||||||||||||||||||||||
| 756 | dragPos.y(), | - | ||||||||||||||||||||||||
| 757 | d->drag->ymax())); | - | ||||||||||||||||||||||||
| 758 | } executed 318 times by 4 tests: end of blockExecuted by:
| 318 | ||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||
| 760 | QPointF targetPos = d->drag->target()->position(); | - | ||||||||||||||||||||||||
| 761 | - | |||||||||||||||||||||||||
| 762 | if (d->drag->active())
| 118-220 | ||||||||||||||||||||||||
| 763 | d->drag->target()->setPosition(boundedDragPos); executed 220 times by 4 tests: d->drag->target()->setPosition(boundedDragPos);Executed by:
| 220 | ||||||||||||||||||||||||
| 764 | - | |||||||||||||||||||||||||
| 765 | bool dragOverThresholdX = QQuickWindowPrivate::dragOverThreshold(dragPos.x() - startPos.x(), | - | ||||||||||||||||||||||||
| 766 | Qt::XAxis, event, d->drag->threshold()); | - | ||||||||||||||||||||||||
| 767 | bool dragOverThresholdY = QQuickWindowPrivate::dragOverThreshold(dragPos.y() - startPos.y(), | - | ||||||||||||||||||||||||
| 768 | Qt::YAxis, event, d->drag->threshold()); | - | ||||||||||||||||||||||||
| 769 | - | |||||||||||||||||||||||||
| 770 | if (!d->overThreshold && (((targetPos.x() != boundedDragPos.x()) && dragOverThresholdX) ||
| 8-220 | ||||||||||||||||||||||||
| 771 | ((targetPos.y() != boundedDragPos.y()) && dragOverThresholdY)))
| 20-54 | ||||||||||||||||||||||||
| 772 | { | - | ||||||||||||||||||||||||
| 773 | d->overThreshold = true; | - | ||||||||||||||||||||||||
| 774 | if (d->drag->smoothed())
| 2-72 | ||||||||||||||||||||||||
| 775 | d->startScene = event->windowPos(); executed 72 times by 4 tests: d->startScene = event->windowPos();Executed by:
| 72 | ||||||||||||||||||||||||
| 776 | } executed 74 times by 4 tests: end of blockExecuted by:
| 74 | ||||||||||||||||||||||||
| 777 | - | |||||||||||||||||||||||||
| 778 | if (!keepMouseGrab() && d->overThreshold) {
| 36-232 | ||||||||||||||||||||||||
| 779 | setKeepMouseGrab(true); | - | ||||||||||||||||||||||||
| 780 | d->stealMouse = true; | - | ||||||||||||||||||||||||
| 781 | } executed 70 times by 4 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||||||||
| 782 | - | |||||||||||||||||||||||||
| 783 | d->moved = true; | - | ||||||||||||||||||||||||
| 784 | } executed 338 times by 4 tests: end of blockExecuted by:
| 338 | ||||||||||||||||||||||||
| 785 | #endif | - | ||||||||||||||||||||||||
| 786 | - | |||||||||||||||||||||||||
| 787 | QQuickMouseEvent &me = d->quickMouseEvent; | - | ||||||||||||||||||||||||
| 788 | me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress, event->flags()); | - | ||||||||||||||||||||||||
| 789 | me.setSource(event->source()); | - | ||||||||||||||||||||||||
| 790 | emit mouseXChanged(&me); | - | ||||||||||||||||||||||||
| 791 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 792 | emit mouseYChanged(&me); | - | ||||||||||||||||||||||||
| 793 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 794 | emit positionChanged(&me); | - | ||||||||||||||||||||||||
| 795 | } executed 401 times by 4 tests: end of blockExecuted by:
| 401 | ||||||||||||||||||||||||
| 796 | - | |||||||||||||||||||||||||
| 797 | void QQuickMouseArea::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 798 | { | - | ||||||||||||||||||||||||
| 799 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 800 | d->stealMouse = false; | - | ||||||||||||||||||||||||
| 801 | d->overThreshold = false; | - | ||||||||||||||||||||||||
| 802 | if (!d->enabled && !d->pressed) {
| 0-220 | ||||||||||||||||||||||||
| 803 | QQuickItem::mouseReleaseEvent(event); | - | ||||||||||||||||||||||||
| 804 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 805 | d->saveEvent(event); | - | ||||||||||||||||||||||||
| 806 | setPressed(event->button(), false, event->source()); | - | ||||||||||||||||||||||||
| 807 | if (!d->pressed) {
| 2-220 | ||||||||||||||||||||||||
| 808 | // no other buttons are pressed | - | ||||||||||||||||||||||||
| 809 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 810 | if (d->drag)
| 58-162 | ||||||||||||||||||||||||
| 811 | d->drag->setActive(false); executed 58 times by 4 tests: d->drag->setActive(false);Executed by:
| 58 | ||||||||||||||||||||||||
| 812 | #endif | - | ||||||||||||||||||||||||
| 813 | // If we don't accept hover, we need to reset containsMouse. | - | ||||||||||||||||||||||||
| 814 | if (!acceptHoverEvents())
| 12-208 | ||||||||||||||||||||||||
| 815 | setHovered(false); executed 208 times by 6 tests: setHovered(false);Executed by:
| 208 | ||||||||||||||||||||||||
| 816 | QQuickWindow *w = window(); | - | ||||||||||||||||||||||||
| 817 | if (w && w->mouseGrabberItem() == this)
| 0-218 | ||||||||||||||||||||||||
| 818 | ungrabMouse(); executed 218 times by 6 tests: ungrabMouse();Executed by:
| 218 | ||||||||||||||||||||||||
| 819 | setKeepMouseGrab(false); | - | ||||||||||||||||||||||||
| 820 | } executed 220 times by 6 tests: end of blockExecuted by:
| 220 | ||||||||||||||||||||||||
| 821 | } executed 222 times by 6 tests: end of blockExecuted by:
| 222 | ||||||||||||||||||||||||
| 822 | d->doubleClick = false; | - | ||||||||||||||||||||||||
| 823 | } executed 222 times by 6 tests: end of blockExecuted by:
| 222 | ||||||||||||||||||||||||
| 824 | - | |||||||||||||||||||||||||
| 825 | void QQuickMouseArea::mouseDoubleClickEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 826 | { | - | ||||||||||||||||||||||||
| 827 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 828 | if (d->enabled) {
| 0-38 | ||||||||||||||||||||||||
| 829 | d->saveEvent(event); | - | ||||||||||||||||||||||||
| 830 | QQuickMouseEvent &me = d->quickMouseEvent; | - | ||||||||||||||||||||||||
| 831 | me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, | - | ||||||||||||||||||||||||
| 832 | false, event->flags()); | - | ||||||||||||||||||||||||
| 833 | me.setSource(event->source()); | - | ||||||||||||||||||||||||
| 834 | me.setAccepted(d->isDoubleClickConnected()); | - | ||||||||||||||||||||||||
| 835 | emit this->doubleClicked(&me); | - | ||||||||||||||||||||||||
| 836 | if (!me.isAccepted())
| 16-22 | ||||||||||||||||||||||||
| 837 | d->propagate(&me, QQuickMouseAreaPrivate::DoubleClick); executed 22 times by 2 tests: d->propagate(&me, QQuickMouseAreaPrivate::DoubleClick);Executed by:
| 22 | ||||||||||||||||||||||||
| 838 | d->doubleClick = d->isDoubleClickConnected() || me.isAccepted();
| 2-20 | ||||||||||||||||||||||||
| 839 | } executed 38 times by 2 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||||||||
| 840 | QQuickItem::mouseDoubleClickEvent(event); | - | ||||||||||||||||||||||||
| 841 | } executed 38 times by 2 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||||||||
| 842 | - | |||||||||||||||||||||||||
| 843 | void QQuickMouseArea::hoverEnterEvent(QHoverEvent *event) | - | ||||||||||||||||||||||||
| 844 | { | - | ||||||||||||||||||||||||
| 845 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 846 | if (!d->enabled && !d->pressed) {
| 0-24 | ||||||||||||||||||||||||
| 847 | QQuickItem::hoverEnterEvent(event); | - | ||||||||||||||||||||||||
| 848 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 849 | d->lastPos = event->posF(); | - | ||||||||||||||||||||||||
| 850 | d->lastModifiers = event->modifiers(); | - | ||||||||||||||||||||||||
| 851 | setHovered(true); | - | ||||||||||||||||||||||||
| 852 | QQuickMouseEvent &me = d->quickMouseEvent; | - | ||||||||||||||||||||||||
| 853 | me.reset(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); | - | ||||||||||||||||||||||||
| 854 | emit mouseXChanged(&me); | - | ||||||||||||||||||||||||
| 855 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 856 | emit mouseYChanged(&me); | - | ||||||||||||||||||||||||
| 857 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 858 | } executed 24 times by 3 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||||||||
| 859 | } | - | ||||||||||||||||||||||||
| 860 | - | |||||||||||||||||||||||||
| 861 | void QQuickMouseArea::hoverMoveEvent(QHoverEvent *event) | - | ||||||||||||||||||||||||
| 862 | { | - | ||||||||||||||||||||||||
| 863 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 864 | if (!d->enabled && !d->pressed) {
| 0-12 | ||||||||||||||||||||||||
| 865 | QQuickItem::hoverMoveEvent(event); | - | ||||||||||||||||||||||||
| 866 | } else if (d->lastPos != event->posF()) { never executed: end of block
| 0-10 | ||||||||||||||||||||||||
| 867 | d->lastPos = event->posF(); | - | ||||||||||||||||||||||||
| 868 | d->lastModifiers = event->modifiers(); | - | ||||||||||||||||||||||||
| 869 | QQuickMouseEvent &me = d->quickMouseEvent; | - | ||||||||||||||||||||||||
| 870 | me.reset(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); | - | ||||||||||||||||||||||||
| 871 | emit mouseXChanged(&me); | - | ||||||||||||||||||||||||
| 872 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 873 | emit mouseYChanged(&me); | - | ||||||||||||||||||||||||
| 874 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 875 | emit positionChanged(&me); | - | ||||||||||||||||||||||||
| 876 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 877 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||
| 878 | - | |||||||||||||||||||||||||
| 879 | void QQuickMouseArea::hoverLeaveEvent(QHoverEvent *event) | - | ||||||||||||||||||||||||
| 880 | { | - | ||||||||||||||||||||||||
| 881 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 882 | if (!d->enabled && !d->pressed)
| 0-10 | ||||||||||||||||||||||||
| 883 | QQuickItem::hoverLeaveEvent(event); never executed: QQuickItem::hoverLeaveEvent(event); | 0 | ||||||||||||||||||||||||
| 884 | else | - | ||||||||||||||||||||||||
| 885 | setHovered(false); executed 10 times by 2 tests: setHovered(false);Executed by:
| 10 | ||||||||||||||||||||||||
| 886 | } | - | ||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||
| 888 | #if QT_CONFIG(wheelevent) | - | ||||||||||||||||||||||||
| 889 | void QQuickMouseArea::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||||||||
| 890 | { | - | ||||||||||||||||||||||||
| 891 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 892 | if (!d->enabled || (!isScrollGestureEnabled() && event->source() != Qt::MouseEventNotSynthesized)) {
| 0-2 | ||||||||||||||||||||||||
| 893 | QQuickItem::wheelEvent(event); | - | ||||||||||||||||||||||||
| 894 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 895 | } | - | ||||||||||||||||||||||||
| 896 | - | |||||||||||||||||||||||||
| 897 | QQuickWheelEvent &we = d->quickWheelEvent; | - | ||||||||||||||||||||||||
| 898 | we.reset(event->posF().x(), event->posF().y(), event->angleDelta(), event->pixelDelta(), | - | ||||||||||||||||||||||||
| 899 | event->buttons(), event->modifiers(), event->inverted()); | - | ||||||||||||||||||||||||
| 900 | we.setAccepted(d->isWheelConnected()); | - | ||||||||||||||||||||||||
| 901 | emit wheel(&we); | - | ||||||||||||||||||||||||
| 902 | if (!we.isAccepted())
| 0-2 | ||||||||||||||||||||||||
| 903 | QQuickItem::wheelEvent(event); never executed: QQuickItem::wheelEvent(event); | 0 | ||||||||||||||||||||||||
| 904 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 905 | #endif | - | ||||||||||||||||||||||||
| 906 | - | |||||||||||||||||||||||||
| 907 | void QQuickMouseArea::ungrabMouse() | - | ||||||||||||||||||||||||
| 908 | { | - | ||||||||||||||||||||||||
| 909 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 910 | if (d->pressed) {
| 40-426 | ||||||||||||||||||||||||
| 911 | // if our mouse grab has been removed (probably by Flickable), fix our | - | ||||||||||||||||||||||||
| 912 | // state | - | ||||||||||||||||||||||||
| 913 | d->pressed = Qt::NoButton; | - | ||||||||||||||||||||||||
| 914 | d->stealMouse = false; | - | ||||||||||||||||||||||||
| 915 | d->doubleClick = false; | - | ||||||||||||||||||||||||
| 916 | d->overThreshold = false; | - | ||||||||||||||||||||||||
| 917 | setKeepMouseGrab(false); | - | ||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||
| 919 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 920 | if (d->drag)
| 10-30 | ||||||||||||||||||||||||
| 921 | d->drag->setActive(false); executed 10 times by 1 test: d->drag->setActive(false);Executed by:
| 10 | ||||||||||||||||||||||||
| 922 | #endif | - | ||||||||||||||||||||||||
| 923 | - | |||||||||||||||||||||||||
| 924 | emit canceled(); | - | ||||||||||||||||||||||||
| 925 | emit pressedChanged(); | - | ||||||||||||||||||||||||
| 926 | emit containsPressChanged(); | - | ||||||||||||||||||||||||
| 927 | emit pressedButtonsChanged(); | - | ||||||||||||||||||||||||
| 928 | - | |||||||||||||||||||||||||
| 929 | if (d->hovered && !isUnderMouse()) {
| 0-38 | ||||||||||||||||||||||||
| 930 | d->hovered = false; | - | ||||||||||||||||||||||||
| 931 | emit hoveredChanged(); | - | ||||||||||||||||||||||||
| 932 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 933 | } executed 40 times by 4 tests: end of blockExecuted by:
| 40 | ||||||||||||||||||||||||
| 934 | } executed 466 times by 6 tests: end of blockExecuted by:
| 466 | ||||||||||||||||||||||||
| 935 | - | |||||||||||||||||||||||||
| 936 | void QQuickMouseArea::mouseUngrabEvent() | - | ||||||||||||||||||||||||
| 937 | { | - | ||||||||||||||||||||||||
| 938 | ungrabMouse(); | - | ||||||||||||||||||||||||
| 939 | } executed 248 times by 6 tests: end of blockExecuted by:
| 248 | ||||||||||||||||||||||||
| 940 | - | |||||||||||||||||||||||||
| 941 | bool QQuickMouseArea::sendMouseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 942 | { | - | ||||||||||||||||||||||||
| 943 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 944 | QPointF localPos = mapFromScene(event->windowPos()); | - | ||||||||||||||||||||||||
| 945 | - | |||||||||||||||||||||||||
| 946 | QQuickWindow *c = window(); | - | ||||||||||||||||||||||||
| 947 | QQuickItem *grabber = c ? c->mouseGrabberItem() : nullptr;
| 0-86 | ||||||||||||||||||||||||
| 948 | bool stealThisEvent = d->stealMouse; | - | ||||||||||||||||||||||||
| 949 | if ((stealThisEvent || contains(localPos)) && (!grabber || !grabber->keepMouseGrab())) {
| 0-62 | ||||||||||||||||||||||||
| 950 | QMouseEvent mouseEvent(event->type(), localPos, event->windowPos(), event->screenPos(), | - | ||||||||||||||||||||||||
| 951 | event->button(), event->buttons(), event->modifiers()); | - | ||||||||||||||||||||||||
| 952 | mouseEvent.setAccepted(false); | - | ||||||||||||||||||||||||
| 953 | - | |||||||||||||||||||||||||
| 954 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 955 | case QEvent::MouseMove: executed 38 times by 1 test: case QEvent::MouseMove:Executed by:
| 38 | ||||||||||||||||||||||||
| 956 | mouseMoveEvent(&mouseEvent); | - | ||||||||||||||||||||||||
| 957 | break; executed 38 times by 1 test: break;Executed by:
| 38 | ||||||||||||||||||||||||
| 958 | case QEvent::MouseButtonPress: executed 24 times by 1 test: case QEvent::MouseButtonPress:Executed by:
| 24 | ||||||||||||||||||||||||
| 959 | mousePressEvent(&mouseEvent); | - | ||||||||||||||||||||||||
| 960 | break; executed 24 times by 1 test: break;Executed by:
| 24 | ||||||||||||||||||||||||
| 961 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
| 962 | mouseReleaseEvent(&mouseEvent); | - | ||||||||||||||||||||||||
| 963 | stealThisEvent = d->stealMouse; | - | ||||||||||||||||||||||||
| 964 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 965 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 966 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 967 | } | - | ||||||||||||||||||||||||
| 968 | grabber = c ? c->mouseGrabberItem() : nullptr;
| 0-62 | ||||||||||||||||||||||||
| 969 | if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this)
| 0-38 | ||||||||||||||||||||||||
| 970 | grabMouse(); executed 10 times by 1 test: grabMouse();Executed by:
| 10 | ||||||||||||||||||||||||
| 971 | - | |||||||||||||||||||||||||
| 972 | return stealThisEvent; executed 62 times by 1 test: return stealThisEvent;Executed by:
| 62 | ||||||||||||||||||||||||
| 973 | } | - | ||||||||||||||||||||||||
| 974 | if (event->type() == QEvent::MouseButtonRelease) {
| 10-14 | ||||||||||||||||||||||||
| 975 | if (d->pressed) {
| 0-14 | ||||||||||||||||||||||||
| 976 | d->pressed &= ~event->button(); | - | ||||||||||||||||||||||||
| 977 | emit pressedButtonsChanged(); | - | ||||||||||||||||||||||||
| 978 | if (!d->pressed) {
| 0-14 | ||||||||||||||||||||||||
| 979 | // no other buttons are pressed | - | ||||||||||||||||||||||||
| 980 | d->stealMouse = false; | - | ||||||||||||||||||||||||
| 981 | d->overThreshold = false; | - | ||||||||||||||||||||||||
| 982 | if (c && c->mouseGrabberItem() == this)
| 0-14 | ||||||||||||||||||||||||
| 983 | ungrabMouse(); never executed: ungrabMouse(); | 0 | ||||||||||||||||||||||||
| 984 | emit canceled(); | - | ||||||||||||||||||||||||
| 985 | emit pressedChanged(); | - | ||||||||||||||||||||||||
| 986 | emit containsPressChanged(); | - | ||||||||||||||||||||||||
| 987 | if (d->hovered) {
| 0-14 | ||||||||||||||||||||||||
| 988 | d->hovered = false; | - | ||||||||||||||||||||||||
| 989 | emit hoveredChanged(); | - | ||||||||||||||||||||||||
| 990 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 991 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 992 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 993 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 994 | return false; executed 24 times by 1 test: return false;Executed by:
| 24 | ||||||||||||||||||||||||
| 995 | } | - | ||||||||||||||||||||||||
| 996 | - | |||||||||||||||||||||||||
| 997 | bool QQuickMouseArea::childMouseEventFilter(QQuickItem *i, QEvent *e) | - | ||||||||||||||||||||||||
| 998 | { | - | ||||||||||||||||||||||||
| 999 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1000 | if (!d->pressed &&
| 80-102 | ||||||||||||||||||||||||
| 1001 | (!d->enabled || !isVisible()
| 0-102 | ||||||||||||||||||||||||
| 1002 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 1003 | || !d->drag || !d->drag->filterChildren()
| 4-60 | ||||||||||||||||||||||||
| 1004 | #endif | - | ||||||||||||||||||||||||
| 1005 | ) | - | ||||||||||||||||||||||||
| 1006 | ) | - | ||||||||||||||||||||||||
| 1007 | return QQuickItem::childMouseEventFilter(i, e); executed 64 times by 3 tests: return QQuickItem::childMouseEventFilter(i, e);Executed by:
| 64 | ||||||||||||||||||||||||
| 1008 | switch (e->type()) { | - | ||||||||||||||||||||||||
| 1009 | case QEvent::MouseButtonPress: executed 24 times by 1 test: case QEvent::MouseButtonPress:Executed by:
| 24 | ||||||||||||||||||||||||
| 1010 | case QEvent::MouseMove: executed 48 times by 1 test: case QEvent::MouseMove:Executed by:
| 48 | ||||||||||||||||||||||||
| 1011 | case QEvent::MouseButtonRelease: executed 14 times by 1 test: case QEvent::MouseButtonRelease:Executed by:
| 14 | ||||||||||||||||||||||||
| 1012 | return sendMouseEvent(static_cast<QMouseEvent *>(e)); executed 86 times by 1 test: return sendMouseEvent(static_cast<QMouseEvent *>(e));Executed by:
| 86 | ||||||||||||||||||||||||
| 1013 | default: executed 32 times by 1 test: default:Executed by:
| 32 | ||||||||||||||||||||||||
| 1014 | break; executed 32 times by 1 test: break;Executed by:
| 32 | ||||||||||||||||||||||||
| 1015 | } | - | ||||||||||||||||||||||||
| 1016 | - | |||||||||||||||||||||||||
| 1017 | return QQuickItem::childMouseEventFilter(i, e); executed 32 times by 1 test: return QQuickItem::childMouseEventFilter(i, e);Executed by:
| 32 | ||||||||||||||||||||||||
| 1018 | } | - | ||||||||||||||||||||||||
| 1019 | - | |||||||||||||||||||||||||
| 1020 | void QQuickMouseArea::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||||||||
| 1021 | { | - | ||||||||||||||||||||||||
| 1022 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1023 | if (event->timerId() == d->pressAndHoldTimer.timerId()) {
| 0-26 | ||||||||||||||||||||||||
| 1024 | d->pressAndHoldTimer.stop(); | - | ||||||||||||||||||||||||
| 1025 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 1026 | bool dragged = d->drag && d->drag->active();
| 0-26 | ||||||||||||||||||||||||
| 1027 | #else | - | ||||||||||||||||||||||||
| 1028 | bool dragged = false; | - | ||||||||||||||||||||||||
| 1029 | #endif | - | ||||||||||||||||||||||||
| 1030 | if (d->pressed && dragged == false && d->hovered == true) {
| 0-22 | ||||||||||||||||||||||||
| 1031 | d->longPress = true; | - | ||||||||||||||||||||||||
| 1032 | QQuickMouseEvent &me = d->quickMouseEvent; | - | ||||||||||||||||||||||||
| 1033 | me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress, d->lastFlags); | - | ||||||||||||||||||||||||
| 1034 | me.setSource(Qt::MouseEventSynthesizedByQt); | - | ||||||||||||||||||||||||
| 1035 | me.setAccepted(d->isPressAndHoldConnected()); | - | ||||||||||||||||||||||||
| 1036 | emit pressAndHold(&me); | - | ||||||||||||||||||||||||
| 1037 | if (!me.isAccepted())
| 10-12 | ||||||||||||||||||||||||
| 1038 | d->propagate(&me, QQuickMouseAreaPrivate::PressAndHold); executed 12 times by 1 test: d->propagate(&me, QQuickMouseAreaPrivate::PressAndHold);Executed by:
| 12 | ||||||||||||||||||||||||
| 1039 | if (!me.isAccepted()) // no one handled the long press - allow click
| 8-14 | ||||||||||||||||||||||||
| 1040 | d->longPress = false; executed 8 times by 1 test: d->longPress = false;Executed by:
| 8 | ||||||||||||||||||||||||
| 1041 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||
| 1042 | } executed 26 times by 3 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||
| 1043 | } executed 26 times by 3 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||
| 1044 | - | |||||||||||||||||||||||||
| 1045 | void QQuickMouseArea::windowDeactivateEvent() | - | ||||||||||||||||||||||||
| 1046 | { | - | ||||||||||||||||||||||||
| 1047 | ungrabMouse(); | - | ||||||||||||||||||||||||
| 1048 | QQuickItem::windowDeactivateEvent(); | - | ||||||||||||||||||||||||
| 1049 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1050 | - | |||||||||||||||||||||||||
| 1051 | void QQuickMouseArea::geometryChanged(const QRectF &newGeometry, | - | ||||||||||||||||||||||||
| 1052 | const QRectF &oldGeometry) | - | ||||||||||||||||||||||||
| 1053 | { | - | ||||||||||||||||||||||||
| 1054 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1055 | QQuickItem::geometryChanged(newGeometry, oldGeometry); | - | ||||||||||||||||||||||||
| 1056 | - | |||||||||||||||||||||||||
| 1057 | if (d->lastScenePos.isNull)
| 1226-1992 | ||||||||||||||||||||||||
| 1058 | d->lastScenePos = mapToScene(d->lastPos); executed 1992 times by 19 tests: d->lastScenePos = mapToScene(d->lastPos);Executed by:
| 1992 | ||||||||||||||||||||||||
| 1059 | else if (newGeometry.x() != oldGeometry.x() || newGeometry.y() != oldGeometry.y())
| 116-1010 | ||||||||||||||||||||||||
| 1060 | d->lastPos = mapFromScene(d->lastScenePos); executed 332 times by 4 tests: d->lastPos = mapFromScene(d->lastScenePos);Executed by:
| 332 | ||||||||||||||||||||||||
| 1061 | } executed 3218 times by 19 tests: end of blockExecuted by:
| 3218 | ||||||||||||||||||||||||
| 1062 | - | |||||||||||||||||||||||||
| 1063 | void QQuickMouseArea::itemChange(ItemChange change, const ItemChangeData &value) | - | ||||||||||||||||||||||||
| 1064 | { | - | ||||||||||||||||||||||||
| 1065 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1066 | switch (change) { | - | ||||||||||||||||||||||||
| 1067 | case ItemVisibleHasChanged: executed 64 times by 4 tests: case ItemVisibleHasChanged:Executed by:
| 64 | ||||||||||||||||||||||||
| 1068 | if (acceptHoverEvents() && d->hovered != (isVisible() && isUnderMouse())) {
| 0-60 | ||||||||||||||||||||||||
| 1069 | if (!d->hovered) {
| 0-2 | ||||||||||||||||||||||||
| 1070 | QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition; | - | ||||||||||||||||||||||||
| 1071 | d->lastScenePos = d->window->mapFromGlobal(cursorPos.toPoint()); | - | ||||||||||||||||||||||||
| 1072 | d->lastPos = mapFromScene(d->lastScenePos); | - | ||||||||||||||||||||||||
| 1073 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1074 | setHovered(!d->hovered); | - | ||||||||||||||||||||||||
| 1075 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1076 | break; executed 64 times by 4 tests: break;Executed by:
| 64 | ||||||||||||||||||||||||
| 1077 | default: executed 8206 times by 23 tests: default:Executed by:
| 8206 | ||||||||||||||||||||||||
| 1078 | break; executed 8206 times by 23 tests: break;Executed by:
| 8206 | ||||||||||||||||||||||||
| 1079 | } | - | ||||||||||||||||||||||||
| 1080 | - | |||||||||||||||||||||||||
| 1081 | QQuickItem::itemChange(change, value); | - | ||||||||||||||||||||||||
| 1082 | } executed 8270 times by 23 tests: end of blockExecuted by:
| 8270 | ||||||||||||||||||||||||
| 1083 | - | |||||||||||||||||||||||||
| 1084 | /*! | - | ||||||||||||||||||||||||
| 1085 | \qmlproperty bool QtQuick::MouseArea::hoverEnabled | - | ||||||||||||||||||||||||
| 1086 | This property holds whether hover events are handled. | - | ||||||||||||||||||||||||
| 1087 | - | |||||||||||||||||||||||||
| 1088 | By default, mouse events are only handled in response to a button event, or when a button is | - | ||||||||||||||||||||||||
| 1089 | pressed. Hover enables handling of all mouse events even when no mouse button is | - | ||||||||||||||||||||||||
| 1090 | pressed. | - | ||||||||||||||||||||||||
| 1091 | - | |||||||||||||||||||||||||
| 1092 | This property affects the containsMouse property and the onEntered, onExited and | - | ||||||||||||||||||||||||
| 1093 | onPositionChanged signals. | - | ||||||||||||||||||||||||
| 1094 | */ | - | ||||||||||||||||||||||||
| 1095 | bool QQuickMouseArea::hoverEnabled() const | - | ||||||||||||||||||||||||
| 1096 | { | - | ||||||||||||||||||||||||
| 1097 | return acceptHoverEvents(); executed 24 times by 1 test: return acceptHoverEvents();Executed by:
| 24 | ||||||||||||||||||||||||
| 1098 | } | - | ||||||||||||||||||||||||
| 1099 | - | |||||||||||||||||||||||||
| 1100 | void QQuickMouseArea::setHoverEnabled(bool h) | - | ||||||||||||||||||||||||
| 1101 | { | - | ||||||||||||||||||||||||
| 1102 | if (h == acceptHoverEvents())
| 2-162 | ||||||||||||||||||||||||
| 1103 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 1104 | - | |||||||||||||||||||||||||
| 1105 | setAcceptHoverEvents(h); | - | ||||||||||||||||||||||||
| 1106 | emit hoverEnabledChanged(); | - | ||||||||||||||||||||||||
| 1107 | } executed 162 times by 5 tests: end of blockExecuted by:
| 162 | ||||||||||||||||||||||||
| 1108 | - | |||||||||||||||||||||||||
| 1109 | - | |||||||||||||||||||||||||
| 1110 | /*! | - | ||||||||||||||||||||||||
| 1111 | \qmlproperty bool QtQuick::MouseArea::containsMouse | - | ||||||||||||||||||||||||
| 1112 | This property holds whether the mouse is currently inside the mouse area. | - | ||||||||||||||||||||||||
| 1113 | - | |||||||||||||||||||||||||
| 1114 | \warning If hoverEnabled is false, containsMouse will only be valid | - | ||||||||||||||||||||||||
| 1115 | when the mouse is pressed while the mouse cursor is inside the MouseArea. | - | ||||||||||||||||||||||||
| 1116 | */ | - | ||||||||||||||||||||||||
| 1117 | bool QQuickMouseArea::hovered() const | - | ||||||||||||||||||||||||
| 1118 | { | - | ||||||||||||||||||||||||
| 1119 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1120 | return d->hovered; executed 224 times by 4 tests: return d->hovered;Executed by:
| 224 | ||||||||||||||||||||||||
| 1121 | } | - | ||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||
| 1123 | /*! | - | ||||||||||||||||||||||||
| 1124 | \qmlproperty bool QtQuick::MouseArea::pressed | - | ||||||||||||||||||||||||
| 1125 | This property holds whether any of the \l acceptedButtons are currently pressed. | - | ||||||||||||||||||||||||
| 1126 | */ | - | ||||||||||||||||||||||||
| 1127 | bool QQuickMouseArea::pressed() const | - | ||||||||||||||||||||||||
| 1128 | { | - | ||||||||||||||||||||||||
| 1129 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1130 | return d->pressed; executed 688 times by 8 tests: return d->pressed;Executed by:
| 688 | ||||||||||||||||||||||||
| 1131 | } | - | ||||||||||||||||||||||||
| 1132 | - | |||||||||||||||||||||||||
| 1133 | /*! | - | ||||||||||||||||||||||||
| 1134 | \qmlproperty bool QtQuick::MouseArea::containsPress | - | ||||||||||||||||||||||||
| 1135 | \since 5.4 | - | ||||||||||||||||||||||||
| 1136 | This is a convenience property equivalent to \c {pressed && containsMouse}, | - | ||||||||||||||||||||||||
| 1137 | i.e. it holds whether any of the \l acceptedButtons are currently pressed | - | ||||||||||||||||||||||||
| 1138 | and the mouse is currently within the MouseArea. | - | ||||||||||||||||||||||||
| 1139 | - | |||||||||||||||||||||||||
| 1140 | This property is particularly useful for highlighting an item while the mouse | - | ||||||||||||||||||||||||
| 1141 | is pressed within its bounds. | - | ||||||||||||||||||||||||
| 1142 | - | |||||||||||||||||||||||||
| 1143 | \sa pressed, containsMouse | - | ||||||||||||||||||||||||
| 1144 | */ | - | ||||||||||||||||||||||||
| 1145 | bool QQuickMouseArea::containsPress() const | - | ||||||||||||||||||||||||
| 1146 | { | - | ||||||||||||||||||||||||
| 1147 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1148 | return d->pressed && d->hovered; executed 68 times by 2 tests: return d->pressed && d->hovered;Executed by:
| 68 | ||||||||||||||||||||||||
| 1149 | } | - | ||||||||||||||||||||||||
| 1150 | - | |||||||||||||||||||||||||
| 1151 | void QQuickMouseArea::setHovered(bool h) | - | ||||||||||||||||||||||||
| 1152 | { | - | ||||||||||||||||||||||||
| 1153 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1154 | if (d->hovered != h) {
| 427-510 | ||||||||||||||||||||||||
| 1155 | qCDebug(DBG_HOVER_TRACE) << this << d->hovered << "->" << h; never executed: QMessageLogger(__FILE__, 1155, __PRETTY_FUNCTION__, DBG_HOVER_TRACE().categoryName()).debug() << this << d->hovered << "->" << h;
| 0-510 | ||||||||||||||||||||||||
| 1156 | d->hovered = h; | - | ||||||||||||||||||||||||
| 1157 | emit hoveredChanged(); | - | ||||||||||||||||||||||||
| 1158 | d->hovered ? emit entered() : emit exited(); | - | ||||||||||||||||||||||||
| 1159 | if (d->pressed)
| 22-488 | ||||||||||||||||||||||||
| 1160 | emit containsPressChanged(); executed 22 times by 3 tests: containsPressChanged();Executed by:
| 22 | ||||||||||||||||||||||||
| 1161 | } executed 510 times by 8 tests: end of blockExecuted by:
| 510 | ||||||||||||||||||||||||
| 1162 | } executed 937 times by 8 tests: end of blockExecuted by:
| 937 | ||||||||||||||||||||||||
| 1163 | - | |||||||||||||||||||||||||
| 1164 | /*! | - | ||||||||||||||||||||||||
| 1165 | \qmlproperty Qt::MouseButtons QtQuick::MouseArea::acceptedButtons | - | ||||||||||||||||||||||||
| 1166 | This property holds the mouse buttons that the mouse area reacts to. | - | ||||||||||||||||||||||||
| 1167 | - | |||||||||||||||||||||||||
| 1168 | To specify that the MouseArea will react to multiple buttons, | - | ||||||||||||||||||||||||
| 1169 | Qt::MouseButtons flag values are combined using the "|" (or) operator: | - | ||||||||||||||||||||||||
| 1170 | - | |||||||||||||||||||||||||
| 1171 | \code | - | ||||||||||||||||||||||||
| 1172 | MouseArea { acceptedButtons: Qt.LeftButton | Qt.RightButton } | - | ||||||||||||||||||||||||
| 1173 | \endcode | - | ||||||||||||||||||||||||
| 1174 | - | |||||||||||||||||||||||||
| 1175 | To indicate that all possible mouse buttons are to be accepted, | - | ||||||||||||||||||||||||
| 1176 | the special value 'Qt.AllButtons' may be used: | - | ||||||||||||||||||||||||
| 1177 | - | |||||||||||||||||||||||||
| 1178 | \code | - | ||||||||||||||||||||||||
| 1179 | MouseArea { acceptedButtons: Qt.AllButtons } | - | ||||||||||||||||||||||||
| 1180 | \endcode | - | ||||||||||||||||||||||||
| 1181 | - | |||||||||||||||||||||||||
| 1182 | The default value is \c Qt.LeftButton. | - | ||||||||||||||||||||||||
| 1183 | */ | - | ||||||||||||||||||||||||
| 1184 | Qt::MouseButtons QQuickMouseArea::acceptedButtons() const | - | ||||||||||||||||||||||||
| 1185 | { | - | ||||||||||||||||||||||||
| 1186 | return acceptedMouseButtons(); executed 24 times by 1 test: return acceptedMouseButtons();Executed by:
| 24 | ||||||||||||||||||||||||
| 1187 | } | - | ||||||||||||||||||||||||
| 1188 | - | |||||||||||||||||||||||||
| 1189 | void QQuickMouseArea::setAcceptedButtons(Qt::MouseButtons buttons) | - | ||||||||||||||||||||||||
| 1190 | { | - | ||||||||||||||||||||||||
| 1191 | if (buttons != acceptedMouseButtons()) {
| 16-54 | ||||||||||||||||||||||||
| 1192 | setAcceptedMouseButtons(buttons); | - | ||||||||||||||||||||||||
| 1193 | emit acceptedButtonsChanged(); | - | ||||||||||||||||||||||||
| 1194 | } executed 54 times by 4 tests: end of blockExecuted by:
| 54 | ||||||||||||||||||||||||
| 1195 | } executed 70 times by 4 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||||||||
| 1196 | - | |||||||||||||||||||||||||
| 1197 | bool QQuickMouseArea::setPressed(Qt::MouseButton button, bool p, Qt::MouseEventSource source) | - | ||||||||||||||||||||||||
| 1198 | { | - | ||||||||||||||||||||||||
| 1199 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1200 | - | |||||||||||||||||||||||||
| 1201 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 1202 | bool dragged = d->drag && d->drag->active();
| 58-376 | ||||||||||||||||||||||||
| 1203 | #else | - | ||||||||||||||||||||||||
| 1204 | bool dragged = false; | - | ||||||||||||||||||||||||
| 1205 | #endif | - | ||||||||||||||||||||||||
| 1206 | bool wasPressed = d->pressed & button; | - | ||||||||||||||||||||||||
| 1207 | bool isclick = wasPressed && p == false && dragged == false && d->hovered == true;
| 2-286 | ||||||||||||||||||||||||
| 1208 | Qt::MouseButtons oldPressed = d->pressed; | - | ||||||||||||||||||||||||
| 1209 | - | |||||||||||||||||||||||||
| 1210 | if (wasPressed != p) {
| 6-508 | ||||||||||||||||||||||||
| 1211 | QQuickMouseEvent &me = d->quickMouseEvent; | - | ||||||||||||||||||||||||
| 1212 | me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress, d->lastFlags); | - | ||||||||||||||||||||||||
| 1213 | me.setSource(source); | - | ||||||||||||||||||||||||
| 1214 | if (p) {
| 222-286 | ||||||||||||||||||||||||
| 1215 | d->pressed |= button; | - | ||||||||||||||||||||||||
| 1216 | if (!d->doubleClick)
| 0-286 | ||||||||||||||||||||||||
| 1217 | emit pressed(&me); executed 286 times by 6 tests: pressed(&me);Executed by:
| 286 | ||||||||||||||||||||||||
| 1218 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 1219 | emit mouseXChanged(&me); | - | ||||||||||||||||||||||||
| 1220 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 1221 | emit mouseYChanged(&me); | - | ||||||||||||||||||||||||
| 1222 | - | |||||||||||||||||||||||||
| 1223 | if (!me.isAccepted()) {
| 10-276 | ||||||||||||||||||||||||
| 1224 | d->pressed = Qt::NoButton; | - | ||||||||||||||||||||||||
| 1225 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 1226 | - | |||||||||||||||||||||||||
| 1227 | if (!oldPressed) {
| 2-284 | ||||||||||||||||||||||||
| 1228 | emit pressedChanged(); | - | ||||||||||||||||||||||||
| 1229 | emit containsPressChanged(); | - | ||||||||||||||||||||||||
| 1230 | } executed 284 times by 6 tests: end of blockExecuted by:
| 284 | ||||||||||||||||||||||||
| 1231 | emit pressedButtonsChanged(); | - | ||||||||||||||||||||||||
| 1232 | } else { executed 286 times by 6 tests: end of blockExecuted by:
| 286 | ||||||||||||||||||||||||
| 1233 | d->pressed &= ~button; | - | ||||||||||||||||||||||||
| 1234 | emit released(&me); | - | ||||||||||||||||||||||||
| 1235 | me.setPosition(d->lastPos); | - | ||||||||||||||||||||||||
| 1236 | if (!d->pressed) {
| 2-220 | ||||||||||||||||||||||||
| 1237 | emit pressedChanged(); | - | ||||||||||||||||||||||||
| 1238 | emit containsPressChanged(); | - | ||||||||||||||||||||||||
| 1239 | } executed 220 times by 6 tests: end of blockExecuted by:
| 220 | ||||||||||||||||||||||||
| 1240 | emit pressedButtonsChanged(); | - | ||||||||||||||||||||||||
| 1241 | if (isclick && !d->longPress && !d->doubleClick){
| 14-162 | ||||||||||||||||||||||||
| 1242 | me.setAccepted(d->isClickConnected()); | - | ||||||||||||||||||||||||
| 1243 | emit clicked(&me); | - | ||||||||||||||||||||||||
| 1244 | if (!me.isAccepted())
| 54-74 | ||||||||||||||||||||||||
| 1245 | d->propagate(&me, QQuickMouseAreaPrivate::Click); executed 74 times by 3 tests: d->propagate(&me, QQuickMouseAreaPrivate::Click);Executed by:
| 74 | ||||||||||||||||||||||||
| 1246 | } executed 128 times by 4 tests: end of blockExecuted by:
| 128 | ||||||||||||||||||||||||
| 1247 | } executed 222 times by 6 tests: end of blockExecuted by:
| 222 | ||||||||||||||||||||||||
| 1248 | - | |||||||||||||||||||||||||
| 1249 | return me.isAccepted(); executed 508 times by 6 tests: return me.isAccepted();Executed by:
| 508 | ||||||||||||||||||||||||
| 1250 | } | - | ||||||||||||||||||||||||
| 1251 | return false; executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||||||||||||||
| 1252 | } | - | ||||||||||||||||||||||||
| 1253 | - | |||||||||||||||||||||||||
| 1254 | - | |||||||||||||||||||||||||
| 1255 | /*! | - | ||||||||||||||||||||||||
| 1256 | \qmlproperty Qt::CursorShape QtQuick::MouseArea::cursorShape | - | ||||||||||||||||||||||||
| 1257 | This property holds the cursor shape for this mouse area. | - | ||||||||||||||||||||||||
| 1258 | Note that on platforms that do not display a mouse cursor this may have | - | ||||||||||||||||||||||||
| 1259 | no effect. | - | ||||||||||||||||||||||||
| 1260 | - | |||||||||||||||||||||||||
| 1261 | The available cursor shapes are: | - | ||||||||||||||||||||||||
| 1262 | \list | - | ||||||||||||||||||||||||
| 1263 | \li Qt.ArrowCursor | - | ||||||||||||||||||||||||
| 1264 | \li Qt.UpArrowCursor | - | ||||||||||||||||||||||||
| 1265 | \li Qt.CrossCursor | - | ||||||||||||||||||||||||
| 1266 | \li Qt.WaitCursor | - | ||||||||||||||||||||||||
| 1267 | \li Qt.IBeamCursor | - | ||||||||||||||||||||||||
| 1268 | \li Qt.SizeVerCursor | - | ||||||||||||||||||||||||
| 1269 | \li Qt.SizeHorCursor | - | ||||||||||||||||||||||||
| 1270 | \li Qt.SizeBDiagCursor | - | ||||||||||||||||||||||||
| 1271 | \li Qt.SizeFDiagCursor | - | ||||||||||||||||||||||||
| 1272 | \li Qt.SizeAllCursor | - | ||||||||||||||||||||||||
| 1273 | \li Qt.BlankCursor | - | ||||||||||||||||||||||||
| 1274 | \li Qt.SplitVCursor | - | ||||||||||||||||||||||||
| 1275 | \li Qt.SplitHCursor | - | ||||||||||||||||||||||||
| 1276 | \li Qt.PointingHandCursor | - | ||||||||||||||||||||||||
| 1277 | \li Qt.ForbiddenCursor | - | ||||||||||||||||||||||||
| 1278 | \li Qt.WhatsThisCursor | - | ||||||||||||||||||||||||
| 1279 | \li Qt.BusyCursor | - | ||||||||||||||||||||||||
| 1280 | \li Qt.OpenHandCursor | - | ||||||||||||||||||||||||
| 1281 | \li Qt.ClosedHandCursor | - | ||||||||||||||||||||||||
| 1282 | \li Qt.DragCopyCursor | - | ||||||||||||||||||||||||
| 1283 | \li Qt.DragMoveCursor | - | ||||||||||||||||||||||||
| 1284 | \li Qt.DragLinkCursor | - | ||||||||||||||||||||||||
| 1285 | \endlist | - | ||||||||||||||||||||||||
| 1286 | - | |||||||||||||||||||||||||
| 1287 | In order to only set a mouse cursor shape for a region without reacting | - | ||||||||||||||||||||||||
| 1288 | to mouse events set the acceptedButtons to none: | - | ||||||||||||||||||||||||
| 1289 | - | |||||||||||||||||||||||||
| 1290 | \code | - | ||||||||||||||||||||||||
| 1291 | MouseArea { cursorShape: Qt.IBeamCursor; acceptedButtons: Qt.NoButton } | - | ||||||||||||||||||||||||
| 1292 | \endcode | - | ||||||||||||||||||||||||
| 1293 | - | |||||||||||||||||||||||||
| 1294 | The default value is \c Qt.ArrowCursor. | - | ||||||||||||||||||||||||
| 1295 | \sa Qt::CursorShape | - | ||||||||||||||||||||||||
| 1296 | */ | - | ||||||||||||||||||||||||
| 1297 | - | |||||||||||||||||||||||||
| 1298 | #if QT_CONFIG(cursor) | - | ||||||||||||||||||||||||
| 1299 | Qt::CursorShape QQuickMouseArea::cursorShape() const | - | ||||||||||||||||||||||||
| 1300 | { | - | ||||||||||||||||||||||||
| 1301 | return cursor().shape(); executed 30 times by 2 tests: return cursor().shape();Executed by:
| 30 | ||||||||||||||||||||||||
| 1302 | } | - | ||||||||||||||||||||||||
| 1303 | - | |||||||||||||||||||||||||
| 1304 | void QQuickMouseArea::setCursorShape(Qt::CursorShape shape) | - | ||||||||||||||||||||||||
| 1305 | { | - | ||||||||||||||||||||||||
| 1306 | if (cursor().shape() == shape)
| 2-4 | ||||||||||||||||||||||||
| 1307 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 1308 | - | |||||||||||||||||||||||||
| 1309 | setCursor(shape); | - | ||||||||||||||||||||||||
| 1310 | - | |||||||||||||||||||||||||
| 1311 | emit cursorShapeChanged(); | - | ||||||||||||||||||||||||
| 1312 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 1313 | - | |||||||||||||||||||||||||
| 1314 | #endif | - | ||||||||||||||||||||||||
| 1315 | - | |||||||||||||||||||||||||
| 1316 | - | |||||||||||||||||||||||||
| 1317 | /*! | - | ||||||||||||||||||||||||
| 1318 | \qmlproperty int QtQuick::MouseArea::pressAndHoldInterval | - | ||||||||||||||||||||||||
| 1319 | \since 5.9 | - | ||||||||||||||||||||||||
| 1320 | - | |||||||||||||||||||||||||
| 1321 | This property overrides the elapsed time in milliseconds before | - | ||||||||||||||||||||||||
| 1322 | \c pressAndHold is emitted. | - | ||||||||||||||||||||||||
| 1323 | - | |||||||||||||||||||||||||
| 1324 | If not explicitly set -- or after reset -- the value follows | - | ||||||||||||||||||||||||
| 1325 | \c QStyleHints::mousePressAndHoldInterval. | - | ||||||||||||||||||||||||
| 1326 | - | |||||||||||||||||||||||||
| 1327 | Typically it's sufficient to set this property globally using the | - | ||||||||||||||||||||||||
| 1328 | application style hint. This property should be used when varying intervals | - | ||||||||||||||||||||||||
| 1329 | are needed for certain MouseAreas. | - | ||||||||||||||||||||||||
| 1330 | - | |||||||||||||||||||||||||
| 1331 | \sa pressAndHold | - | ||||||||||||||||||||||||
| 1332 | */ | - | ||||||||||||||||||||||||
| 1333 | int QQuickMouseArea::pressAndHoldInterval() const | - | ||||||||||||||||||||||||
| 1334 | { | - | ||||||||||||||||||||||||
| 1335 | Q_D(const QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1336 | return d->pressAndHoldInterval > -1 ? executed 300 times by 7 tests: return d->pressAndHoldInterval > -1 ? d->pressAndHoldInterval : QGuiApplication::styleHints()->mousePressAndHoldInterval();Executed by:
| 300 | ||||||||||||||||||||||||
| 1337 | d->pressAndHoldInterval : QGuiApplication::styleHints()->mousePressAndHoldInterval(); executed 300 times by 7 tests: return d->pressAndHoldInterval > -1 ? d->pressAndHoldInterval : QGuiApplication::styleHints()->mousePressAndHoldInterval();Executed by:
| 300 | ||||||||||||||||||||||||
| 1338 | } | - | ||||||||||||||||||||||||
| 1339 | - | |||||||||||||||||||||||||
| 1340 | void QQuickMouseArea::setPressAndHoldInterval(int interval) | - | ||||||||||||||||||||||||
| 1341 | { | - | ||||||||||||||||||||||||
| 1342 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1343 | if (interval != d->pressAndHoldInterval) {
| 0-4 | ||||||||||||||||||||||||
| 1344 | d->pressAndHoldInterval = interval; | - | ||||||||||||||||||||||||
| 1345 | emit pressAndHoldIntervalChanged(); | - | ||||||||||||||||||||||||
| 1346 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 1347 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 1348 | - | |||||||||||||||||||||||||
| 1349 | void QQuickMouseArea::resetPressAndHoldInterval() | - | ||||||||||||||||||||||||
| 1350 | { | - | ||||||||||||||||||||||||
| 1351 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1352 | if (d->pressAndHoldInterval > -1) {
| 0-2 | ||||||||||||||||||||||||
| 1353 | d->pressAndHoldInterval = -1; | - | ||||||||||||||||||||||||
| 1354 | emit pressAndHoldIntervalChanged(); | - | ||||||||||||||||||||||||
| 1355 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1356 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1357 | - | |||||||||||||||||||||||||
| 1358 | /*! | - | ||||||||||||||||||||||||
| 1359 | \qmlpropertygroup QtQuick::MouseArea::drag | - | ||||||||||||||||||||||||
| 1360 | \qmlproperty Item QtQuick::MouseArea::drag.target | - | ||||||||||||||||||||||||
| 1361 | \qmlproperty bool QtQuick::MouseArea::drag.active | - | ||||||||||||||||||||||||
| 1362 | \qmlproperty enumeration QtQuick::MouseArea::drag.axis | - | ||||||||||||||||||||||||
| 1363 | \qmlproperty real QtQuick::MouseArea::drag.minimumX | - | ||||||||||||||||||||||||
| 1364 | \qmlproperty real QtQuick::MouseArea::drag.maximumX | - | ||||||||||||||||||||||||
| 1365 | \qmlproperty real QtQuick::MouseArea::drag.minimumY | - | ||||||||||||||||||||||||
| 1366 | \qmlproperty real QtQuick::MouseArea::drag.maximumY | - | ||||||||||||||||||||||||
| 1367 | \qmlproperty bool QtQuick::MouseArea::drag.filterChildren | - | ||||||||||||||||||||||||
| 1368 | \qmlproperty real QtQuick::MouseArea::drag.threshold | - | ||||||||||||||||||||||||
| 1369 | - | |||||||||||||||||||||||||
| 1370 | \c drag provides a convenient way to make an item draggable. | - | ||||||||||||||||||||||||
| 1371 | - | |||||||||||||||||||||||||
| 1372 | \list | - | ||||||||||||||||||||||||
| 1373 | \li \c drag.target specifies the id of the item to drag. | - | ||||||||||||||||||||||||
| 1374 | \li \c drag.active specifies if the target item is currently being dragged. | - | ||||||||||||||||||||||||
| 1375 | \li \c drag.axis specifies whether dragging can be done horizontally (\c Drag.XAxis), vertically (\c Drag.YAxis), or both (\c Drag.XAndYAxis) | - | ||||||||||||||||||||||||
| 1376 | \li \c drag.minimum and \c drag.maximum limit how far the target can be dragged along the corresponding axes. | - | ||||||||||||||||||||||||
| 1377 | \endlist | - | ||||||||||||||||||||||||
| 1378 | - | |||||||||||||||||||||||||
| 1379 | The following example displays a \l Rectangle that can be dragged along the X-axis. The opacity | - | ||||||||||||||||||||||||
| 1380 | of the rectangle is reduced when it is dragged to the right. | - | ||||||||||||||||||||||||
| 1381 | - | |||||||||||||||||||||||||
| 1382 | \snippet qml/mousearea/mousearea.qml drag | - | ||||||||||||||||||||||||
| 1383 | - | |||||||||||||||||||||||||
| 1384 | \note Items cannot be dragged if they are anchored for the requested | - | ||||||||||||||||||||||||
| 1385 | \c drag.axis. For example, if \c anchors.left or \c anchors.right was set | - | ||||||||||||||||||||||||
| 1386 | for \c rect in the above example, it cannot be dragged along the X-axis. | - | ||||||||||||||||||||||||
| 1387 | This can be avoided by settng the anchor value to \c undefined in | - | ||||||||||||||||||||||||
| 1388 | an \l {pressed}{onPressed} handler. | - | ||||||||||||||||||||||||
| 1389 | - | |||||||||||||||||||||||||
| 1390 | If \c drag.filterChildren is set to true, a drag can override descendant MouseAreas. This | - | ||||||||||||||||||||||||
| 1391 | enables a parent MouseArea to handle drags, for example, while descendants handle clicks: | - | ||||||||||||||||||||||||
| 1392 | - | |||||||||||||||||||||||||
| 1393 | \c drag.threshold determines the threshold in pixels of when the drag operation should | - | ||||||||||||||||||||||||
| 1394 | start. By default this is bound to a platform dependent value. This property was added in | - | ||||||||||||||||||||||||
| 1395 | Qt Quick 2.2. | - | ||||||||||||||||||||||||
| 1396 | - | |||||||||||||||||||||||||
| 1397 | If \c drag.smoothed is \c true, the target will be moved only after the drag operation has | - | ||||||||||||||||||||||||
| 1398 | started. If set to \c false, the target will be moved straight to the current mouse position. | - | ||||||||||||||||||||||||
| 1399 | By default, this property is \c true. This property was added in Qt Quick 2.4 | - | ||||||||||||||||||||||||
| 1400 | - | |||||||||||||||||||||||||
| 1401 | See the \l Drag attached property and \l DropArea if you want to make a drop. | - | ||||||||||||||||||||||||
| 1402 | - | |||||||||||||||||||||||||
| 1403 | \snippet qml/mousearea/mouseareadragfilter.qml dragfilter | - | ||||||||||||||||||||||||
| 1404 | - | |||||||||||||||||||||||||
| 1405 | */ | - | ||||||||||||||||||||||||
| 1406 | - | |||||||||||||||||||||||||
| 1407 | #if QT_CONFIG(draganddrop) | - | ||||||||||||||||||||||||
| 1408 | QQuickDrag *QQuickMouseArea::drag() | - | ||||||||||||||||||||||||
| 1409 | { | - | ||||||||||||||||||||||||
| 1410 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1411 | if (!d->drag)
| 452-3098 | ||||||||||||||||||||||||
| 1412 | d->drag = new QQuickDrag; executed 452 times by 6 tests: d->drag = new QQuickDrag;Executed by:
| 452 | ||||||||||||||||||||||||
| 1413 | return d->drag; executed 3550 times by 6 tests: return d->drag;Executed by:
| 3550 | ||||||||||||||||||||||||
| 1414 | } | - | ||||||||||||||||||||||||
| 1415 | #endif | - | ||||||||||||||||||||||||
| 1416 | - | |||||||||||||||||||||||||
| 1417 | QSGNode *QQuickMouseArea::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) | - | ||||||||||||||||||||||||
| 1418 | { | - | ||||||||||||||||||||||||
| 1419 | Q_UNUSED(data); | - | ||||||||||||||||||||||||
| 1420 | Q_D(QQuickMouseArea); | - | ||||||||||||||||||||||||
| 1421 | - | |||||||||||||||||||||||||
| 1422 | if (!qmlVisualTouchDebugging())
| 0 | ||||||||||||||||||||||||
| 1423 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||||||||
| 1424 | - | |||||||||||||||||||||||||
| 1425 | QSGInternalRectangleNode *rectangle = static_cast<QSGInternalRectangleNode *>(oldNode); | - | ||||||||||||||||||||||||
| 1426 | if (!rectangle) rectangle = d->sceneGraphContext()->createInternalRectangleNode(); never executed: rectangle = d->sceneGraphContext()->createInternalRectangleNode();
| 0 | ||||||||||||||||||||||||
| 1427 | - | |||||||||||||||||||||||||
| 1428 | rectangle->setRect(QRectF(0, 0, width(), height())); | - | ||||||||||||||||||||||||
| 1429 | rectangle->setColor(QColor(255, 0, 0, 50)); | - | ||||||||||||||||||||||||
| 1430 | rectangle->update(); | - | ||||||||||||||||||||||||
| 1431 | return rectangle; never executed: return rectangle; | 0 | ||||||||||||||||||||||||
| 1432 | } | - | ||||||||||||||||||||||||
| 1433 | - | |||||||||||||||||||||||||
| 1434 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 1435 | - | |||||||||||||||||||||||||
| 1436 | #include "moc_qquickmousearea_p.cpp" | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |