| 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 | #ifndef QQUICKMOUSEAREA_P_H |
| 41 | #define QQUICKMOUSEAREA_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include "qquickitem.h" |
| 55 | #include <private/qtquickglobal_p.h> |
| 56 | #include <QtCore/qstringlist.h> |
| 57 | |
| 58 | QT_BEGIN_NAMESPACE |
| 59 | |
| 60 | class QQuickMouseEvent; |
| 61 | class QQuickDrag; |
| 62 | class QQuickMouseAreaPrivate; |
| 63 | class QQuickWheelEvent; |
| 64 | // used in Qt Location |
| 65 | class Q_QUICK_PRIVATE_EXPORT QQuickMouseArea : public QQuickItem |
| 66 | { |
| 67 | Q_OBJECT |
| 68 | |
| 69 | Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mouseXChanged) |
| 70 | Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mouseYChanged) |
| 71 | Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) |
| 72 | Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) |
| 73 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) |
| 74 | Q_PROPERTY(bool scrollGestureEnabled READ isScrollGestureEnabled WRITE setScrollGestureEnabled NOTIFY scrollGestureEnabledChanged REVISION 5) |
| 75 | Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedButtonsChanged) |
| 76 | Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) |
| 77 | Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) |
| 78 | #if QT_CONFIG(quick_draganddrop) |
| 79 | Q_PROPERTY(QQuickDrag *drag READ drag CONSTANT) //### add flicking to QQuickDrag or add a QQuickFlick ??? |
| 80 | #endif |
| 81 | Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged) |
| 82 | Q_PROPERTY(bool propagateComposedEvents READ propagateComposedEvents WRITE setPropagateComposedEvents NOTIFY propagateComposedEventsChanged) |
| 83 | #if QT_CONFIG(cursor) |
| 84 | Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET unsetCursor NOTIFY cursorShapeChanged) |
| 85 | #endif |
| 86 | Q_PROPERTY(bool containsPress READ containsPress NOTIFY containsPressChanged REVISION 4) |
| 87 | Q_PROPERTY(int pressAndHoldInterval READ pressAndHoldInterval WRITE setPressAndHoldInterval NOTIFY pressAndHoldIntervalChanged RESET resetPressAndHoldInterval REVISION 9) |
| 88 | QML_NAMED_ELEMENT(MouseArea) |
| 89 | |
| 90 | public: |
| 91 | QQuickMouseArea(QQuickItem *parent=nullptr); |
| 92 | ~QQuickMouseArea(); |
| 93 | |
| 94 | qreal mouseX() const; |
| 95 | qreal mouseY() const; |
| 96 | |
| 97 | bool isEnabled() const; |
| 98 | void setEnabled(bool); |
| 99 | |
| 100 | bool isScrollGestureEnabled() const; |
| 101 | void setScrollGestureEnabled(bool); |
| 102 | |
| 103 | bool hovered() const; |
| 104 | bool pressed() const; |
| 105 | bool containsPress() const; |
| 106 | |
| 107 | Qt::MouseButtons pressedButtons() const; |
| 108 | |
| 109 | Qt::MouseButtons acceptedButtons() const; |
| 110 | void setAcceptedButtons(Qt::MouseButtons buttons); |
| 111 | |
| 112 | bool hoverEnabled() const; |
| 113 | void setHoverEnabled(bool h); |
| 114 | |
| 115 | #if QT_CONFIG(quick_draganddrop) |
| 116 | QQuickDrag *drag(); |
| 117 | #endif |
| 118 | |
| 119 | bool preventStealing() const; |
| 120 | void setPreventStealing(bool prevent); |
| 121 | |
| 122 | bool propagateComposedEvents() const; |
| 123 | void setPropagateComposedEvents(bool propagate); |
| 124 | |
| 125 | #if QT_CONFIG(cursor) |
| 126 | Qt::CursorShape cursorShape() const; |
| 127 | void setCursorShape(Qt::CursorShape shape); |
| 128 | #endif |
| 129 | |
| 130 | int pressAndHoldInterval() const; |
| 131 | void setPressAndHoldInterval(int interval); |
| 132 | void resetPressAndHoldInterval(); |
| 133 | |
| 134 | Q_SIGNALS: |
| 135 | void hoveredChanged(); |
| 136 | void pressedChanged(); |
| 137 | void enabledChanged(); |
| 138 | Q_REVISION(5) void scrollGestureEnabledChanged(); |
| 139 | void pressedButtonsChanged(); |
| 140 | void acceptedButtonsChanged(); |
| 141 | void hoverEnabledChanged(); |
| 142 | #if QT_CONFIG(cursor) |
| 143 | void cursorShapeChanged(); |
| 144 | #endif |
| 145 | void positionChanged(QQuickMouseEvent *mouse); |
| 146 | void mouseXChanged(QQuickMouseEvent *mouse); |
| 147 | void mouseYChanged(QQuickMouseEvent *mouse); |
| 148 | void preventStealingChanged(); |
| 149 | void propagateComposedEventsChanged(); |
| 150 | |
| 151 | void pressed(QQuickMouseEvent *mouse); |
| 152 | void pressAndHold(QQuickMouseEvent *mouse); |
| 153 | void released(QQuickMouseEvent *mouse); |
| 154 | void clicked(QQuickMouseEvent *mouse); |
| 155 | void doubleClicked(QQuickMouseEvent *mouse); |
| 156 | void wheel(QQuickWheelEvent *wheel); |
| 157 | void entered(); |
| 158 | void exited(); |
| 159 | void canceled(); |
| 160 | Q_REVISION(4) void containsPressChanged(); |
| 161 | Q_REVISION(9) void pressAndHoldIntervalChanged(); |
| 162 | |
| 163 | protected: |
| 164 | void setHovered(bool); |
| 165 | bool setPressed(Qt::MouseButton button, bool p, Qt::MouseEventSource source); |
| 166 | bool sendMouseEvent(QMouseEvent *event); |
| 167 | |
| 168 | void mousePressEvent(QMouseEvent *event) override; |
| 169 | void mouseReleaseEvent(QMouseEvent *event) override; |
| 170 | void mouseDoubleClickEvent(QMouseEvent *event) override; |
| 171 | void mouseMoveEvent(QMouseEvent *event) override; |
| 172 | void mouseUngrabEvent() override; |
| 173 | void touchUngrabEvent() override; |
| 174 | void hoverEnterEvent(QHoverEvent *event) override; |
| 175 | void hoverMoveEvent(QHoverEvent *event) override; |
| 176 | void hoverLeaveEvent(QHoverEvent *event) override; |
| 177 | #if QT_CONFIG(wheelevent) |
| 178 | void wheelEvent(QWheelEvent *event) override; |
| 179 | #endif |
| 180 | bool childMouseEventFilter(QQuickItem *i, QEvent *e) override; |
| 181 | void timerEvent(QTimerEvent *event) override; |
| 182 | void windowDeactivateEvent() override; |
| 183 | |
| 184 | void geometryChanged(const QRectF &newGeometry, |
| 185 | const QRectF &oldGeometry) override; |
| 186 | void itemChange(ItemChange change, const ItemChangeData& value) override; |
| 187 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
| 188 | |
| 189 | private: |
| 190 | void handlePress(); |
| 191 | void handleRelease(); |
| 192 | void ungrabMouse(); |
| 193 | |
| 194 | private: |
| 195 | Q_DISABLE_COPY(QQuickMouseArea) |
| 196 | Q_DECLARE_PRIVATE(QQuickMouseArea) |
| 197 | }; |
| 198 | |
| 199 | QT_END_NAMESPACE |
| 200 | |
| 201 | QML_DECLARE_TYPE(QQuickMouseArea) |
| 202 | |
| 203 | #endif // QQUICKMOUSEAREA_P_H |
| 204 | |