Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickhoverhandler.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 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
5#include <private/qquicksinglepointhandler_p_p.h>
6#include <private/qquickdeliveryagent_p.h>
7#include <private/qquickitem_p.h>
8
10
11Q_LOGGING_CATEGORY(lcHoverHandler, "qt.quick.handler.hover")
12
13
40{
41 Q_DECLARE_PUBLIC(QQuickHoverHandler)
42
43public:
44 void onEnabledChanged() override;
45 void onParentChanged(QQuickItem *oldParent, QQuickItem *newParent) override;
46
47 void updateHasHoverInChild(QQuickItem *item, bool hasHover);
48};
49
51{
53
54 if (auto parent = q->parentItem())
56 if (!enabled)
57 q->setHovered(false);
58
60}
61
63{
64 if (oldParent)
65 updateHasHoverInChild(oldParent, false);
66 if (newParent)
67 updateHasHoverInChild(newParent, true);
68
70}
71
73{
75 itemPriv->setHasHoverInChild(hasHover);
76 // The DA needs to resolve which items and handlers should now be hovered or unhovered.
77 // Marking the parent item dirty ensures that flushFrameSynchronousEvents() will be called from the render loop,
78 // even if this change is not in response to a mouse event and no item has already marked itself dirty.
80}
81
84{
86 // Tell QQuickPointerDeviceHandler::wantsPointerEvent() to ignore button state
87 d->acceptedButtons = Qt::NoButton;
88 if (parent)
89 d->updateHasHoverInChild(parent, true);
90}
91
93{
95 if (auto parent = parentItem())
96 d->updateHasHoverInChild(parent, false);
97}
98
107{
108 if (m_blocking == blocking)
109 return;
110
111 m_blocking = blocking;
112 emit blockingChanged();
113}
114
116{
117 switch (event->type())
118 {
120 setHovered(false);
121 setActive(false);
122 break;
123 default:
125 break;
126 }
127
128 return true;
129}
130
132{
135
136 if (d->enabled) {
137 if (auto parent = parentItem())
138 d->updateHasHoverInChild(parent, true);
139 }
140}
141
143{
144 // No state change should occur if a button is being pressed or released.
145 if (event->isSinglePointEvent() && static_cast<QSinglePointEvent *>(event)->button())
146 return false;
147 auto &point = event->point(0);
149 // assume this is a mouse or tablet event, so there's only one point
151 return true;
152 }
153
154 // Some hover events come from QQuickWindow::tabletEvent(). In between,
155 // some hover events come from QQuickDeliveryAgentPrivate::flushFrameSynchronousEvents(),
156 // but those look like mouse events. If a particular HoverHandler instance
157 // is filtering for tablet events only (e.g. by setting
158 // acceptedDevices:PointerDevice.Stylus), those events should not cause
159 // the hovered property to transition to false prematurely.
160 // If a QQuickPointerTabletEvent caused the hovered property to become true,
161 // then only another QQuickPointerTabletEvent can make it become false.
162 // But after kCursorOverrideTimeout ms, QQuickItemPrivate::effectiveCursorHandler()
163 // will ignore it, just in case there is no QQuickPointerTabletEvent to unset it.
164 // For example, a tablet proximity leave event could occur, but we don't deliver it to the window.
165 if (!(m_hoveredTablet && QQuickDeliveryAgentPrivate::isMouseEvent(event)))
166 setHovered(false);
167
168 return false;
169}
170
172{
173 bool hovered = true;
174 if (point.state() == QEventPoint::Released &&
176 hovered = false;
178 m_hoveredTablet = true;
179 setHovered(hovered);
180}
181
190void QQuickHoverHandler::setHovered(bool hovered)
191{
192 if (m_hovered != hovered) {
193 qCDebug(lcHoverHandler) << objectName() << "hovered" << m_hovered << "->" << hovered;
194 m_hovered = hovered;
195 if (!hovered)
196 m_hoveredTablet = false;
198 }
199}
200
349
350#include "moc_qquickhoverhandler_p.cpp"
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
\inmodule QtCore
Definition qcoreevent.h:45
@ HoverLeave
Definition qcoreevent.h:176
QString objectName
the name of this object
Definition qobject.h:94
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1363
A base class for pointer events.
Definition qevent.h:73
const QPointingDevice * pointingDevice() const
Returns the source device from which this event originates.
Definition qevent.cpp:327
PointerType pointerType
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
static bool isTabletEvent(const QPointerEvent *ev)
static bool isMouseEvent(const QPointerEvent *ev)
\qmltype HoverHandler \instantiates QQuickHoverHandler \inherits SinglePointHandler \inqmlmodule QtQu...
void onParentChanged(QQuickItem *oldParent, QQuickItem *newParent) override
void updateHasHoverInChild(QQuickItem *item, bool hasHover)
void setBlocking(bool blocking)
\qmlproperty bool QtQuick::HoverHandler::blocking
void handleEventPoint(QPointerEvent *ev, QEventPoint &point) override
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQuickHoverHandler(QQuickItem *parent=nullptr)
bool wantsPointerEvent(QPointerEvent *event) override
It is the responsibility of this function to decide whether the event could be relevant at all to thi...
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void dirty(DirtyType)
static QQuickItemPrivate * get(QQuickItem *item)
void setHasHoverInChild(bool hasHover)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
bool wantsPointerEvent(QPointerEvent *event) override
It is the responsibility of this function to decide whether the event could be relevant at all to thi...
virtual void onParentChanged(QQuickItem *, QQuickItem *)
bool parentContains(const QEventPoint &point) const
Returns true if margin() > 0 and point is within the margin beyond QQuickItem::boundingRect(),...
QQuickItem * parentItem() const
\qmlproperty Item QtQuick::PointerHandler::parent
virtual bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point)
Returns true if the given point (as part of event) could be relevant at all to this handler,...
A base class for pointer events containing a single point, such as mouse events.
Definition qevent.h:108
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:115
Combined button and popup list for selecting options.
@ NoButton
Definition qnamespace.h:56
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLenum GLsizei const GLuint GLboolean enabled
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit
QGraphicsItem * item
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent