diff options
author | Jonathan White <support@dmapps.us> | 2020-08-14 05:33:53 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2020-08-17 05:40:57 +0300 |
commit | a5208959c480a9c087f70827f54b9cd99bd130a0 (patch) | |
tree | a4a35d98119ffca8be6b3b83e9e980f7b23cc492 /src/core/Resources.cpp | |
parent | e96d0429cd0b0faf128a9a000395206929017d17 (diff) |
Fix excessive memory usage by icons
* Fixes #5240
* Limit size of icons being loaded to prevent excessive memory usage in some cases
* Fix loading database icons, previous method would just overwrite the same pixmap and not actually provide caching.
Diffstat (limited to 'src/core/Resources.cpp')
-rw-r--r-- | src/core/Resources.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/core/Resources.cpp b/src/core/Resources.cpp index 2f99c9349..ae8c0d46a 100644 --- a/src/core/Resources.cpp +++ b/src/core/Resources.cpp @@ -164,7 +164,9 @@ QIcon Resources::icon(const QString& name, bool recolor, const QColor& overrideC icon = QIcon::fromTheme(name); if (getMainWindow() && recolor) { - QImage img = icon.pixmap(128, 128).toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); + 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); @@ -172,20 +174,19 @@ QIcon Resources::icon(const QString& name, bool recolor, const QColor& overrideC if (!overrideColor.isValid()) { QPalette palette = getMainWindow()->palette(); - painter.fillRect(0, 0, img.width(), img.height(), palette.color(QPalette::Normal, QPalette::WindowText)); + painter.fillRect(rect, palette.color(QPalette::Normal, QPalette::WindowText)); icon.addPixmap(QPixmap::fromImage(img), QIcon::Normal); - painter.fillRect(0, 0, img.width(), img.height(), palette.color(QPalette::Active, QPalette::ButtonText)); + painter.fillRect(rect, palette.color(QPalette::Active, QPalette::ButtonText)); icon.addPixmap(QPixmap::fromImage(img), QIcon::Active); - painter.fillRect( - 0, 0, img.width(), img.height(), palette.color(QPalette::Active, QPalette::HighlightedText)); + painter.fillRect(rect, palette.color(QPalette::Active, QPalette::HighlightedText)); icon.addPixmap(QPixmap::fromImage(img), QIcon::Selected); - painter.fillRect(0, 0, img.width(), img.height(), palette.color(QPalette::Disabled, QPalette::WindowText)); + painter.fillRect(rect, palette.color(QPalette::Disabled, QPalette::WindowText)); icon.addPixmap(QPixmap::fromImage(img), QIcon::Disabled); } else { - painter.fillRect(0, 0, img.width(), img.height(), overrideColor); + painter.fillRect(rect, overrideColor); icon.addPixmap(QPixmap::fromImage(img), QIcon::Normal); } @@ -211,18 +212,16 @@ QIcon Resources::onOffIcon(const QString& name, bool recolor) return icon; } + const QSize size(48, 48); QIcon on = Resources::icon(name + "-on", recolor); - for (const auto& size : on.availableSizes()) { - 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); - } + 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); - for (const auto& size : off.availableSizes()) { - 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); - } + 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); |