diff options
author | louib <code@louib.net> | 2020-10-06 03:41:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 03:41:00 +0300 |
commit | af4ecb4aa15506fed9a06fc56d4e4c05a498ba24 (patch) | |
tree | 9d9685bfc211060e8537cadc0eebb84f0c379d23 /src/core/Resources.cpp | |
parent | ba8611cf4caf38e9d84776e09e54069aa0bd0b27 (diff) |
Move icon handling from Resources to gui/Icons (#5506)
Diffstat (limited to 'src/core/Resources.cpp')
-rw-r--r-- | src/core/Resources.cpp | 142 |
1 files changed, 1 insertions, 141 deletions
diff --git a/src/core/Resources.cpp b/src/core/Resources.cpp index ae8c0d46a..463abe530 100644 --- a/src/core/Resources.cpp +++ b/src/core/Resources.cpp @@ -18,17 +18,13 @@ #include "Resources.h" -#include <QBitmap> +#include <QCoreApplication> #include <QDir> #include <QLibrary> -#include <QPainter> -#include <QStyle> #include "config-keepassx.h" #include "core/Config.h" #include "core/Global.h" -#include "gui/MainWindow.h" -#include "gui/osutils/OSUtils.h" Resources* Resources::m_instance(nullptr); @@ -96,138 +92,6 @@ QString Resources::wordlistPath(const QString& name) const return dataPath(QStringLiteral("wordlists/%1").arg(name)); } -QIcon Resources::applicationIcon() -{ - return icon("keepassxc", false); -} - -QString Resources::trayIconAppearance() const -{ - auto iconAppearance = config()->get(Config::GUI_TrayIconAppearance).toString(); - if (iconAppearance.isNull()) { -#ifdef Q_OS_MACOS - iconAppearance = osUtils->isDarkMode() ? "monochrome-light" : "monochrome-dark"; -#else - iconAppearance = "monochrome-light"; -#endif - } - return iconAppearance; -} - -QIcon Resources::trayIcon() -{ - return trayIconUnlocked(); -} - -QIcon Resources::trayIconLocked() -{ - auto iconApperance = trayIconAppearance(); - - if (iconApperance == "monochrome-light") { - return icon("keepassxc-monochrome-light-locked", false); - } - if (iconApperance == "monochrome-dark") { - return icon("keepassxc-monochrome-dark-locked", false); - } - return icon("keepassxc-locked", false); -} - -QIcon Resources::trayIconUnlocked() -{ - auto iconApperance = trayIconAppearance(); - - if (iconApperance == "monochrome-light") { - return icon("keepassxc-monochrome-light", false); - } - if (iconApperance == "monochrome-dark") { - return icon("keepassxc-monochrome-dark", false); - } - return icon("keepassxc", false); -} - -QIcon Resources::icon(const QString& name, bool recolor, const QColor& overrideColor) -{ - QIcon icon = m_iconCache.value(name); - - if (!icon.isNull() && !overrideColor.isValid()) { - return icon; - } - - // Resetting the application theme name before calling QIcon::fromTheme() is required for hacky - // QPA platform themes such as qt5ct, which randomly mess with the configured icon theme. - // If we do not reset the theme name here, it will become empty at some point, causing - // Qt to look for icons at the user-level and global default locations. - // - // See issue #4963: https://github.com/keepassxreboot/keepassxc/issues/4963 - // and qt5ct issue #80: https://sourceforge.net/p/qt5ct/tickets/80/ - QIcon::setThemeName("application"); - - icon = QIcon::fromTheme(name); - if (getMainWindow() && recolor) { - const QRect rect(0, 0, 48, 48); - QImage img = icon.pixmap(rect.width(), rect.height()).toImage(); - img = img.convertToFormat(QImage::Format_ARGB32_Premultiplied); - icon = {}; - - QPainter painter(&img); - painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); - - if (!overrideColor.isValid()) { - QPalette palette = getMainWindow()->palette(); - painter.fillRect(rect, palette.color(QPalette::Normal, QPalette::WindowText)); - icon.addPixmap(QPixmap::fromImage(img), QIcon::Normal); - - painter.fillRect(rect, palette.color(QPalette::Active, QPalette::ButtonText)); - icon.addPixmap(QPixmap::fromImage(img), QIcon::Active); - - painter.fillRect(rect, palette.color(QPalette::Active, QPalette::HighlightedText)); - icon.addPixmap(QPixmap::fromImage(img), QIcon::Selected); - - painter.fillRect(rect, palette.color(QPalette::Disabled, QPalette::WindowText)); - icon.addPixmap(QPixmap::fromImage(img), QIcon::Disabled); - } else { - painter.fillRect(rect, overrideColor); - icon.addPixmap(QPixmap::fromImage(img), QIcon::Normal); - } - -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - icon.setIsMask(true); -#endif - } - - if (!overrideColor.isValid()) { - m_iconCache.insert(name, icon); - } - - return icon; -} - -QIcon Resources::onOffIcon(const QString& name, bool recolor) -{ - QString cacheName = "onoff/" + name; - - QIcon icon = m_iconCache.value(cacheName); - - if (!icon.isNull()) { - return icon; - } - - const QSize size(48, 48); - QIcon on = Resources::icon(name + "-on", recolor); - icon.addPixmap(on.pixmap(size, QIcon::Mode::Normal), QIcon::Mode::Normal, QIcon::On); - icon.addPixmap(on.pixmap(size, QIcon::Mode::Selected), QIcon::Mode::Selected, QIcon::On); - icon.addPixmap(on.pixmap(size, QIcon::Mode::Disabled), QIcon::Mode::Disabled, QIcon::On); - - QIcon off = Resources::icon(name + "-off", recolor); - icon.addPixmap(off.pixmap(size, QIcon::Mode::Normal), QIcon::Mode::Normal, QIcon::Off); - icon.addPixmap(off.pixmap(size, QIcon::Mode::Selected), QIcon::Mode::Selected, QIcon::Off); - icon.addPixmap(off.pixmap(size, QIcon::Mode::Disabled), QIcon::Mode::Disabled, QIcon::Off); - - m_iconCache.insert(cacheName, icon); - - return icon; -} - Resources::Resources() { const QString appDirPath = QCoreApplication::applicationDirPath(); @@ -265,10 +129,6 @@ Resources* Resources::instance() { if (!m_instance) { m_instance = new Resources(); - - Q_INIT_RESOURCE(icons); - QIcon::setThemeSearchPaths(QStringList{":/icons"} << QIcon::themeSearchPaths()); - QIcon::setThemeName("application"); } return m_instance; |