Changeset View
Changeset View
Standalone View
Standalone View
language/codegen/templatepreviewicon.h
- This file was added.
1 | /* This file is part of KDevelop | ||||
---|---|---|---|---|---|
2 | Copyright 2017 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #ifndef KDEVPLATFORM_TEMPLATEPREVIEWICON_H | ||||
21 | #define KDEVPLATFORM_TEMPLATEPREVIEWICON_H | ||||
22 | | ||||
23 | #include <QSharedDataPointer> | ||||
24 | #include <QMetaType> | ||||
25 | | ||||
26 | #include <language/languageexport.h> | ||||
27 | | ||||
28 | class QPixmap; | ||||
29 | | ||||
30 | namespace KDevelop | ||||
31 | { | ||||
32 | | ||||
33 | class TemplatePreviewIconData; | ||||
34 | | ||||
35 | /** | ||||
36 | * @brief A class for loading preview images/icons as specified in a template description on demand | ||||
37 | * | ||||
38 | * It stores the icon name as extracted from the template description together with | ||||
39 | * the path to the archive. Only on demand will the icon file tried to be loaded and | ||||
40 | * returned as pixmap object. | ||||
41 | * To support also legacy template installations with the preview image installed as separate file, | ||||
42 | * the local directory prefix in the QStandardPaths::GenericDataLocation is stored as well | ||||
43 | * to search also those paths as fallback. | ||||
44 | * | ||||
45 | * If the icon name is empty, no matching icon file could be found or no image successfully loaded, | ||||
46 | * the returned pixmap will default to a themed "kdevelop" icon image (128x128). | ||||
47 | **/ | ||||
48 | class KDEVPLATFORMLANGUAGE_EXPORT TemplatePreviewIcon | ||||
49 | { | ||||
50 | public: | ||||
51 | /** | ||||
52 | * Creates a new template preview icon object | ||||
53 | * | ||||
54 | * @param iconName the raw icon name as specified in the template description | ||||
55 | * @param archivePath absolute path to the template archive the icon is used by | ||||
56 | * @param dataDir local directory prefix of the icon file if searching it through QStandardPaths::GenericDataLocation | ||||
57 | **/ | ||||
58 | TemplatePreviewIcon(const QString& iconName, const QString& archivePath, const QString& dataDir); | ||||
59 | TemplatePreviewIcon(); | ||||
60 | TemplatePreviewIcon(const TemplatePreviewIcon& other); | ||||
61 | ~TemplatePreviewIcon(); | ||||
62 | | ||||
63 | TemplatePreviewIcon& operator=(const TemplatePreviewIcon& other); | ||||
64 | | ||||
65 | public: | ||||
66 | /** | ||||
67 | * Generates a pixmap to be used as preview for a template. | ||||
68 | * Either from the preview image file as specified, or falling back | ||||
69 | * to a themed "kdevelop" icon image (128x128). | ||||
70 | * The pixmap is not cached, . | ||||
71 | * | ||||
72 | * @return pixmap to be used as preview for a template | ||||
73 | **/ | ||||
74 | QPixmap pixmap() const; | ||||
75 | | ||||
76 | private: | ||||
77 | QSharedDataPointer<TemplatePreviewIconData> d; | ||||
78 | }; | ||||
79 | | ||||
80 | } | ||||
81 | | ||||
82 | Q_DECLARE_METATYPE(KDevelop::TemplatePreviewIcon) | ||||
83 | | ||||
84 | #endif // KDEVPLATFORM_TEMPLATEPREVIEWICON_H |