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
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:
15 {
16 QImage cursorImage(64,64,QImage::Format_ARGB32);
17 cursorImage.fill(Qt::transparent);
18 cursorPixmap = QPixmap::fromImage(cursorImage);
19 }
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)
28 emit q->mouseXChanged();
29 if (yChanged)
30 emit q->mouseYChanged();
31 }
32 }
33
35 {
37 if (this->hovered == hovered)
38 return;
39 this->hovered = hovered;
40 emit q->hoveredChanged();
41 }
42
46 bool hovered = false;
47};
48
60
62{
63 Q_D(const QWaylandMouseTracker);
64 return d->mousePos.x();
65}
67{
68 Q_D(const QWaylandMouseTracker);
69 return d->mousePos.y();
70}
71
72#if QT_CONFIG(cursor)
74{
76 if (d->windowSystemCursorEnabled != enable) {
77 d->windowSystemCursorEnabled = enable;
78 if (enable) {
80 } else {
81 setCursor(QCursor(d->cursorPixmap));
82 }
84 }
85}
86
88{
89 Q_D(const QWaylandMouseTracker);
90 return d->windowSystemCursorEnabled;
91}
92#endif
93
95{
96 Q_D(const QWaylandMouseTracker);
97 return d->hovered;
98}
99
101{
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
119
126
128{
131 d->setHovered(true);
132}
133
135{
138 d->setHovered(false);
139}
140
142
143#include "moc_qwaylandmousetracker_p.cpp"
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
\inmodule QtCore
Definition qcoreevent.h:45
@ MouseMove
Definition qcoreevent.h:63
@ HoverMove
Definition qcoreevent.h:177
\inmodule QtGui
Definition qevent.h:246
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32
Definition qimage.h:47
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition qimage.cpp:1758
\inmodule QtGui
Definition qevent.h:196
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setFiltersChildMouseEvents(bool filter)
Sets whether pointer events intended for this item's children should be filtered through this item.
Q_INVOKABLE QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const
Maps the given point in item's coordinate system to the equivalent point within this item's coordinat...
void setAcceptHoverEvents(bool enabled)
If enabled is true, this sets the item to accept hover events; otherwise, hover events are not accept...
virtual void hoverMoveEvent(QHoverEvent *event)
This event handler can be reimplemented in a subclass to receive hover-move events for an item.
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons accepted by this item to buttons.
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Definition qevent.h:119
void handleMousePos(const QPointF &mousePos)
bool childMouseEventFilter(QQuickItem *item, QEvent *event) override
Reimplement this method to filter the pointer events that are received by this item's children.
void windowSystemCursorEnabledChanged()
void hoverLeaveEvent(QHoverEvent *event) override
This event handler can be reimplemented in a subclass to receive hover-leave events for an item.
QWaylandMouseTracker(QQuickItem *parent=nullptr)
void hoverEnterEvent(QHoverEvent *event) override
This event handler can be reimplemented in a subclass to receive hover-enter events for an item.
void setWindowSystemCursorEnabled(bool enable)
void hoverMoveEvent(QHoverEvent *event) override
This event handler can be reimplemented in a subclass to receive hover-move events for an item.
void mouseMoveEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
Combined button and popup list for selecting options.
@ AllButtons
Definition qnamespace.h:90
@ transparent
Definition qnamespace.h:47
static void unsetCursor(QWindow *w)
GLboolean enable
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
item setCursor(Qt::IBeamCursor)
[1]
QGraphicsItem * item