Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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.
79 itemPriv->dirty(QQuickItemPrivate::Content);
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);
148 const bool inside = parentContains(point);
150 // assume this is a mouse or tablet event, so there's only one point
152 return true;
153 }
154
155 // Some hover events come from QQuickWindow::tabletEvent(). In between,
156 // some hover events come from QQuickDeliveryAgentPrivate::flushFrameSynchronousEvents(),
157 // but those look like mouse events. If a particular HoverHandler instance
158 // is filtering for tablet events only (e.g. by setting
159 // acceptedDevices:PointerDevice.Stylus), those events should not cause
160 // the hovered property to transition to false prematurely.
161 // If a QQuickPointerTabletEvent caused the hovered property to become true,
162 // then only another QQuickPointerTabletEvent can make it become false.
163 // But after kCursorOverrideTimeout ms, QQuickItemPrivate::effectiveCursorHandler()
164 // will ignore it, just in case there is no QQuickPointerTabletEvent to unset it.
165 // For example, a tablet proximity leave event could occur, but we don't deliver it to the window.
166 if (!inside || !(m_hoveredTablet && QQuickDeliveryAgentPrivate::isMouseEvent(event)))
167 setHovered(false);
168
169 return false;
170}
171
173{
174 bool hovered = true;
175 if (point.state() == QEventPoint::Released &&
176 ev->pointingDevice()->pointerType() == QPointingDevice::PointerType::Finger)
177 hovered = false;
179 m_hoveredTablet = true;
180 setHovered(hovered);
181}
182
191void QQuickHoverHandler::setHovered(bool hovered)
192{
193 if (m_hovered != hovered) {
194 qCDebug(lcHoverHandler) << objectName() << "hovered" << m_hovered << "->" << hovered;
195 m_hovered = hovered;
196 if (!hovered)
197 m_hoveredTablet = false;
199 }
200}
201
353
354#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
QObject * parent
Definition qobject.h:73
QString objectName
the name of this object
Definition qobject.h:107
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:1389
A base class for pointer events.
Definition qevent.h:73
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...
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
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:109
Qt::MouseButton button() const
Returns the button that caused the event.
Definition qevent.h:116
Combined button and popup list for selecting options.
@ NoButton
Definition qnamespace.h:57
#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