MCPcopy Create free account
hub / github.com/KDE/kdevelop / pixmap

Method pixmap

kdevplatform/language/codegen/templatepreviewicon.cpp:60–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60QPixmap TemplatePreviewIcon::pixmap() const
61{
62 if (!d->iconName.isEmpty()) {
63 // read icon from archive
64 QScopedPointer<KArchive> templateArchive;
65 if (QFileInfo(d->archivePath).completeSuffix() == QLatin1String("zip")) {
66 templateArchive.reset(new KZip(d->archivePath));
67 } else {
68 templateArchive.reset(new KTar(d->archivePath));
69 }
70
71 if (templateArchive->open(QIODevice::ReadOnly)) {
72 const KArchiveFile* iconFile = templateArchive->directory()->file(d->iconName);
73 if (iconFile) {
74 QPixmap pixmap;
75 const bool loadSuccess = pixmap.loadFromData(iconFile->data());
76 if (loadSuccess) {
77 return pixmap;
78 }
79 qCWarning(LANGUAGE) << "Could not load preview icon" << d->iconName << "from" << d->archivePath;
80 }
81 }
82
83 // support legacy templates with image files installed separately in the filesystem
84 const QString iconFilePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
85 d->dataDir + d->iconName);
86 if (!iconFilePath.isEmpty()) {
87 QPixmap pixmap(iconFilePath);
88 if (!pixmap.isNull()) {
89 return pixmap;
90 }
91 qCWarning(LANGUAGE) << "Could not load preview icon" << iconFilePath << "as wanted for" << d->archivePath;
92 }
93 }
94
95 // try theme icon or default to a kdevelop icon
96 // QIcon::hasThemeIcon for empty string can yield true with some engines, not wanted here
97 const bool isThemeIcon = (!d->iconName.isEmpty() && QIcon::hasThemeIcon(d->iconName));
98 const QString iconName = isThemeIcon ? d->iconName : QStringLiteral("kdevelop");
99
100 const QIcon icon = QIcon::fromTheme(iconName);
101 return icon.pixmap(128, 128);
102}

Callers 15

breakpointPixmapMethod · 0.80
notifyHitMethod · 0.80
paintEventMethod · 0.80
statusIconChangedMethod · 0.80
htmlImgFunction · 0.80
OneUseWidgetMethod · 0.80
TopContextUsesWidgetMethod · 0.80

Calls 8

isNullMethod · 0.80
QFileInfoClass · 0.50
isEmptyMethod · 0.45
resetMethod · 0.45
openMethod · 0.45
fileMethod · 0.45
directoryMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected