Lomiri
Loading...
Searching...
No Matches
CursorImageProvider.h
1/*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef CURSORIMAGEPROVIDER_H
18#define CURSORIMAGEPROVIDER_H
19
20#include <QQuickImageProvider>
21#include <QScopedPointer>
22
23// xcursor static lib
24extern "C"
25{
26#include <xcursor.h>
27}
28
29class CursorImage {
30public:
31 virtual ~CursorImage() {}
32
33 QImage qimage;
34
35 // TODO: consider if there's a need to animate the hotspot
36 // ie, if there's a need to make it an array of points, one for each frame.
37 // Maybe no single xcursor (or at least the ones we know of or use)
38 // vary its hotspot position through its animation.
39 QPoint hotspot;
40
41 int frameWidth{0};
42 int frameHeight{0};
43 int frameCount{1};
44 int frameDuration{40};
45
46 // Requested height when creating this cursor.
47 int requestedHeight{0};
48};
49
50class XCursorImage : public CursorImage {
51public:
52 XCursorImage(const QString &theme, const QString &file, int preferredCursorHeightPx);
53 virtual ~XCursorImage();
54};
55
56class BuiltInCursorImage : public CursorImage {
57public:
58 BuiltInCursorImage(int cursorHeight);
59};
60
61class BlankCursorImage : public CursorImage {
62public:
63 BlankCursorImage();
64};
65
66class CustomCursorImage : public CursorImage {
67public:
68 CustomCursorImage(const QCursor &cursor);
69};
70
71class CursorImageProvider : public QQuickImageProvider
72{
73public:
74 CursorImageProvider();
75 virtual ~CursorImageProvider();
76
77 static CursorImageProvider *instance() { return m_instance; }
78
79
80 QImage requestImage(const QString &cursorThemeAndNameAndHeight, QSize *size, const QSize &requestedSize) override;
81
82 CursorImage *fetchCursor(const QString &themeName, const QString &cursorName, int cursorHeight);
83
84 void setCustomCursor(const QCursor &customCursor);
85
86private:
87 CursorImage *fetchCursor(const QString &cursorThemeAndNameAndHeight);
88 CursorImage *fetchCursorHelper(const QString &themeName, const QString &cursorName, int cursorHeight);
89
90 // themeName -> (cursorName -> cursorImage)
91 // TODO: discard old, unused, cursors
92 QMap<QString, QMap<QString, CursorImage*> > m_cursors;
93
94 QScopedPointer<CursorImage> m_builtInCursorImage;
95 BlankCursorImage m_blankCursorImage;
96 QScopedPointer<CursorImage> m_customCursorImage;
97
98 QMap<QString, QStringList> m_fallbackNames;
99
100 static CursorImageProvider *m_instance;
101};
102
103#endif // CURSORIMAGEPROVIDER_H