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
qfbcursor.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
4#include "qfbcursor_p.h"
5#include "qfbscreen_p.h"
6#include <QtGui/QPainter>
7#include <QtGui/private/qguiapplication_p.h>
8
10
15
21
23 : mVisible(true),
24 mScreen(screen),
25 mDirty(false),
26 mOnScreen(false),
27 mCursorImage(nullptr),
28 mDeviceListener(nullptr)
29{
30 const char *envVar = "QT_QPA_FB_HIDECURSOR";
31 if (qEnvironmentVariableIsSet(envVar))
32 mVisible = qEnvironmentVariableIntValue(envVar) == 0;
33 if (!mVisible)
34 return;
35
36 mCursorImage.reset(new QPlatformCursorImage(0, 0, 0, 0, 0, 0));
37 setCursor(Qt::ArrowCursor);
38
39 mDeviceListener = new QFbCursorDeviceListener(this);
43}
44
46{
47 delete mDeviceListener;
48}
49
50QRect QFbCursor::getCurrentRect() const
51{
52 QRect rect = mCursorImage->image()->rect().translated(-mCursorImage->hotspot().x(),
53 -mCursorImage->hotspot().y());
54 rect.translate(m_pos);
55 QPoint mScreenOffset = mScreen->geometry().topLeft();
56 rect.translate(-mScreenOffset); // global to local translation
57 return rect;
58}
59
61{
62 return m_pos;
63}
64
66{
68 m_pos = pos;
69 if (!mVisible)
70 return;
71 mCurrentRect = getCurrentRect();
72 if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft())))
73 setDirty();
74}
75
77{
78 if (e.type() != QEvent::MouseMove)
79 return;
80 m_pos = e.globalPosition().toPoint();
81 if (!mVisible)
82 return;
83 mCurrentRect = getCurrentRect();
84 if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreen->geometry().topLeft())))
85 setDirty();
86}
87
89{
90 if (!mVisible)
91 return QRect();
92
93 mDirty = false;
94 if (mCurrentRect.isNull())
95 return QRect();
96
97 // We need this because the cursor might be mDirty due to moving off mScreen
98 QPoint mScreenOffset = mScreen->geometry().topLeft();
99 // global to local translation
100 if (!mCurrentRect.translated(mScreenOffset).intersects(mScreen->geometry()))
101 return QRect();
102
103 mPrevRect = mCurrentRect;
104 painter.drawImage(mPrevRect, *mCursorImage->image());
105 mOnScreen = true;
106 return mPrevRect;
107}
108
110{
111 if (mOnScreen) {
112 mOnScreen = false;
113 return mPrevRect;
114 }
115 return QRect();
116}
117
118void QFbCursor::setCursor(Qt::CursorShape shape)
119{
120 if (mCursorImage)
121 mCursorImage->set(shape);
122}
123
124void QFbCursor::setCursor(const QImage &image, int hotx, int hoty)
125{
126 if (mCursorImage)
127 mCursorImage->set(image, hotx, hoty);
128}
129
130void QFbCursor::setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
131{
132 if (mCursorImage)
133 mCursorImage->set(data, mask, width, height, hotX, hotY);
134}
135
136#ifndef QT_NO_CURSOR
138{
140 if (!mVisible)
141 return;
142 const Qt::CursorShape shape = widgetCursor ? widgetCursor->shape() : Qt::ArrowCursor;
143
144 if (shape == Qt::BitmapCursor) {
145 // application supplied cursor
146 QPoint spot = widgetCursor->hotSpot();
147 setCursor(widgetCursor->pixmap().toImage(), spot.x(), spot.y());
148 } else {
149 // system cursor
150 setCursor(shape);
151 }
152 mCurrentRect = getCurrentRect();
153 QPoint mScreenOffset = mScreen->geometry().topLeft(); // global to local translation
154 if (mOnScreen || mScreen->geometry().intersects(mCurrentRect.translated(mScreenOffset)))
155 setDirty();
156}
157#endif
158
160{
161 if (!mVisible)
162 return;
163
164 if (!mDirty) {
165 mDirty = true;
166 mScreen->scheduleUpdate();
167 }
168}
169
171{
172 mVisible = mDeviceListener ? mDeviceListener->hasMouse() : false;
173 mScreen->setDirty(mVisible ? getCurrentRect() : lastPainted());
174}
175
177
178#include "moc_qfbcursor_p.cpp"
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
@ MouseMove
Definition qcoreevent.h:63
Type type() const
Returns the event type.
Definition qcoreevent.h:304
void onDeviceListChanged(QInputDeviceManager::DeviceType type)
Definition qfbcursor.cpp:16
void setPos(const QPoint &pos) override
Definition qfbcursor.cpp:65
QPoint pos() const override
Definition qfbcursor.cpp:60
virtual void setDirty()
QRect dirtyRect()
void updateMouseStatus()
void pointerEvent(const QMouseEvent &event) override
This method is called by Qt whenever a QMouseEvent is generated by the underlying pointer input.
Definition qfbcursor.cpp:76
QFbCursor(QFbScreen *screen)
Definition qfbcursor.cpp:22
virtual QRect lastPainted() const
Definition qfbcursor_p.h:64
virtual QRect drawCursor(QPainter &painter)
Definition qfbcursor.cpp:88
void changeCursor(QCursor *widgetCursor, QWindow *window) override
This method is called by Qt whenever the cursor graphic should be changed.
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
Definition qfbscreen_p.h:45
virtual void setDirty(const QRect &rect)
void scheduleUpdate()
static QInputDeviceManager * inputDeviceManager()
\inmodule QtGui
Definition qimage.h:37
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
void deviceListChanged(QInputDeviceManager::DeviceType type)
\inmodule QtGui
Definition qevent.h:196
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
The QPlatformCursorImage class provides a set of graphics intended to be used as cursors.
QPoint hotspot() const
Return the cursor's hotspot.
void set(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
Sets the cursor image to the graphic represented by the combination of data and mask,...
QImage * image()
Return the cursor graphic as a pointer to a QImage.
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
\inmodule QtCore\reentrant
Definition qrect.h:30
bool intersects(const QRect &r) const noexcept
Returns true if this rectangle intersects with the given rectangle (i.e., there is at least one pixel...
Definition qrect.cpp:1069
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:164
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
QPointF globalPosition() const
Returns the position of the point in this event on the screen or virtual desktop.
Definition qevent.h:123
\inmodule QtGui
Definition qwindow.h:63
rect
[4]
Combined button and popup list for selecting options.
CursorShape
@ BitmapCursor
@ ArrowCursor
Definition image.cpp:4
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei width
GLenum type
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
QScreen * screen
[1]
Definition main.cpp:29
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_UNUSED(x)
unsigned char uchar
Definition qtypes.h:32
QObject::connect nullptr
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]