Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandmousetracker.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtQuick/private/qquickitem_p.h>
8
10
12{
13 Q_DECLARE_PUBLIC(QWaylandMouseTracker)
14public:
22 {
24 bool xChanged = mousePos.x() != this->mousePos.x();
25 bool yChanged = mousePos.y() != this->mousePos.y();
26 if (xChanged || yChanged) {
27 this->mousePos = mousePos;
28 if (xChanged)
30 if (yChanged)
32 }
33 }
34
36 {
38 if (this->hovered == hovered)
39 return;
40 this->hovered = hovered;
42 }
43
47 bool hovered = false;
48};
49
50QWaylandMouseTracker::QWaylandMouseTracker(QQuickItem *parent)
51 : QQuickItem(*(new QWaylandMouseTrackerPrivate), parent)
52{
53 Q_D(QWaylandMouseTracker);
54 setFiltersChildMouseEvents(true);
55 setAcceptHoverEvents(true);
56 setAcceptedMouseButtons(Qt::AllButtons);
57#if QT_CONFIG(cursor)
58 setCursor(QCursor(d->cursorPixmap));
59#endif
60}
61
62qreal QWaylandMouseTracker::mouseX() const
63{
64 Q_D(const QWaylandMouseTracker);
65 return d->mousePos.x();
66}
67qreal QWaylandMouseTracker::mouseY() const
68{
69 Q_D(const QWaylandMouseTracker);
70 return d->mousePos.y();
71}
72
73void QWaylandMouseTracker::setWindowSystemCursorEnabled(bool enable)
74{
75 Q_D(QWaylandMouseTracker);
76 if (d->windowSystemCursorEnabled != enable) {
77 d->windowSystemCursorEnabled = enable;
78#if QT_CONFIG(cursor)
79 if (enable) {
80 unsetCursor();
81 } else {
82 setCursor(QCursor(d->cursorPixmap));
83 }
84#endif
85 emit windowSystemCursorEnabledChanged();
86 }
87}
88
89bool QWaylandMouseTracker::windowSystemCursorEnabled() const
90{
91 Q_D(const QWaylandMouseTracker);
92 return d->windowSystemCursorEnabled;
93}
94
95bool QWaylandMouseTracker::hovered() const
96{
97 Q_D(const QWaylandMouseTracker);
98 return d->hovered;
99}
100
101bool QWaylandMouseTracker::childMouseEventFilter(QQuickItem *item, QEvent *event)
102{
103 Q_D(QWaylandMouseTracker);
104 if (event->type() == QEvent::MouseMove) {
105 QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
106 d->handleMousePos(mapFromItem(item, mouseEvent->position()));
107 } else if (event->type() == QEvent::HoverMove) {
108 QHoverEvent *hoverEvent = static_cast<QHoverEvent *>(event);
109 d->handleMousePos(mapFromItem(item, hoverEvent->position()));
110 }
111 return false;
112}
113
114void QWaylandMouseTracker::mouseMoveEvent(QMouseEvent *event)
115{
116 Q_D(QWaylandMouseTracker);
117 QQuickItem::mouseMoveEvent(event);
118 d->handleMousePos(event->position());
119}
120
121void QWaylandMouseTracker::hoverMoveEvent(QHoverEvent *event)
122{
123 Q_D(QWaylandMouseTracker);
124 QQuickItem::hoverMoveEvent(event);
125 d->handleMousePos(event->position());
126}
127
128void QWaylandMouseTracker::hoverEnterEvent(QHoverEvent *event)
129{
130 Q_D(QWaylandMouseTracker);
131 Q_UNUSED(event);
132 d->setHovered(true);
133}
134
135void QWaylandMouseTracker::hoverLeaveEvent(QHoverEvent *event)
136{
137 Q_D(QWaylandMouseTracker);
138 Q_UNUSED(event);
139 d->setHovered(false);
140}
141
142QT_END_NAMESPACE
143
144#include "moc_qwaylandmousetracker_p.cpp"
Combined button and popup list for selecting options.