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 CursorImageProvider : public QQuickImageProvider
51 {
52 public:
53  CursorImageProvider();
54  virtual ~CursorImageProvider();
55 
56  static CursorImageProvider *instance() { return m_instance; }
57 
58 
59  QImage requestImage(const QString &cursorName, QSize *size, const QSize &requestedSize) override;
60 
61  QPoint hotspot(const QString &themeName, const QString &cursorName);
62 
63 private:
64  CursorImage *fetchCursor(const QString &cursorThemeAndName);
65  CursorImage *fetchCursor(const QString &themeName, const QString &cursorName);
66  CursorImage *fetchCursorHelper(const QString &themeName, const QString &cursorName);
67 
68  // themeName -> (cursorName -> cursorImage)
69  QMap<QString, QMap<QString, CursorImage*> > m_cursors;
70 
71  QScopedPointer<CursorImage> m_builtInCursorImage;
72 
73  static CursorImageProvider *m_instance;
74 };
75 
76 #endif // CURSORIMAGEPROVIDER_H