File indexing completed on 2024-05-12 04:37:48
0001 /* 0002 SPDX-FileCopyrightText: 2017 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_TEMPLATEPREVIEWICON_H 0008 #define KDEVPLATFORM_TEMPLATEPREVIEWICON_H 0009 0010 #include <QSharedDataPointer> 0011 #include <QMetaType> 0012 0013 #include <language/languageexport.h> 0014 0015 class QPixmap; 0016 0017 namespace KDevelop { 0018 class TemplatePreviewIconData; 0019 0020 /** 0021 * @brief A class for loading preview images/icons as specified in a template description on demand 0022 * 0023 * It stores the icon name as extracted from the template description together with 0024 * the path to the archive. Only on demand will the icon file tried to be loaded and 0025 * returned as pixmap object. 0026 * To support also legacy template installations with the preview image installed as separate file, 0027 * the local directory prefix in the QStandardPaths::GenericDataLocation is stored as well 0028 * to search also those paths as fallback. 0029 * 0030 * If the icon name is empty, no matching icon file could be found or no image successfully loaded, 0031 * the returned pixmap will default to a themed "kdevelop" icon image (128x128). 0032 **/ 0033 class KDEVPLATFORMLANGUAGE_EXPORT TemplatePreviewIcon 0034 { 0035 public: 0036 /** 0037 * Creates a new template preview icon object 0038 * 0039 * @param iconName the raw icon name as specified in the template description 0040 * @param archivePath absolute path to the template archive the icon is used by 0041 * @param dataDir local directory prefix of the icon file if searching it through QStandardPaths::GenericDataLocation 0042 **/ 0043 TemplatePreviewIcon(const QString& iconName, const QString& archivePath, const QString& dataDir); 0044 TemplatePreviewIcon(); 0045 TemplatePreviewIcon(const TemplatePreviewIcon& other); 0046 ~TemplatePreviewIcon(); 0047 0048 TemplatePreviewIcon& operator=(const TemplatePreviewIcon& other); 0049 0050 public: 0051 /** 0052 * Generates a pixmap to be used as preview for a template. 0053 * Either from the preview image file as specified, or falling back 0054 * to a themed "kdevelop" icon image (128x128). 0055 * The pixmap is not cached, . 0056 * 0057 * @return pixmap to be used as preview for a template 0058 **/ 0059 QPixmap pixmap() const; 0060 0061 private: 0062 QSharedDataPointer<TemplatePreviewIconData> d; 0063 }; 0064 } 0065 0066 Q_DECLARE_METATYPE(KDevelop::TemplatePreviewIcon) 0067 0068 #endif // KDEVPLATFORM_TEMPLATEPREVIEWICON_H