Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/core/iconitem.cpp
Show All 20 Lines | |||||
21 | #include "iconitem.h" | 21 | #include "iconitem.h" | ||
22 | #include <QDebug> | 22 | #include <QDebug> | ||
23 | #include <QPaintEngine> | 23 | #include <QPaintEngine> | ||
24 | #include <QPainter> | 24 | #include <QPainter> | ||
25 | #include <QPropertyAnimation> | 25 | #include <QPropertyAnimation> | ||
26 | #include <QPixmap> | 26 | #include <QPixmap> | ||
27 | #include <QSGSimpleTextureNode> | 27 | #include <QSGSimpleTextureNode> | ||
28 | #include <QQuickWindow> | 28 | #include <QQuickWindow> | ||
29 | #include <QPixmap> | | |||
30 | 29 | | |||
31 | #include <kiconloader.h> | 30 | #include <kiconloader.h> | ||
32 | #include <kiconeffect.h> | 31 | #include <kiconeffect.h> | ||
33 | #include <KIconTheme> | 32 | #include <KIconTheme> | ||
34 | 33 | | |||
35 | #include "fadingnode_p.h" | 34 | #include "fadingnode_p.h" | ||
36 | #include <QuickAddons/ManagedTextureNode> | 35 | #include <QuickAddons/ManagedTextureNode> | ||
37 | #include "units.h" | 36 | #include "units.h" | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 143 | { | |||
151 | 150 | | |||
152 | // If the QIcon was created with QIcon::fromTheme(), try to load it as svg | 151 | // If the QIcon was created with QIcon::fromTheme(), try to load it as svg | ||
153 | if (source.canConvert<QIcon>() && !source.value<QIcon>().name().isEmpty()) { | 152 | if (source.canConvert<QIcon>() && !source.value<QIcon>().name().isEmpty()) { | ||
154 | sourceString = source.value<QIcon>().name(); | 153 | sourceString = source.value<QIcon>().name(); | ||
155 | } | 154 | } | ||
156 | 155 | | |||
157 | if (!sourceString.isEmpty()) { | 156 | if (!sourceString.isEmpty()) { | ||
158 | //If a url in the form file:// is passed, take the image pointed by that from disk | 157 | //If a url in the form file:// is passed, take the image pointed by that from disk | ||
159 | QUrl url(sourceString); | 158 | if (sourceString.startsWith(QLatin1String("file:"))) { | ||
160 | if (url.isLocalFile()) { | 159 | const QUrl url(sourceString); | ||
161 | m_icon = QIcon(); | 160 | m_icon = QIcon(); | ||
162 | m_imageIcon = QImage(url.path()); | 161 | m_imageIcon = QImage(url.toLocalFile()); | ||
163 | m_svgIconName.clear(); | 162 | m_svgIconName.clear(); | ||
164 | delete m_svgIcon; | 163 | delete m_svgIcon; | ||
165 | m_svgIcon = 0; | 164 | m_svgIcon = 0; | ||
166 | } else { | 165 | } else { | ||
167 | if (!m_svgIcon) { | 166 | if (!m_svgIcon) { | ||
168 | m_svgIcon = new Plasma::Svg(this); | 167 | m_svgIcon = new Plasma::Svg(this); | ||
169 | m_svgIcon->setColorGroup(m_colorGroup); | 168 | m_svgIcon->setColorGroup(m_colorGroup); | ||
170 | m_svgIcon->setStatus(m_status); | 169 | m_svgIcon->setStatus(m_status); | ||
171 | m_svgIcon->setDevicePixelRatio((window() ? window()->devicePixelRatio() : qApp->devicePixelRatio())); | 170 | m_svgIcon->setDevicePixelRatio((window() ? window()->devicePixelRatio() : qApp->devicePixelRatio())); | ||
172 | connect(m_svgIcon, &Plasma::Svg::repaintNeeded, this, &IconItem::schedulePixmapUpdate); | 171 | connect(m_svgIcon, &Plasma::Svg::repaintNeeded, this, &IconItem::schedulePixmapUpdate); | ||
173 | } | 172 | } | ||
174 | 173 | | |||
175 | if (m_usesPlasmaTheme) { | 174 | if (m_usesPlasmaTheme) { | ||
176 | //try as a svg icon from plasma theme | 175 | //try as a svg icon from plasma theme | ||
177 | m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.split('-').first()); | 176 | m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.section('-', 0, 0)); | ||
178 | m_svgIcon->setContainsMultipleImages(true); | 177 | m_svgIcon->setContainsMultipleImages(true); | ||
179 | //invalidate the image path to recalculate it later | 178 | //invalidate the image path to recalculate it later | ||
180 | } else { | 179 | } else { | ||
181 | m_svgIcon->setImagePath(QString()); | 180 | m_svgIcon->setImagePath(QString()); | ||
182 | } | 181 | } | ||
183 | 182 | | |||
184 | //success? | 183 | //success? | ||
185 | if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) { | 184 | if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) { | ||
▲ Show 20 Lines • Show All 371 Lines • ▼ Show 20 Line(s) | 545 | { | |||
557 | QPixmap result; | 556 | QPixmap result; | ||
558 | if (size <= 0) { | 557 | if (size <= 0) { | ||
559 | m_iconPixmap = QPixmap(); | 558 | m_iconPixmap = QPixmap(); | ||
560 | m_animation->stop(); | 559 | m_animation->stop(); | ||
561 | update(); | 560 | update(); | ||
562 | return; | 561 | return; | ||
563 | } else if (m_svgIcon) { | 562 | } else if (m_svgIcon) { | ||
564 | m_svgIcon->resize(size, size); | 563 | m_svgIcon->resize(size, size); | ||
565 | if (m_svgIcon->hasElement(m_svgIconName)) { | 564 | if (!m_svgIconName.isEmpty() && m_svgIcon->hasElement(m_svgIconName)) { | ||
566 | result = m_svgIcon->pixmap(m_svgIconName); | 565 | result = m_svgIcon->pixmap(m_svgIconName); | ||
567 | } else if (!m_svgIconName.isEmpty()) { | 566 | } else if (!m_svgIconName.isEmpty()) { | ||
568 | const auto *iconTheme = KIconLoader::global()->theme(); | 567 | const auto *iconTheme = KIconLoader::global()->theme(); | ||
569 | QString iconPath; | | |||
570 | if (iconTheme) { | 568 | if (iconTheme) { | ||
571 | iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest); | 569 | QString iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svg"), size, KIconLoader::MatchBest); | ||
572 | if (iconPath.isEmpty()) { | 570 | if (iconPath.isEmpty()) { | ||
573 | iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svgz"), qMin(width(), height()), KIconLoader::MatchBest); | 571 | iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svgz"), size, KIconLoader::MatchBest); | ||
574 | } | | |||
575 | } else { | | |||
576 | qWarning() << "KIconLoader has no theme set"; | | |||
577 | } | 572 | } | ||
578 | 573 | | |||
579 | if (!iconPath.isEmpty()) { | 574 | if (!iconPath.isEmpty()) { | ||
580 | m_svgIcon->setImagePath(iconPath); | 575 | m_svgIcon->setImagePath(iconPath); | ||
581 | } | 576 | } | ||
577 | } else { | ||||
578 | qWarning() << "KIconLoader has no theme set"; | ||||
579 | } | ||||
580 | | ||||
582 | result = m_svgIcon->pixmap(); | 581 | result = m_svgIcon->pixmap(); | ||
583 | } | 582 | } | ||
584 | } else if (!m_icon.isNull()) { | 583 | } else if (!m_icon.isNull()) { | ||
585 | result = m_icon.pixmap(QSize(size, size) * (window() ? window()->devicePixelRatio() : qApp->devicePixelRatio())); | 584 | result = m_icon.pixmap(QSize(size, size) * (window() ? window()->devicePixelRatio() : qApp->devicePixelRatio())); | ||
586 | } else if (!m_imageIcon.isNull()) { | 585 | } else if (!m_imageIcon.isNull()) { | ||
587 | result = QPixmap::fromImage(m_imageIcon); | 586 | result = QPixmap::fromImage(m_imageIcon); | ||
588 | } else { | 587 | } else { | ||
589 | m_iconPixmap = QPixmap(); | 588 | m_iconPixmap = QPixmap(); | ||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |