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
58QT_BEGIN_NAMESPACE
59
60class QQuickMouseEvent;
61class QQuickDrag;
62class QQuickMouseAreaPrivate;
63class QQuickWheelEvent;
64// used in Qt Location
65class 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 2)
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 1)
87 Q_PROPERTY(int pressAndHoldInterval READ pressAndHoldInterval WRITE setPressAndHoldInterval NOTIFY pressAndHoldIntervalChanged RESET resetPressAndHoldInterval REVISION 9)
88
89public:
90 QQuickMouseArea(QQuickItem *parent=nullptr);
91 ~QQuickMouseArea();
92
93 qreal mouseX() const;
94 qreal mouseY() const;
95
96 bool isEnabled() const;
97 void setEnabled(bool);
98
99 bool isScrollGestureEnabled() const;
100 void setScrollGestureEnabled(bool);
101
102 bool hovered() const;
103 bool pressed() const;
104 bool containsPress() const;
105
106 Qt::MouseButtons pressedButtons() const;
107
108 Qt::MouseButtons acceptedButtons() const;
109 void setAcceptedButtons(Qt::MouseButtons buttons);
110
111 bool hoverEnabled() const;
112 void setHoverEnabled(bool h);
113
114#if QT_CONFIG(quick_draganddrop)
115 QQuickDrag *drag();
116#endif
117
118 bool preventStealing() const;
119 void setPreventStealing(bool prevent);
120
121 bool propagateComposedEvents() const;
122 void setPropagateComposedEvents(bool propagate);
123
124#if QT_CONFIG(cursor)
125 Qt::CursorShape cursorShape() const;
126 void setCursorShape(Qt::CursorShape shape);
127#endif
128
129 int pressAndHoldInterval() const;
130 void setPressAndHoldInterval(int interval);
131 void resetPressAndHoldInterval();
132
133Q_SIGNALS:
134 void hoveredChanged();
135 void pressedChanged();
136 void enabledChanged();
137 Q_REVISION(2) void scrollGestureEnabledChanged();
138 void pressedButtonsChanged();
139 void acceptedButtonsChanged();
140 void hoverEnabledChanged();
141#if QT_CONFIG(cursor)
142 void cursorShapeChanged();
143#endif
144 void positionChanged(QQuickMouseEvent *mouse);
145 void mouseXChanged(QQuickMouseEvent *mouse);
146 void mouseYChanged(QQuickMouseEvent *mouse);
147 void preventStealingChanged();
148 void propagateComposedEventsChanged();
149
150 void pressed(QQuickMouseEvent *mouse);
151 void pressAndHold(QQuickMouseEvent *mouse);
152 void released(QQuickMouseEvent *mouse);
153 void clicked(QQuickMouseEvent *mouse);
154 void doubleClicked(QQuickMouseEvent *mouse);
155 void wheel(QQuickWheelEvent *wheel);
156 void entered();
157 void exited();
158 void canceled();
159 Q_REVISION(1) void containsPressChanged();
160 Q_REVISION(9) void pressAndHoldIntervalChanged();
161
162protected:
163 void setHovered(bool);
164 bool setPressed(Qt::MouseButton button, bool p, Qt::MouseEventSource source);
165 bool sendMouseEvent(QMouseEvent *event);
166
167 void mousePressEvent(QMouseEvent *event) override;
168 void mouseReleaseEvent(QMouseEvent *event) override;
169 void mouseDoubleClickEvent(QMouseEvent *event) override;
170 void mouseMoveEvent(QMouseEvent *event) override;
171 void mouseUngrabEvent() override;
172 void hoverEnterEvent(QHoverEvent *event) override;
173 void hoverMoveEvent(QHoverEvent *event) override;
174 void hoverLeaveEvent(QHoverEvent *event) override;
175#if QT_CONFIG(wheelevent)
176 void wheelEvent(QWheelEvent *event) override;
177#endif
178 bool childMouseEventFilter(QQuickItem *i, QEvent *e) override;
179 void timerEvent(QTimerEvent *event) override;
180 void windowDeactivateEvent() override;
181
182 void geometryChanged(const QRectF &newGeometry,
183 const QRectF &oldGeometry) override;
184 void itemChange(ItemChange change, const ItemChangeData& value) override;
185 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
186
187private:
188 void handlePress();
189 void handleRelease();
190 void ungrabMouse();
191
192private:
193 Q_DISABLE_COPY(QQuickMouseArea)
194 Q_DECLARE_PRIVATE(QQuickMouseArea)
195};
196
197QT_END_NAMESPACE
198
199QML_DECLARE_TYPE(QQuickMouseArea)
200
201#endif // QQUICKMOUSEAREA_P_H
202