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
qwindowscursor.h
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#ifndef QWINDOWSCURSOR_H
5#define QWINDOWSCURSOR_H
6
7#include <QtCore/qt_windows.h>
8
9#include <qpa/qplatformcursor.h>
10#include <QtCore/qsharedpointer.h>
11#include <QtCore/qhash.h>
12
14
22
24{
25 return k1.bitmapCacheKey == k2.bitmapCacheKey && k1.maskCacheKey == k2.maskCacheKey;
26}
27
28inline size_t qHash(const QWindowsPixmapCursorCacheKey &k, size_t seed) noexcept
29{
30 return (size_t(k.bitmapCacheKey) + size_t(k.maskCacheKey)) ^ seed;
31}
32
34{
35 Q_DISABLE_COPY_MOVE(CursorHandle)
36public:
37 explicit CursorHandle(HCURSOR hcursor = nullptr) : m_hcursor(hcursor) {}
39 {
40 if (m_hcursor)
41 DestroyCursor(m_hcursor);
42 }
43
44 bool isNull() const { return !m_hcursor; }
45 HCURSOR handle() const { return m_hcursor; }
46
47private:
48 const HCURSOR m_hcursor;
49};
50
51using CursorHandlePtr = QSharedPointer<CursorHandle>;
52
54{
55public:
56 enum class State {
57 Showing,
58 Hidden,
59 Suppressed // Cursor suppressed by touch interaction (Windows 8).
60 };
61
62 struct PixmapCursor {
63 explicit PixmapCursor(const QPixmap &pix = QPixmap(), const QPoint &h = QPoint()) : pixmap(pix), hotSpot(h) {}
64
67 };
68
69 explicit QWindowsCursor(const QPlatformScreen *screen);
70
71 void changeCursor(QCursor * widgetCursor, QWindow * widget) override;
72 void setOverrideCursor(const QCursor &cursor) override;
73 void clearOverrideCursor() override;
74 static void enforceOverrideCursor();
75 static bool hasOverrideCursor() { return m_overriddenCursor != nullptr; }
76
77 QPoint pos() const override;
78 void setPos(const QPoint &pos) override;
79
80 QSize size() const override;
81
82 static HCURSOR createPixmapCursor(QPixmap pixmap, const QPoint &hotSpot, qreal scaleFactor = 1);
83 static HCURSOR createPixmapCursor(const PixmapCursor &pc, qreal scaleFactor = 1) { return createPixmapCursor(pc.pixmap, pc.hotSpot, scaleFactor); }
84 static PixmapCursor customCursor(Qt::CursorShape cursorShape, const QPlatformScreen *screen = nullptr);
85
86 static HCURSOR createCursorFromShape(Qt::CursorShape cursorShape, const QPlatformScreen *screen = nullptr);
87 static QPoint mousePosition();
88 static State cursorState();
89
92
94
95 HCURSOR hCursor(const QCursor &c) const;
96
97private:
98 typedef QHash<Qt::CursorShape, CursorHandlePtr> StandardCursorCache;
99 typedef QHash<QWindowsPixmapCursorCacheKey, CursorHandlePtr> PixmapCursorCache;
100
101 CursorHandlePtr cursorHandle(const QCursor &c);
102
103 const QPlatformScreen *const m_screen;
104 StandardCursorCache m_standardCursorCache;
105 PixmapCursorCache m_pixmapCursorCache;
106
107 mutable QPixmap m_copyDragCursor;
108 mutable QPixmap m_moveDragCursor;
109 mutable QPixmap m_linkDragCursor;
110 mutable QPixmap m_ignoreDragCursor;
111
112 static HCURSOR m_overriddenCursor;
113 static HCURSOR m_overrideCursor;
114};
115
117
118#endif // QWINDOWSCURSOR_H
CursorHandle(HCURSOR hcursor=nullptr)
HCURSOR handle() const
bool isNull() const
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
The QPlatformCursor class provides information about pointer device events (movement,...
The QPlatformScreen class provides an abstraction for visual displays.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore
Definition qsize.h:25
\inmodule QtGui
Definition qwindow.h:63
Platform cursor implementation.
static bool hasOverrideCursor()
static QPoint mousePosition()
void setOverrideCursor(const QCursor &cursor) override
Reimplement this function in subclass to set an override cursor on the associated screen and return t...
static HCURSOR createPixmapCursor(const PixmapCursor &pc, qreal scaleFactor=1)
static HCURSOR createPixmapCursor(QPixmap pixmap, const QPoint &hotSpot, qreal scaleFactor=1)
void changeCursor(QCursor *widgetCursor, QWindow *widget) override
Set a cursor on a window.
static PixmapCursor customCursor(Qt::CursorShape cursorShape, const QPlatformScreen *screen=nullptr)
HCURSOR hCursor(const QCursor &c) const
void clearOverrideCursor() override
Reimplement this function in subclass to clear the override cursor.
CursorHandlePtr standardWindowCursor(Qt::CursorShape s=Qt::ArrowCursor)
Return cached standard cursor resources or create new ones.
static State cursorState()
static HCURSOR createCursorFromShape(Qt::CursorShape cursorShape, const QPlatformScreen *screen=nullptr)
static void enforceOverrideCursor()
QWindowsCursor(const QPlatformScreen *screen)
QPixmap dragDefaultCursor(Qt::DropAction action) const
CursorHandlePtr pixmapWindowCursor(const QCursor &c)
Return cached pixmap cursor or create new one.
QSize size() const override
Returns the size of the cursor, in native pixels.
QPoint pos() const override
void setPos(const QPoint &pos) override
QOpenGLWidget * widget
[1]
QCursor cursor
QPixmap pix
Combined button and popup list for selecting options.
CursorShape
@ ArrowCursor
DropAction
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define k1
QScreen * screen
[1]
Definition main.cpp:29
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
HICON HCURSOR
bool operator==(const QWindowsPixmapCursorCacheKey &k1, const QWindowsPixmapCursorCacheKey &k2)
size_t qHash(const QWindowsPixmapCursorCacheKey &k, size_t seed) noexcept
widget render & pixmap
PixmapCursor(const QPixmap &pix=QPixmap(), const QPoint &h=QPoint())
QWindowsPixmapCursorCacheKey(const QCursor &c)