1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKMOUSEAREA_P_H
5#define QQUICKMOUSEAREA_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qquickitem.h"
19#include <private/qtquickglobal_p.h>
20#include <QtCore/qstringlist.h>
21
22QT_BEGIN_NAMESPACE
23
24class QQuickMouseEvent;
25class QQuickDrag;
26class QQuickMouseAreaPrivate;
27class QQuickWheelEvent;
28// used in Qt Location
29class Q_QUICK_PRIVATE_EXPORT QQuickMouseArea : public QQuickItem
30{
31 Q_OBJECT
32
33 Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mouseXChanged FINAL)
34 Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mouseYChanged FINAL)
35 Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged FINAL)
36 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL)
37 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
38 Q_PROPERTY(bool scrollGestureEnabled READ isScrollGestureEnabled WRITE setScrollGestureEnabled NOTIFY scrollGestureEnabledChanged REVISION(2, 5) FINAL)
39 Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedButtonsChanged FINAL)
40 Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged FINAL)
41 Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged FINAL)
42#if QT_CONFIG(quick_draganddrop)
43 Q_PROPERTY(QQuickDrag *drag READ drag CONSTANT FINAL) //### add flicking to QQuickDrag or add a QQuickFlick ???
44#endif
45 Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged FINAL)
46 Q_PROPERTY(bool propagateComposedEvents READ propagateComposedEvents WRITE setPropagateComposedEvents NOTIFY propagateComposedEventsChanged FINAL)
47#if QT_CONFIG(cursor)
48 Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET unsetCursor NOTIFY cursorShapeChanged FINAL)
49#endif
50 Q_PROPERTY(bool containsPress READ containsPress NOTIFY containsPressChanged REVISION(2, 4) FINAL)
51 Q_PROPERTY(int pressAndHoldInterval READ pressAndHoldInterval WRITE setPressAndHoldInterval NOTIFY pressAndHoldIntervalChanged RESET resetPressAndHoldInterval REVISION(2, 9) FINAL)
52 QML_NAMED_ELEMENT(MouseArea)
53 QML_ADDED_IN_VERSION(2, 0)
54
55public:
56 QQuickMouseArea(QQuickItem *parent=nullptr);
57 ~QQuickMouseArea();
58
59 qreal mouseX() const;
60 qreal mouseY() const;
61
62 bool isEnabled() const;
63 void setEnabled(bool);
64
65 bool isScrollGestureEnabled() const;
66 void setScrollGestureEnabled(bool);
67
68 bool hovered() const;
69 bool isPressed() const;
70 bool containsPress() const;
71
72 Qt::MouseButtons pressedButtons() const;
73
74 Qt::MouseButtons acceptedButtons() const;
75 void setAcceptedButtons(Qt::MouseButtons buttons);
76
77 bool hoverEnabled() const;
78 void setHoverEnabled(bool h);
79
80#if QT_CONFIG(quick_draganddrop)
81 QQuickDrag *drag();
82#endif
83
84 bool preventStealing() const;
85 void setPreventStealing(bool prevent);
86
87 bool propagateComposedEvents() const;
88 void setPropagateComposedEvents(bool propagate);
89
90#if QT_CONFIG(cursor)
91 Qt::CursorShape cursorShape() const;
92 void setCursorShape(Qt::CursorShape shape);
93#endif
94
95 int pressAndHoldInterval() const;
96 void setPressAndHoldInterval(int interval);
97 void resetPressAndHoldInterval();
98
99Q_SIGNALS:
100 void hoveredChanged();
101 void pressedChanged();
102 void enabledChanged();
103 Q_REVISION(2, 5) void scrollGestureEnabledChanged();
104 void pressedButtonsChanged();
105 void acceptedButtonsChanged();
106 void hoverEnabledChanged();
107#if QT_CONFIG(cursor)
108 void cursorShapeChanged();
109#endif
110 void positionChanged(QQuickMouseEvent *mouse);
111 void mouseXChanged(QQuickMouseEvent *mouse);
112 void mouseYChanged(QQuickMouseEvent *mouse);
113 void preventStealingChanged();
114 void propagateComposedEventsChanged();
115
116 void pressed(QQuickMouseEvent *mouse);
117 void pressAndHold(QQuickMouseEvent *mouse);
118 void released(QQuickMouseEvent *mouse);
119 void clicked(QQuickMouseEvent *mouse);
120 void doubleClicked(QQuickMouseEvent *mouse);
121#if QT_CONFIG(wheelevent)
122 void wheel(QQuickWheelEvent *wheel);
123#endif
124 void entered();
125 void exited();
126 void canceled();
127 Q_REVISION(2, 4) void containsPressChanged();
128 Q_REVISION(2, 9) void pressAndHoldIntervalChanged();
129
130protected:
131 void setHovered(bool);
132 bool setPressed(Qt::MouseButton button, bool p, Qt::MouseEventSource source);
133 bool sendMouseEvent(QMouseEvent *event);
134
135 void mousePressEvent(QMouseEvent *event) override;
136 void mouseReleaseEvent(QMouseEvent *event) override;
137 void mouseDoubleClickEvent(QMouseEvent *event) override;
138 void mouseMoveEvent(QMouseEvent *event) override;
139 void mouseUngrabEvent() override;
140 void touchUngrabEvent() override;
141 void hoverEnterEvent(QHoverEvent *event) override;
142 void hoverMoveEvent(QHoverEvent *event) override;
143 void hoverLeaveEvent(QHoverEvent *event) override;
144#if QT_CONFIG(wheelevent)
145 void wheelEvent(QWheelEvent *event) override;
146#endif
147 bool childMouseEventFilter(QQuickItem *i, QEvent *e) override;
148 void timerEvent(QTimerEvent *event) override;
149
150 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
151 void itemChange(ItemChange change, const ItemChangeData& value) override;
152 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
153
154private:
155 void handlePress();
156 void handleRelease();
157 void ungrabMouse();
158
159private:
160 Q_DISABLE_COPY(QQuickMouseArea)
161 Q_DECLARE_PRIVATE(QQuickMouseArea)
162};
163
164QT_END_NAMESPACE
165
166QML_DECLARE_TYPE(QQuickMouseArea)
167
168#endif // QQUICKMOUSEAREA_P_H
169

source code of qtdeclarative/src/quick/items/qquickmousearea_p.h