From 8b437821a27dc1f5c45115c7550d8370ee0b295e Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 12 Jan 2014 16:57:29 +0100 Subject: [PATCH] Add ability to load icons with on/off state. --- src/core/FilePath.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ src/core/FilePath.h | 1 + 2 files changed, 46 insertions(+) diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index dd300ec1d..52db1ed28 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -117,6 +117,51 @@ QIcon FilePath::icon(const QString& category, const QString& name, bool fromThem return icon; } +QIcon FilePath::onOffIcon(const QString& category, const QString& name) +{ + QString combinedName = category + "/" + name; + QString cacheName = "onoff/" + combinedName; + + QIcon icon = m_iconCache.value(cacheName); + + if (!icon.isNull()) { + return icon; + } + + for (int i = 0; i < 2; i++) { + QIcon::State state; + QString stateName; + + if (i == 0) { + state = QIcon::Off; + stateName = "off"; + } + else { + state = QIcon::On; + stateName = "on"; + } + + QList pngSizes; + pngSizes << 16 << 22 << 24 << 32 << 48 << 64 << 128; + QString filename; + Q_FOREACH (int size, pngSizes) { + filename = QString("%1/icons/application/%2x%2/%3-%4.png").arg(m_dataPath, QString::number(size), + combinedName, stateName); + if (QFile::exists(filename)) { + icon.addFile(filename, QSize(size, size), QIcon::Normal, state); + } + } + filename = QString("%1/icons/application/scalable/%3-%4.svgz").arg(m_dataPath, combinedName, stateName); + if (QFile::exists(filename)) { + icon.addFile(filename, QSize(), QIcon::Normal, state); + } + } + + m_iconCache.insert(cacheName, icon); + + return icon; +} + FilePath::FilePath() { if (false) { diff --git a/src/core/FilePath.h b/src/core/FilePath.h index 411cbbc7d..9e98d3e39 100644 --- a/src/core/FilePath.h +++ b/src/core/FilePath.h @@ -31,6 +31,7 @@ public: QString pluginPath(const QString& name); QIcon applicationIcon(); QIcon icon(const QString& category, const QString& name, bool fromTheme = true); + QIcon onOffIcon(const QString& category, const QString& name); static FilePath* instance();