Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
5
#
include
"qwaylandmousetracker_p.h"
6
7
#
include
<
QtQuick
/
private
/
qquickitem_p
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
class
QWaylandMouseTrackerPrivate
:
public
QQuickItemPrivate
12
{
13
Q_DECLARE_PUBLIC(QWaylandMouseTracker)
14
public
:
15
QWaylandMouseTrackerPrivate
()
16
{
17
QImage
cursorImage
(64,64,
QImage
::
Format_ARGB32
);
18
cursorImage
.
fill
(
Qt
::
transparent
);
19
cursorPixmap
=
QPixmap
::
fromImage
(
cursorImage
);
20
}
21
void
handleMousePos
(
const
QPointF
&
mousePos
)
22
{
23
Q_Q
(
QWaylandMouseTracker
);
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
)
29
emit
q
->
mouseXChanged
();
30
if
(
yChanged
)
31
emit
q
->
mouseYChanged
();
32
}
33
}
34
35
void
setHovered
(
bool
hovered
)
36
{
37
Q_Q
(
QWaylandMouseTracker
);
38
if
(
this
->
hovered
==
hovered
)
39
return
;
40
this
->
hovered
=
hovered
;
41
emit
q
->
hoveredChanged
();
42
}
43
44
QPointF
mousePos
;
45
bool
windowSystemCursorEnabled
=
false
;
46
QPixmap
cursorPixmap
;
47
bool
hovered
=
false
;
48
};
49
50
QWaylandMouseTracker::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
62
qreal QWaylandMouseTracker::mouseX()
const
63
{
64
Q_D(
const
QWaylandMouseTracker);
65
return
d->mousePos.x();
66
}
67
qreal QWaylandMouseTracker::mouseY()
const
68
{
69
Q_D(
const
QWaylandMouseTracker);
70
return
d->mousePos.y();
71
}
72
73
void
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
89
bool
QWaylandMouseTracker::windowSystemCursorEnabled()
const
90
{
91
Q_D(
const
QWaylandMouseTracker);
92
return
d->windowSystemCursorEnabled;
93
}
94
95
bool
QWaylandMouseTracker::hovered()
const
96
{
97
Q_D(
const
QWaylandMouseTracker);
98
return
d->hovered;
99
}
100
101
bool
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
114
void
QWaylandMouseTracker::mouseMoveEvent(QMouseEvent *event)
115
{
116
Q_D(QWaylandMouseTracker);
117
QQuickItem::mouseMoveEvent(event);
118
d->handleMousePos(event->position());
119
}
120
121
void
QWaylandMouseTracker::hoverMoveEvent(QHoverEvent *event)
122
{
123
Q_D(QWaylandMouseTracker);
124
QQuickItem::hoverMoveEvent(event);
125
d->handleMousePos(event->position());
126
}
127
128
void
QWaylandMouseTracker::hoverEnterEvent(QHoverEvent *event)
129
{
130
Q_D(QWaylandMouseTracker);
131
Q_UNUSED(event);
132
d->setHovered(
true
);
133
}
134
135
void
QWaylandMouseTracker::hoverLeaveEvent(QHoverEvent *event)
136
{
137
Q_D(QWaylandMouseTracker);
138
Q_UNUSED(event);
139
d->setHovered(
false
);
140
}
141
142
QT_END_NAMESPACE
143
144
#
include
"moc_qwaylandmousetracker_p.cpp"
QWaylandMouseTrackerPrivate
Definition
qwaylandmousetracker.cpp:12
QWaylandMouseTrackerPrivate::hovered
bool hovered
Definition
qwaylandmousetracker.cpp:47
QWaylandMouseTrackerPrivate::cursorPixmap
QPixmap cursorPixmap
Definition
qwaylandmousetracker.cpp:46
QWaylandMouseTrackerPrivate::windowSystemCursorEnabled
bool windowSystemCursorEnabled
Definition
qwaylandmousetracker.cpp:45
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtwayland
src
compositor
compositor_api
qwaylandmousetracker.cpp
Generated on
for Qt by
1.18.0