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
5
6#include <QtQuick/private/qquickitem_p.h>
7
9
11{
12 Q_DECLARE_PUBLIC(QWaylandMouseTracker)
13public:
21 {
23 bool xChanged = mousePos.x() != this->mousePos.x();
24 bool yChanged = mousePos.y() != this->mousePos.y();
25 if (xChanged || yChanged) {
26 this->mousePos = mousePos;
27 if (xChanged)
29 if (yChanged)
31 }
32 }
33
35 {
37 if (this->hovered == hovered)
38 return;
39 this->hovered = hovered;
41 }
42
46 bool hovered = false;
47};
48
49QWaylandMouseTracker::QWaylandMouseTracker(QQuickItem *parent)
50 : QQuickItem(*(new QWaylandMouseTrackerPrivate), parent)
51{
52 Q_D(QWaylandMouseTracker);
53 setFiltersChildMouseEvents(true);
54 setAcceptHoverEvents(true);
55 setAcceptedMouseButtons(Qt::AllButtons);
56#if QT_CONFIG(cursor)
57 setCursor(QCursor(d->cursorPixmap));
58#endif
59}
60
61qreal QWaylandMouseTracker::mouseX() const
62{
63 Q_D(const QWaylandMouseTracker);
64 return d->mousePos.x();
65}
66qreal QWaylandMouseTracker::mouseY() const
67{
68 Q_D(const QWaylandMouseTracker);
69 return d->mousePos.y();
70}
71
72#if QT_CONFIG(cursor)
73void QWaylandMouseTracker::setWindowSystemCursorEnabled(bool enable)
74{
75 Q_D(QWaylandMouseTracker);
76 if (d->windowSystemCursorEnabled != enable) {
77 d->windowSystemCursorEnabled = enable;
78 if (enable) {
79 unsetCursor();
80 } else {
81 setCursor(QCursor(d->cursorPixmap));
82 }
83 emit windowSystemCursorEnabledChanged();
84 }
85}
86
87bool QWaylandMouseTracker::windowSystemCursorEnabled() const
88{
89 Q_D(const QWaylandMouseTracker);
90 return d->windowSystemCursorEnabled;
91}
92#endif
93
94bool QWaylandMouseTracker::hovered() const
95{
96 Q_D(const QWaylandMouseTracker);
97 return d->hovered;
98}
99
100bool QWaylandMouseTracker::childMouseEventFilter(QQuickItem *item, QEvent *event)
101{
102 Q_D(QWaylandMouseTracker);
103 if (event->type() == QEvent::MouseMove) {
104 QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
105 d->handleMousePos(mapFromItem(item, mouseEvent->position()));
106 } else if (event->type() == QEvent::HoverMove) {
107 QHoverEvent *hoverEvent = static_cast<QHoverEvent *>(event);
108 d->handleMousePos(mapFromItem(item, hoverEvent->position()));
109 }
110 return false;
111}
112
113void QWaylandMouseTracker::mouseMoveEvent(QMouseEvent *event)
114{
115 Q_D(QWaylandMouseTracker);
116 QQuickItem::mouseMoveEvent(event);
117 d->handleMousePos(event->position());
118}
119
120void QWaylandMouseTracker::hoverMoveEvent(QHoverEvent *event)
121{
122 Q_D(QWaylandMouseTracker);
123 QQuickItem::hoverMoveEvent(event);
124 d->handleMousePos(event->position());
125}
126
127void QWaylandMouseTracker::hoverEnterEvent(QHoverEvent *event)
128{
129 Q_D(QWaylandMouseTracker);
130 Q_UNUSED(event);
131 d->setHovered(true);
132}
133
134void QWaylandMouseTracker::hoverLeaveEvent(QHoverEvent *event)
135{
136 Q_D(QWaylandMouseTracker);
137 Q_UNUSED(event);
138 d->setHovered(false);
139}
140
141QT_END_NAMESPACE
142
143#include "moc_qwaylandmousetracker_p.cpp"
Combined button and popup list for selecting options.