Small improvements in IconItem
Summary: Don't construct a QUrl for every source strings. Check it's a file url first (which is the only kind of url we support at the moment) When extracting the path, use toLocalFile, so it works on platforms where path!=toLocalPath (e.g. windows) Don't split a string and get a chunk, but just extract the chunk we need with section. Reduces allocations that are automatically discarded. Narrow iconPath scope Test Plan: Tests still pass, plasmashell still works Reviewers: #frameworks, #plasma, mart Reviewed By: #plasma, mart Subscribers: plasma-devel Tags: #plasma, #frameworks Differential Revision: https://phabricator.kde.org/D6014
This commit is contained in:
parent
68ed01638c
commit
3b303d7363
@ -26,7 +26,6 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QSGSimpleTextureNode>
|
#include <QSGSimpleTextureNode>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QPixmap>
|
|
||||||
|
|
||||||
#include <kiconloader.h>
|
#include <kiconloader.h>
|
||||||
#include <kiconeffect.h>
|
#include <kiconeffect.h>
|
||||||
@ -156,10 +155,10 @@ void IconItem::setSource(const QVariant &source)
|
|||||||
|
|
||||||
if (!sourceString.isEmpty()) {
|
if (!sourceString.isEmpty()) {
|
||||||
//If a url in the form file:// is passed, take the image pointed by that from disk
|
//If a url in the form file:// is passed, take the image pointed by that from disk
|
||||||
QUrl url(sourceString);
|
if (sourceString.startsWith(QLatin1String("file:"))) {
|
||||||
if (url.isLocalFile()) {
|
const QUrl url(sourceString);
|
||||||
m_icon = QIcon();
|
m_icon = QIcon();
|
||||||
m_imageIcon = QImage(url.path());
|
m_imageIcon = QImage(url.toLocalFile());
|
||||||
m_svgIconName.clear();
|
m_svgIconName.clear();
|
||||||
delete m_svgIcon;
|
delete m_svgIcon;
|
||||||
m_svgIcon = 0;
|
m_svgIcon = 0;
|
||||||
@ -174,7 +173,7 @@ void IconItem::setSource(const QVariant &source)
|
|||||||
|
|
||||||
if (m_usesPlasmaTheme) {
|
if (m_usesPlasmaTheme) {
|
||||||
//try as a svg icon from plasma theme
|
//try as a svg icon from plasma theme
|
||||||
m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.split('-').first());
|
m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.section('-', 0, 0));
|
||||||
m_svgIcon->setContainsMultipleImages(true);
|
m_svgIcon->setContainsMultipleImages(true);
|
||||||
//invalidate the image path to recalculate it later
|
//invalidate the image path to recalculate it later
|
||||||
} else {
|
} else {
|
||||||
@ -562,23 +561,23 @@ void IconItem::loadPixmap()
|
|||||||
return;
|
return;
|
||||||
} else if (m_svgIcon) {
|
} else if (m_svgIcon) {
|
||||||
m_svgIcon->resize(size, size);
|
m_svgIcon->resize(size, size);
|
||||||
if (m_svgIcon->hasElement(m_svgIconName)) {
|
if (!m_svgIconName.isEmpty() && m_svgIcon->hasElement(m_svgIconName)) {
|
||||||
result = m_svgIcon->pixmap(m_svgIconName);
|
result = m_svgIcon->pixmap(m_svgIconName);
|
||||||
} else if (!m_svgIconName.isEmpty()) {
|
} else if (!m_svgIconName.isEmpty()) {
|
||||||
const auto *iconTheme = KIconLoader::global()->theme();
|
const auto *iconTheme = KIconLoader::global()->theme();
|
||||||
QString iconPath;
|
|
||||||
if (iconTheme) {
|
if (iconTheme) {
|
||||||
iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest);
|
QString iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svg"), size, KIconLoader::MatchBest);
|
||||||
if (iconPath.isEmpty()) {
|
if (iconPath.isEmpty()) {
|
||||||
iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svgz"), qMin(width(), height()), KIconLoader::MatchBest);
|
iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svgz"), size, KIconLoader::MatchBest);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!iconPath.isEmpty()) {
|
||||||
|
m_svgIcon->setImagePath(iconPath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "KIconLoader has no theme set";
|
qWarning() << "KIconLoader has no theme set";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iconPath.isEmpty()) {
|
|
||||||
m_svgIcon->setImagePath(iconPath);
|
|
||||||
}
|
|
||||||
result = m_svgIcon->pixmap();
|
result = m_svgIcon->pixmap();
|
||||||
}
|
}
|
||||||
} else if (!m_icon.isNull()) {
|
} else if (!m_icon.isNull()) {
|
||||||
|
@ -528,10 +528,10 @@ QRectF SvgPrivate::elementRect(const QString &elementId)
|
|||||||
return QRectF();
|
return QRectF();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString id = cacheId(elementId);
|
const QString id = cacheId(elementId);
|
||||||
|
const auto it = localRectCache.constFind(id);
|
||||||
if (localRectCache.contains(id)) {
|
if (it != localRectCache.constEnd()) {
|
||||||
return localRectCache.value(id);
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF rect;
|
QRectF rect;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user