Browse Source

Merge pull request #12894 from Chocobo1/thememanager

Improvements to UIThemeManager
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
9aba0cbcf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/gui/rss/feedlistwidget.cpp
  2. 21
      src/gui/uithememanager.cpp
  3. 4
      src/gui/uithememanager.h

12
src/gui/rss/feedlistwidget.cpp

@ -85,13 +85,13 @@ void FeedListWidget::handleFeedStateChanged(RSS::Feed *feed)
QIcon icon; QIcon icon;
if (feed->isLoading()) if (feed->isLoading())
icon = UIThemeManager::instance()->getIcon(QStringLiteral("loading")); icon = UIThemeManager::instance()->getIcon(QLatin1String("loading"));
else if (feed->hasError()) else if (feed->hasError())
icon = UIThemeManager::instance()->getIcon(QStringLiteral("unavailable")); icon = UIThemeManager::instance()->getIcon(QLatin1String("unavailable"));
else if (!feed->iconPath().isEmpty()) else if (!feed->iconPath().isEmpty())
icon = QIcon(feed->iconPath()); icon = QIcon(feed->iconPath());
else else
icon = UIThemeManager::instance()->getIcon(QStringLiteral("application-rss+xml")); icon = UIThemeManager::instance()->getIcon(QLatin1String("application-rss+xml"));
item->setData(0, Qt::DecorationRole, icon); item->setData(0, Qt::DecorationRole, icon);
} }
@ -237,14 +237,14 @@ QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem
if (feed->isLoading()) if (feed->isLoading())
icon = UIThemeManager::instance()->getIcon(QLatin1String("loading")); icon = UIThemeManager::instance()->getIcon(QLatin1String("loading"));
else if (feed->hasError()) else if (feed->hasError())
icon = UIThemeManager::instance()->getIcon(QStringLiteral("unavailable")); icon = UIThemeManager::instance()->getIcon(QLatin1String("unavailable"));
else if (!feed->iconPath().isEmpty()) else if (!feed->iconPath().isEmpty())
icon = QIcon(feed->iconPath()); icon = QIcon(feed->iconPath());
else else
icon = UIThemeManager::instance()->getIcon(QStringLiteral("application-rss+xml")); icon = UIThemeManager::instance()->getIcon(QLatin1String("application-rss+xml"));
} }
else { else {
icon = UIThemeManager::instance()->getIcon("inode-directory"); icon = UIThemeManager::instance()->getIcon(QLatin1String("inode-directory"));
} }
item->setData(0, Qt::DecorationRole, icon); item->setData(0, Qt::DecorationRole, icon);

21
src/gui/uithememanager.cpp

@ -31,7 +31,6 @@
#include <QApplication> #include <QApplication>
#include <QFile> #include <QFile>
#include <QIcon>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QPalette> #include <QPalette>
@ -77,6 +76,9 @@ void UIThemeManager::initInstance()
UIThemeManager::UIThemeManager() UIThemeManager::UIThemeManager()
: m_useCustomTheme(Preferences::instance()->useCustomUITheme()) : m_useCustomTheme(Preferences::instance()->useCustomUITheme())
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
, m_useSystemTheme(Preferences::instance()->useSystemIconTheme())
#endif
{ {
const Preferences *const pref = Preferences::instance(); const Preferences *const pref = Preferences::instance();
if (m_useCustomTheme) { if (m_useCustomTheme) {
@ -88,10 +90,6 @@ UIThemeManager::UIThemeManager()
applyPalette(); applyPalette();
} }
} }
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
m_useSystemTheme = pref->useSystemIconTheme();
#endif
} }
UIThemeManager *UIThemeManager::instance() UIThemeManager *UIThemeManager::instance()
@ -127,14 +125,15 @@ QIcon UIThemeManager::getIcon(const QString &iconId, const QString &fallback) co
return icon; return icon;
} }
#endif #endif
// cache to avoid rescaling svg icons
static QHash<QString, QIcon> iconCache; // Cache to avoid rescaling svg icons
const auto iter = iconCache.find(iconId); // And don't cache system icons because users might change them at run time
if (iter != iconCache.end()) const auto iter = m_iconCache.find(iconId);
if (iter != m_iconCache.end())
return *iter; return *iter;
const QIcon icon {getIconPathFromResources(iconId, fallback)}; const QIcon icon {getIconPathFromResources(iconId, fallback)};
iconCache[iconId] = icon; m_iconCache[iconId] = icon;
return icon; return icon;
} }
@ -153,7 +152,7 @@ QString UIThemeManager::getIconPath(const QString &iconId) const
{ {
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
if (m_useSystemTheme) { if (m_useSystemTheme) {
QString path = Utils::Fs::tempPath() + iconId + ".png"; QString path = Utils::Fs::tempPath() + iconId + QLatin1String(".png");
if (!QFile::exists(path)) { if (!QFile::exists(path)) {
const QIcon icon = QIcon::fromTheme(iconId); const QIcon icon = QIcon::fromTheme(iconId);
if (!icon.isNull()) if (!icon.isNull())

4
src/gui/uithememanager.h

@ -31,6 +31,7 @@
#include <QColor> #include <QColor>
#include <QHash> #include <QHash>
#include <QIcon>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
@ -60,8 +61,9 @@ private:
static UIThemeManager *m_instance; static UIThemeManager *m_instance;
QHash<QString, QColor> m_colors; QHash<QString, QColor> m_colors;
mutable QHash<QString, QIcon> m_iconCache;
const bool m_useCustomTheme; const bool m_useCustomTheme;
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
bool m_useSystemTheme; const bool m_useSystemTheme;
#endif #endif
}; };

Loading…
Cancel
Save