Loading...
Searching...
No Matches
CursorTheme.hpp
1#pragma once
2#include <QCursor>
3#include <QObject>
4#include <QPixmap>
5#include <QPointF>
6#include <QSize>
7
8#include <score_lib_base_export.h>
9
10#include <array>
11#include <cstdint>
12#include <memory>
13
14class QDrag;
15class QImage;
16class QScreen;
17class QWidget;
18class QWindow;
19
20namespace score
21{
32enum class CursorArtwork : uint8_t
33{
34 Pointer,
35 UpArrow,
36 Cross,
37 Wait,
38 IBeam,
39 ScaleV,
40 ScaleH,
41 ScaleBDiag,
42 ScaleFDiag,
43 Move,
44 SplitV,
45 SplitH,
46 PointingHand,
47 Forbidden,
48 WhatsThis,
49 Busy,
50 OpenHand,
51 ClosedHand,
52 DragCopy,
53 DragMove,
54 DragLink,
55 Magnifier,
56 Spin,
57 PlayFromHere,
58 CreationMode,
59
60 Count
61};
62
64{
66 const char* svg{};
69 QSize size{32, 32};
73 QPointF hotspot{};
76 bool mirrored{};
77};
78
79SCORE_LIB_BASE_EXPORT
80const CursorArtworkInfo& cursorArtworkInfo(CursorArtwork) noexcept;
81
84SCORE_LIB_BASE_EXPORT
85CursorArtwork cursorArtworkForShape(Qt::CursorShape) noexcept;
86
88constexpr bool isThemeCursorShape(Qt::CursorShape s) noexcept
89{
90 return s >= Qt::ArrowCursor && s <= Qt::LastCursor && s != Qt::BlankCursor;
91}
92
94enum class CursorPlatform : uint8_t
95{
97 X11,
102 Windows,
105 MacOS,
109 Wayland
110};
111
112SCORE_LIB_BASE_EXPORT
113CursorPlatform cursorPlatform(const QString& platformName) noexcept;
114
116{
119 qreal devicePixelRatio{1.};
121 QPoint hotspot;
128};
129
140SCORE_LIB_BASE_EXPORT
142 CursorPlatform platform, QSize canvas, QPointF hotspot, double zoom,
143 double screenScale) noexcept;
144
147SCORE_LIB_BASE_EXPORT
149
159SCORE_LIB_BASE_EXPORT
160QPixmap renderDragCursor(CursorArtwork a, const CursorGeometry& g, bool topLeft);
161
166namespace win32_hit
167{
168constexpr int Error = -2;
169constexpr int Transparent = -1;
170constexpr int Nowhere = 0;
171constexpr int Client = 1;
172constexpr int Caption = 2;
173constexpr int SysMenu = 3;
174constexpr int GrowBox = 4;
175constexpr int Menu = 5;
176constexpr int HScroll = 6;
177constexpr int VScroll = 7;
178constexpr int MinButton = 8;
179constexpr int MaxButton = 9;
180constexpr int Left = 10;
181constexpr int Right = 11;
182constexpr int Top = 12;
183constexpr int TopLeft = 13;
184constexpr int TopRight = 14;
185constexpr int Bottom = 15;
186constexpr int BottomLeft = 16;
187constexpr int BottomRight = 17;
188constexpr int Border = 18;
189constexpr int Object = 19;
190constexpr int Close = 20;
191constexpr int Help = 21;
192}
193
200SCORE_LIB_BASE_EXPORT
201CursorArtwork windowsHitTestCursor(int hitTest, bool windowBlocked) noexcept;
202
215class SCORE_LIB_BASE_EXPORT CursorTheme final : public QObject
216{
217public:
218 static CursorTheme& instance();
219
222 static void setStartupZoom(double zoom) noexcept;
223
226 void setZoom(double zoom);
227 double zoom() const noexcept { return m_zoom; }
228
230 void rebuild();
231
234 const QCursor& cursor(CursorArtwork a) const noexcept;
237 QCursor cursor(Qt::CursorShape s) const noexcept;
238
240 const QCursor& cursor(CursorArtwork a, double screenScale) const noexcept;
241
244 double screenScaleOf(const QScreen* screen) const noexcept;
245 double screenScaleOf(const QWindow& window) const noexcept;
246 double screenScaleOf(const QWidget& widget) const noexcept;
247
250 QPixmap dragCursor(Qt::DropAction action) const noexcept;
251 QPixmap dragCursor(Qt::DropAction action, double screenScale) const noexcept;
252
255 void setDragCursors(QDrag& drag) const;
256
262 void install();
263 bool installed() const noexcept { return m_installed; }
264
268 void fixWidget(QWidget& w) const;
269 void fixWindow(QWindow& w) const;
270
272 CursorPlatform platform() const noexcept { return m_platform; }
273 double screenScale() const noexcept;
274
275private:
276 struct Set;
277 struct Impl;
278
279 CursorTheme();
280 ~CursorTheme() override;
281 bool eventFilter(QObject* watched, QEvent* event) override;
282
283 void build();
284 void watchScreen(QScreen* screen);
285 void screensChanged();
286 void refixEverything();
287 void fixOverrideCursor() const;
288 void updatePointerScreen(QPointF globalPos) const;
289 void ensureBuilt() const;
290
291 const Set& set(double screenScale) const;
292 const Set& defaultSet() const;
293 const QCursor* remap(const QCursor& c, const Set& target) const;
294
295 std::unique_ptr<Impl> m_impl;
296 QPointF m_lastMousePos;
298 const QObject* m_lastMoveTarget{};
299 QPointF m_lastMoveLocal;
300 double m_zoom{1.};
301 CursorPlatform m_platform{CursorPlatform::Windows};
302 bool m_installed{};
303 bool m_built{};
304};
305}
Definition CursorTheme.hpp:216
CursorPlatform platform() const noexcept
Geometry the cursors of the primary screen are built with.
Definition CursorTheme.hpp:272
Represents a menu in the software.
Definition Menu.hpp:15
Base toolkit upon which the software is built.
Definition Application.cpp:85
CursorGeometry cursorGeometry(CursorPlatform platform, QSize canvas, QPointF hotspot, double zoom, double screenScale) noexcept
Definition CursorTheme.cpp:350
CursorArtwork windowsHitTestCursor(int hitTest, bool windowBlocked) noexcept
Definition CursorTheme.cpp:503
CursorArtwork cursorArtworkForShape(Qt::CursorShape s) noexcept
Definition CursorTheme.cpp:332
constexpr bool isThemeCursorShape(Qt::CursorShape s) noexcept
The shapes of Qt::CursorShape that the platform draws from its own theme.
Definition CursorTheme.hpp:88
QImage renderCursorArtwork(CursorArtwork a, const CursorGeometry &g)
Definition CursorTheme.cpp:419
CursorPlatform
How a platform plug-in of Qt turns a pixmap cursor into the one on screen.
Definition CursorTheme.hpp:95
@ X11
xcb: the pixmap is shown pixel for pixel, the hotspot is in pixels.
QPixmap renderDragCursor(CursorArtwork a, const CursorGeometry &g, bool topLeft)
Definition CursorTheme.cpp:462
CursorArtwork
Definition CursorTheme.hpp:33
STL namespace.
Definition CursorTheme.hpp:64
QPointF hotspot
Definition CursorTheme.hpp:73
bool mirrored
Definition CursorTheme.hpp:76
const char * svg
Path of the SVG source in the resources.
Definition CursorTheme.hpp:66
QSize size
Definition CursorTheme.hpp:69
Definition CursorTheme.hpp:116
QPoint pixelHotspot
The pixel of the pixmap the platform puts the hotspot on.
Definition CursorTheme.hpp:123
QSize pixelSize
Size and device pixel ratio of the pixmap to build the QCursor from.
Definition CursorTheme.hpp:118
QPoint renderOffset
Definition CursorTheme.hpp:127
QPoint hotspot
What to give QCursor as hotspot on that platform.
Definition CursorTheme.hpp:121