1 | /*************************************************************************** |
2 | * Copyright 2012 Viranch Mehta <viranch.mehta@gmail.com> * |
3 | * * |
4 | * This program is free software; you can redistribute it and/or modify * |
5 | * it under the terms of the GNU Library General Public License * |
6 | * version 2 as published by the Free Software Foundation * |
7 | * * |
8 | * This program is distributed in the hope that it will be useful, * |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
11 | * GNU Library General Public License for more details. * |
12 | * * |
13 | * You should have received a copy of the GNU Library General Public * |
14 | * License along with this program; if not, write to the * |
15 | * Free Software Foundation, Inc., * |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
17 | ***************************************************************************/ |
18 | |
19 | #ifndef KGIMAGEPROVIDER_H |
20 | #define KGIMAGEPROVIDER_H |
21 | |
22 | #include <QDeclarativeImageProvider> |
23 | #include <QSvgRenderer> |
24 | |
25 | class KgThemeProvider; |
26 | |
27 | /** |
28 | * @class KgImageProvider |
29 | * @since 4.11 |
30 | * @short A QDeclarativeImageProvider that renders requested sprites and |
31 | * returns corresponding pixmap to the QML view. |
32 | * |
33 | * This class is a QDeclarativeImageProvider that takes a KgThemeProvider |
34 | * in its constructor and uses it to get full path to SVGs. These theme |
35 | * SVGs are read and requested sprite pixmap is extracted and given to |
36 | * the QML image element that requests it. |
37 | * |
38 | * For porting KDE games to QML, there is a KgItem QML component provided |
39 | * by KgCore QML plugin which is a small wrapper to request pixmaps from |
40 | * this KgImageProvider. See KgItem's documentation for details. |
41 | */ |
42 | class KgImageProvider : public QDeclarativeImageProvider |
43 | { |
44 | public: |
45 | ///Construcs a new KgImageProvider with the supplied KgThemeProvider |
46 | ///@param provider The KgThemeProvider used to discover the game's |
47 | ///themes. |
48 | KgImageProvider(KgThemeProvider* provider); |
49 | |
50 | ///Reimplemented method that is called when a sprite pixmap is requested |
51 | QImage requestImage(const QString& source, QSize *size, const QSize &requestedSize); |
52 | |
53 | private: |
54 | void reloadRenderer(); |
55 | |
56 | QString m_themeName; |
57 | KgThemeProvider* m_provider; |
58 | QSvgRenderer m_renderer; |
59 | |
60 | }; |
61 | |
62 | #endif //KGIMAGEPROVIDER_H |
63 | |