Unity 8
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
24 extern "C"
25 {
26 #include <xcursor.h>
27 }
28 
29 class CursorImage {
30 public:
31  virtual ~CursorImage() {}
32 
33  QImage qimage;
34  QPoint hotspot;
35 };
36 
37 class XCursorImage : public CursorImage {
38 public:
39  XCursorImage(const QString &theme, const QString &file);
40  virtual ~XCursorImage();
41 
42  XcursorImages *xcursorImages;
43 };
44 
45 class BuiltInCursorImage : public CursorImage {
46 public:
47  BuiltInCursorImage();
48 };
49 
50 class BlankCursorImage : public CursorImage {
51 public:
52  BlankCursorImage();
53 };
54 
55 class CustomCursorImage : public CursorImage {
56 public:
57  CustomCursorImage(const QCursor &cursor);
58 };
59 
60 class CursorImageProvider : public QQuickImageProvider
61 {
62 public:
63  CursorImageProvider();
64  virtual ~CursorImageProvider();
65 
66  static CursorImageProvider *instance() { return m_instance; }
67 
68 
69  QImage requestImage(const QString &cursorName, QSize *size, const QSize &requestedSize) override;
70 
71  QPoint hotspot(const QString &themeName, const QString &cursorName);
72 
73  void setCustomCursor(const QCursor &customCursor);
74 
75 private:
76  CursorImage *fetchCursor(const QString &cursorThemeAndName);
77  CursorImage *fetchCursor(const QString &themeName, const QString &cursorName);
78  CursorImage *fetchCursorHelper(const QString &themeName, const QString &cursorName);
79 
80  // themeName -> (cursorName -> cursorImage)
81  QMap<QString, QMap<QString, CursorImage*> > m_cursors;
82 
83  QScopedPointer<CursorImage> m_builtInCursorImage;
84  BlankCursorImage m_blankCursorImage;
85  QScopedPointer<CursorImage> m_customCursorImage;
86 
87  QMap<QString, QStringList> m_fallbackNames;
88 
89  static CursorImageProvider *m_instance;
90 };
91 
92 #endif // CURSORIMAGEPROVIDER_H