diff --git a/launcher/resources/multimc/index.theme b/launcher/resources/multimc/index.theme index 070e23f10..5a0170403 100644 --- a/launcher/resources/multimc/index.theme +++ b/launcher/resources/multimc/index.theme @@ -1,6 +1,7 @@ [Icon Theme] Name=multimc Comment=Default Icons +FollowsColorScheme=true Inherits=default Directories=8x8,16x16,22x22,24x24,32x32,32x32/instances,48x48,50x50/instances,64x64,128x128/instances,256x256,scalable,scalable/instances diff --git a/launcher/resources/pe_blue/pe_blue.qrc b/launcher/resources/pe_blue/pe_blue.qrc index c8ff75a46..d6fa6ee71 100644 --- a/launcher/resources/pe_blue/pe_blue.qrc +++ b/launcher/resources/pe_blue/pe_blue.qrc @@ -2,6 +2,32 @@ index.theme + + scalable/about.svg + scalable/accounts.svg + scalable/appearance.svg + scalable/bug.svg + scalable/checkupdate.svg + scalable/copy.svg + scalable/custom-commands.svg + scalable/delete.svg + scalable/export.svg + scalable/externaltools.svg + scalable/help.svg + scalable/instance-settings.svg + scalable/launch.svg + scalable/log.svg + scalable/new.svg + scalable/news.svg + scalable/notes.svg + scalable/proxy.svg + scalable/refresh.svg + scalable/rename.svg + scalable/screenshots.svg + scalable/settings.svg + scalable/shortcut.svg + scalable/viewfolder.svg + scalable/about.svg scalable/accounts.svg scalable/bug.svg diff --git a/launcher/resources/pe_colored/pe_colored.qrc b/launcher/resources/pe_colored/pe_colored.qrc index f4f89272f..ee714c779 100644 --- a/launcher/resources/pe_colored/pe_colored.qrc +++ b/launcher/resources/pe_colored/pe_colored.qrc @@ -2,6 +2,32 @@ index.theme + + scalable/about.svg + scalable/accounts.svg + scalable/appearance.svg + scalable/bug.svg + scalable/checkupdate.svg + scalable/copy.svg + scalable/custom-commands.svg + scalable/delete.svg + scalable/export.svg + scalable/externaltools.svg + scalable/help.svg + scalable/instance-settings.svg + scalable/launch.svg + scalable/log.svg + scalable/new.svg + scalable/news.svg + scalable/notes.svg + scalable/proxy.svg + scalable/refresh.svg + scalable/rename.svg + scalable/screenshots.svg + scalable/settings.svg + scalable/shortcut.svg + scalable/viewfolder.svg + scalable/about.svg scalable/accounts.svg scalable/bug.svg diff --git a/launcher/resources/pe_dark/pe_dark.qrc b/launcher/resources/pe_dark/pe_dark.qrc index 302ac4adb..58ba19f3c 100644 --- a/launcher/resources/pe_dark/pe_dark.qrc +++ b/launcher/resources/pe_dark/pe_dark.qrc @@ -2,6 +2,32 @@ index.theme + + scalable/about.svg + scalable/accounts.svg + scalable/appearance.svg + scalable/bug.svg + scalable/checkupdate.svg + scalable/copy.svg + scalable/custom-commands.svg + scalable/delete.svg + scalable/export.svg + scalable/externaltools.svg + scalable/help.svg + scalable/instance-settings.svg + scalable/launch.svg + scalable/log.svg + scalable/new.svg + scalable/news.svg + scalable/notes.svg + scalable/proxy.svg + scalable/refresh.svg + scalable/rename.svg + scalable/screenshots.svg + scalable/settings.svg + scalable/shortcut.svg + scalable/viewfolder.svg + scalable/about.svg scalable/accounts.svg scalable/bug.svg diff --git a/launcher/resources/pe_light/pe_light.qrc b/launcher/resources/pe_light/pe_light.qrc index 4424be0c7..e6c543d3e 100644 --- a/launcher/resources/pe_light/pe_light.qrc +++ b/launcher/resources/pe_light/pe_light.qrc @@ -2,6 +2,32 @@ index.theme + + scalable/about.svg + scalable/accounts.svg + scalable/appearance.svg + scalable/bug.svg + scalable/checkupdate.svg + scalable/copy.svg + scalable/custom-commands.svg + scalable/delete.svg + scalable/export.svg + scalable/externaltools.svg + scalable/help.svg + scalable/instance-settings.svg + scalable/launch.svg + scalable/log.svg + scalable/new.svg + scalable/news.svg + scalable/notes.svg + scalable/proxy.svg + scalable/refresh.svg + scalable/rename.svg + scalable/screenshots.svg + scalable/settings.svg + scalable/shortcut.svg + scalable/viewfolder.svg + scalable/about.svg scalable/accounts.svg scalable/bug.svg diff --git a/launcher/ui/pages/global/AppearancePage.cpp b/launcher/ui/pages/global/AppearancePage.cpp index e7dfd206a..6048f282e 100644 --- a/launcher/ui/pages/global/AppearancePage.cpp +++ b/launcher/ui/pages/global/AppearancePage.cpp @@ -89,8 +89,10 @@ AppearancePage::AppearancePage(QWidget* parent) QDir().mkpath(ThemedIcons::userDirectory()); DesktopServices::openDirectory(ThemedIcons::userDirectory(), true); }); - connect(ui->iconsReloadButton, &QPushButton::clicked, this, - &AppearancePage::loadIconThemes); + connect(ui->iconsReloadButton, &QPushButton::clicked, this, [this] { + ThemedIcons::reload(); + loadIconThemes(); + }); loadIconThemes(); updateIconPreview(); diff --git a/launcher/ui/themes/AppearanceManager.cpp b/launcher/ui/themes/AppearanceManager.cpp index 40d176c13..21d976d9b 100644 --- a/launcher/ui/themes/AppearanceManager.cpp +++ b/launcher/ui/themes/AppearanceManager.cpp @@ -27,6 +27,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -53,6 +57,10 @@ void AppearanceManager::stopSettingNewWindowColorsOnMac() {} void AppearanceManager::initialize(KConfigSettingsObject* legacySettings) { + // The style of the system, which a colour scheme may take the place of + // (see paletteChanged()). + m_systemStyle = QApplication::style()->objectName(); + // The widget style the user chose, if KDE's platform theme is not doing // that already. KStyleManager::initStyle(); @@ -95,7 +103,10 @@ void AppearanceManager::setIconTheme(const QString& id) const QString applied = ThemedIcons::setTheme(id); m_settings->setIconTheme(applied); m_settings->save(); - emit iconsChanged(); + // Left to the next turn of the event loop: the icon loader has just been + // made again, and what asks it for icons should not do so in the middle + // of the change (in a slot of the combo box that chose the theme). + QTimer::singleShot(0, this, [this] { refreshLooks(); }); } bool AppearanceManager::eventFilter(QObject* watched, QEvent* event) @@ -108,8 +119,40 @@ bool AppearanceManager::eventFilter(QObject* watched, QEvent* event) void AppearanceManager::paletteChanged() { + if (m_applyingStyle) { + return; + } + + // A native style (macOS, Windows) paints its own colours, so a colour + // scheme of the user's shows half of the way on it. Fusion follows the + // palette; the system's style comes back with the system's scheme. + const bool custom = + !KColorSchemeManager::instance()->activeSchemeId().isEmpty(); + const QString style = ColorSchemes::styleFor( + qApp->style()->objectName(), m_systemStyle, custom, m_styleOverridden); + if (!style.isEmpty()) { + m_applyingStyle = true; + const QPalette keep = qApp->palette(); + QApplication::setStyle(style); + QApplication::setPalette(keep); + m_applyingStyle = false; + m_styleOverridden = custom; + } + const QPalette palette = qApp->palette(); ThemedIcons::setPalette(palette); setTitlebarColorOfAllWindowsOnMac(palette.window().color()); + refreshLooks(); +} + +void AppearanceManager::refreshLooks() +{ + // Icons are drawn when they are needed, from the palette and the icon + // theme as they are then; what has to happen is that what is on the screen + // is drawn again, and that nothing is reused from before. + QPixmapCache::clear(); + for (QWidget* widget : QApplication::allWidgets()) { + widget->update(); + } emit iconsChanged(); } diff --git a/launcher/ui/themes/AppearanceManager.h b/launcher/ui/themes/AppearanceManager.h index e1b771909..575114d17 100644 --- a/launcher/ui/themes/AppearanceManager.h +++ b/launcher/ui/themes/AppearanceManager.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -62,7 +63,11 @@ class AppearanceManager : public QObject private: void initialize(KConfigSettingsObject* legacySettings); GlobalSettings* m_settings; + QString m_systemStyle; + bool m_styleOverridden = false; + bool m_applyingStyle = false; void paletteChanged(); + void refreshLooks(); void setTitlebarColorOfAllWindowsOnMac(QColor color); void setTitlebarColorOnMac(WId windowId, QColor color); void stopSettingNewWindowColorsOnMac(); diff --git a/launcher/ui/themes/ColorSchemes.cpp b/launcher/ui/themes/ColorSchemes.cpp index b19f30b1f..23b032013 100644 --- a/launcher/ui/themes/ColorSchemes.cpp +++ b/launcher/ui/themes/ColorSchemes.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,27 @@ namespace ColorSchemes return written; } + bool isNativeStyle(const QString& style) + { + static const QStringList native{ + QStringLiteral("macos"), QStringLiteral("macintosh"), + QStringLiteral("windowsvista"), QStringLiteral("windows11")}; + return native.contains(style, Qt::CaseInsensitive); + } + + QString styleFor(const QString& current, const QString& systemStyle, + bool customScheme, bool overridden) + { + if (customScheme && isNativeStyle(current)) { + return QStringLiteral("Fusion"); + } + if (!customScheme && overridden && !systemStyle.isEmpty() && + current.compare(systemStyle, Qt::CaseInsensitive) != 0) { + return systemStyle; + } + return QString(); + } + bool importScheme(const QString& file, const QString& directory, QString* error) { diff --git a/launcher/ui/themes/ColorSchemes.h b/launcher/ui/themes/ColorSchemes.h index 531f3a403..75e19b340 100644 --- a/launcher/ui/themes/ColorSchemes.h +++ b/launcher/ui/themes/ColorSchemes.h @@ -57,6 +57,26 @@ namespace ColorSchemes */ QString idForLegacyTheme(const QString& theme); + /*! + * Whether \p style is the platform's own widget style. It paints with the + * colours of the system and ignores the palette of the application in + * places, so a colour scheme that is not the system's shows half of the + * way on it: dark panels with light buttons. + */ + bool isNativeStyle(const QString& style); + + /*! + * The widget style that makes a colour scheme show completely, or an + * empty string if \p current is fine as it is. + * + * With a scheme of its own (\p customScheme) a native style is replaced + * by Fusion, which follows the palette. With the system's scheme again, + * the style that was replaced (\p overridden) is put back, which is + * \p systemStyle. + */ + QString styleFor(const QString& current, const QString& systemStyle, + bool customScheme, bool overridden); + /*! * Adds a scheme of the user's to \p directory: copies \p file there, if it * is a KDE colour scheme (a ".colors" file with colours in it). One of the diff --git a/launcher/ui/themes/ColorSchemes_test.cpp b/launcher/ui/themes/ColorSchemes_test.cpp index 1c8612ea1..038ea666a 100644 --- a/launcher/ui/themes/ColorSchemes_test.cpp +++ b/launcher/ui/themes/ColorSchemes_test.cpp @@ -136,6 +136,29 @@ class ColorSchemesTest : public QObject } } + void test_ANativeStyleIsReplacedByFusionForASchemeOfItsOwn() + { + // a scheme of the user's on a native style: Fusion + QCOMPARE(ColorSchemes::styleFor("macos", "macos", true, false), + QString("Fusion")); + QCOMPARE(ColorSchemes::styleFor("windows11", "windows11", true, false), + QString("Fusion")); + // a style that follows the palette is left alone + QVERIFY(ColorSchemes::styleFor("Fusion", "macos", true, false) + .isEmpty()); + // the system's scheme: nothing to do, unless the style was replaced + QVERIFY(ColorSchemes::styleFor("macos", "macos", false, false) + .isEmpty()); + QCOMPARE(ColorSchemes::styleFor("Fusion", "macos", false, true), + QString("macos")); + // and it is not put back twice, or over a style that was chosen + QVERIFY(ColorSchemes::styleFor("macos", "macos", false, true) + .isEmpty()); + QVERIFY(ColorSchemes::styleFor("Fusion", "", false, true).isEmpty()); + QVERIFY(ColorSchemes::isNativeStyle("macOS")); + QVERIFY(!ColorSchemes::isNativeStyle("Fusion")); + } + void test_ASchemeOfTheUsersIsImported() { QTemporaryDir source; diff --git a/launcher/ui/themes/ThemedIcons.cpp b/launcher/ui/themes/ThemedIcons.cpp index 015a4d48e..272a86877 100644 --- a/launcher/ui/themes/ThemedIcons.cpp +++ b/launcher/ui/themes/ThemedIcons.cpp @@ -110,12 +110,15 @@ namespace ThemedIcons QStringLiteral("/icons"); } - QList themes() + void reload() { // KIconTheme remembers what it found, which is not up to date for a // theme that was put in the folder a moment ago. KIconTheme::reconfigure(); + } + QList themes() + { QList found; for (const QString& id : KIconTheme::list()) { // hicolor is the freedesktop fallback, not a look to choose @@ -138,18 +141,35 @@ namespace ThemedIcons QString setTheme(const QString& id) { - QString target = QStringLiteral("breeze"); - for (const Theme& theme : themes()) { - if (theme.id == id) { - target = id; - break; + auto isThere = [&id] { + for (const Theme& theme : themes()) { + if (theme.id == id) { + return true; + } } + return false; + }; + // A theme put in the folder a moment ago is not known yet. + if (!isThere()) { + reload(); } + const QString target = + isThere() ? id : QStringLiteral("breeze"); if (target != id) { qDebug() << "There is no icon theme" << id << "; using Breeze"; } - if (QIcon::themeName() != target) { + // What the theme in use does not have comes from the fallback: the + // bundled theme (it has the icons of instances, which no other theme + // has). The bundled theme itself cannot be its own fallback: it has + // none of Breeze's icons, and they came out empty. + const QString fallback = target == QLatin1String("multimc") + ? QStringLiteral("breeze") + : QStringLiteral("multimc"); + const bool changed = QIcon::themeName() != target || + QIcon::fallbackThemeName() != fallback; + if (changed) { + QIcon::setFallbackThemeName(fallback); QIcon::setThemeName(target); KIconTheme::reconfigure(); KIconLoader::global()->newIconLoader(); @@ -176,7 +196,11 @@ namespace ThemedIcons QIcon icon(const QString& name) { const QString alias = aliases().value(name); - if (!alias.isEmpty() && KIconLoader::global()->hasIcon(alias)) { + // No hasIcon() check: while the icon loader is being made again it + // can say no for an icon that is there a moment later, and the + // fallback has no icon for what only Breeze has (accounts, notes...), + // which is an empty icon for good. The engine looks when it draws. + if (!alias.isEmpty()) { return breeze(alias); } // The bundled theme, or what Breeze has under that name. diff --git a/launcher/ui/themes/ThemedIcons.h b/launcher/ui/themes/ThemedIcons.h index f55122d5a..264df6934 100644 --- a/launcher/ui/themes/ThemedIcons.h +++ b/launcher/ui/themes/ThemedIcons.h @@ -69,11 +69,18 @@ namespace ThemedIcons /*! * The icon themes there are, Breeze first: the ones KIconTheme finds, which - * are the user's, the system's and Breeze. Looked up each time, so a - * theme that was added a moment ago is there. + * are the user's, the system's and Breeze. KIconTheme remembers what it + * found: call reload() first for a theme that was added a moment ago. */ QList themes(); + /*! + * Makes KIconTheme look for icon themes again. Not done by themes(), + * since that resets the state of the icon loader, which is not wanted + * every time a list is filled. + */ + void reload(); + /*! * Makes \p id the icon theme, or Breeze if there is no such theme. * @@ -89,7 +96,8 @@ namespace ThemedIcons /*! * The icon for \p name: Breeze's, drawn by KIconEngine, if it is one of - * the aliases, otherwise the icon of that name in the icon theme (the + * the aliases (always: the engine finds the icon when it draws, not when + * it is made), otherwise the icon of that name in the icon theme (the * bundled one, or Breeze's through QIcon). Null when there is none. */ QIcon icon(const QString& name); diff --git a/launcher/ui/themes/ThemedIcons_test.cpp b/launcher/ui/themes/ThemedIcons_test.cpp index 2e8f3424a..6518efaec 100644 --- a/launcher/ui/themes/ThemedIcons_test.cpp +++ b/launcher/ui/themes/ThemedIcons_test.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include "ui/themes/ThemedIcons.h" @@ -41,6 +42,10 @@ static void initResources() { Q_INIT_RESOURCE(multimc); + Q_INIT_RESOURCE(pe_colored); + Q_INIT_RESOURCE(pe_blue); + Q_INIT_RESOURCE(pe_dark); + Q_INIT_RESOURCE(pe_light); } namespace @@ -136,10 +141,10 @@ QList readUiIconRequests(const QString& uiPath, QString* error) } /// The average colour of the opaque pixels of \p icon. - QColor glyphColor(const QIcon& icon) + QColor glyphColor(const QIcon& icon, int size = 32) { const QImage image = - icon.pixmap(32).toImage().convertToFormat(QImage::Format_ARGB32); + icon.pixmap(size).toImage().convertToFormat(QImage::Format_ARGB32); qint64 r = 0, g = 0, b = 0, n = 0; for (int y = 0; y < image.height(); ++y) { for (int x = 0; x < image.width(); ++x) { @@ -197,6 +202,7 @@ class ThemedIconsTest : public QObject index.close(); // found without the application being restarted + ThemedIcons::reload(); bool listed = false; for (const auto& theme : ThemedIcons::themes()) { if (theme.id == "mytheme") { @@ -215,9 +221,151 @@ class ThemedIconsTest : public QObject QCOMPARE(ThemedIcons::setTheme("breeze"), QString("breeze")); } + void test_AnAliasIsAnIconWhileTheLoaderIsMadeAgain() + { + // the icons that only Breeze has (the bundled theme has none of + // them) must not come out empty, whatever the icon loader was doing + // when they were asked for + ThemedIcons::setTheme("breeze"); + KIconLoader::global()->newIconLoader(); + for (const QString& name : {"accounts", "externaltools", "notes"}) { + const QIcon icon = ThemedIcons::icon(name); + QVERIFY2(!icon.isNull(), qPrintable(name)); + QVERIFY2(!icon.pixmap(32).isNull(), qPrintable(name)); + QVERIFY2(glyphColor(icon).isValid(), qPrintable(name)); + } + } + + void test_EveryThemeShowsTheIconsOfTheApplication() + { + // the bundled theme has none of Breeze's icons; choosing it (or going + // back to Breeze afterwards) must not leave icons empty + const QStringList names = {"accounts", "copy", "notes", + "settings", "launch", "externaltools"}; + for (const char* theme : {"multimc", "breeze", "multimc", "breeze"}) { + QCOMPARE(ThemedIcons::setTheme(theme), QString(theme)); + for (const QString& name : names) { + QVERIFY2(glyphColor(ThemedIcons::icon(name)).isValid(), + qPrintable(QString(theme) + ": " + name)); + } + // the icons of instances are only in the bundled theme + for (const char* name : {"grass", "creeper"}) { + QVERIFY2(!QIcon::fromTheme(QString::fromLatin1(name)).isNull(), + qPrintable(QString(theme) + ": " + name)); + } + } + } + + void test_InheritedIconsRemainVisibleAcrossThemeAndPaletteChanges() + { + ThemedIcons::setTheme("breeze"); + const QStringList names = {"copy", "launch", "new", "viewfolder", + "accounts", "notes"}; + QList retained; + for (const QString& name : names) { + retained.append(ThemedIcons::icon(name)); + } + + for (bool dark : {true, false, true}) { + QPalette palette = QGuiApplication::palette(); + const QColor foreground = dark ? QColor(239, 240, 241) + : QColor(35, 38, 41); + const QColor background = dark ? QColor(35, 38, 41) : Qt::white; + palette.setColor(QPalette::Window, background); + for (auto role : {QPalette::WindowText, QPalette::Text, + QPalette::ButtonText}) { + palette.setColor(role, foreground); + } + ThemedIcons::setPalette(palette); + + for (const char* theme : {"breeze", "multimc", "breeze"}) { + QCOMPARE(ThemedIcons::setTheme(theme), QString(theme)); + for (int i = 0; i < names.size(); ++i) { + // Both existing widgets and newly opened pages must remain + // readable. A non-null, opaque pixmap alone is not enough. + for (const QIcon& icon : + {retained[i], ThemedIcons::icon(names[i])}) { + // Breeze uses monochrome artwork at toolbar size; + // larger sizes can have intentionally coloured artwork. + const QColor actual = glyphColor(icon, 22); + const QString context = QString("%1: %2, dark=%3, color=%4") + .arg(theme, names[i]).arg(dark).arg(actual.name()); + QVERIFY2(actual.isValid(), qPrintable(context)); + QVERIFY2(qAbs(actual.lightness() - background.lightness()) > 100, + qPrintable(context)); + } + } + } + } + ThemedIcons::setPalette(QGuiApplication::palette()); + } + + void test_BundledPeThemesUseTheirOwnArtwork_data() + { + QTest::addColumn("theme"); + for (const char* theme : {"pe_colored", "pe_blue", "pe_dark", "pe_light"}) { + QTest::newRow(theme) << QString::fromLatin1(theme); + } + } + + void test_BundledPeThemesUseTheirOwnArtwork() + { + QFETCH(QString, theme); + QCOMPARE(ThemedIcons::setTheme("breeze"), QString("breeze")); + QHash retained; + QHash breeze; + for (auto it = ThemedIcons::aliases().cbegin(); + it != ThemedIcons::aliases().cend(); ++it) { + retained.insert(it.key(), ThemedIcons::icon(it.key())); + breeze.insert(it.key(), retained[it.key()].pixmap(32).toImage()); + } + + for (int cycle = 0; cycle < 2; ++cycle) { + QCOMPARE(ThemedIcons::setTheme(theme), theme); + for (auto it = retained.cbegin(); it != retained.cend(); ++it) { + const QString path = QString(":/icons/%1/scalable/%2.svg") + .arg(theme, it.key()); + QVERIFY2(QFile::exists(path), qPrintable(path)); + // Render the original artwork directly, bypassing theme-name + // lookup. A nonempty fallback is not the selected theme's icon. + const QIcon expected(new KIconEngine(path, KIconLoader::global())); + QVERIFY2(glyphColor(expected, 22).isValid(), qPrintable(path)); + for (int size : {22, 32}) { + for (qreal scale : {1.0, 2.0}) { + const QImage image = expected.pixmap(QSize(size, size), scale).toImage(); + QVERIFY2(!image.isNull(), qPrintable(path)); + for (const QIcon& icon : {it.value(), ThemedIcons::icon(it.key())}) { + QVERIFY2(!icon.isNull(), qPrintable(theme + ": " + it.key())); + QVERIFY2(icon.pixmap(QSize(size, size), scale).toImage() == image, + qPrintable(theme + ": " + it.key())); + } + } + } + } + // Both retained icons and newly requested icons must switch back. + QCOMPARE(ThemedIcons::setTheme("breeze"), QString("breeze")); + for (auto it = retained.cbegin(); it != retained.cend(); ++it) { + QCOMPARE(it.value().pixmap(32).toImage(), breeze.value(it.key())); + QCOMPARE(ThemedIcons::icon(it.key()).pixmap(32).toImage(), breeze.value(it.key())); + } + } + } + + void test_ThemesDoesNotResetTheIconLoader() + { + // filling a list must not change what the loader has been told + QPalette palette; + palette.setColor(QPalette::WindowText, QColor(10, 200, 30)); + ThemedIcons::setPalette(palette); + const QColor before = glyphColor(ThemedIcons::icon("copy")); + ThemedIcons::themes(); + ThemedIcons::themes(); + QCOMPARE(glyphColor(ThemedIcons::icon("copy")), before); + } + void test_AThemeThatIsNotThereIsBreeze() { - QCOMPARE(ThemedIcons::setTheme("pe_dark"), QString("breeze")); + QCOMPARE(ThemedIcons::setTheme("no-such-meshmc-theme"), QString("breeze")); QCOMPARE(ThemedIcons::theme(), QString("breeze")); } diff --git a/launcher/ui/widgets/PageContainer.cpp b/launcher/ui/widgets/PageContainer.cpp index 3dcc86647..6ce115ed0 100644 --- a/launcher/ui/widgets/PageContainer.cpp +++ b/launcher/ui/widgets/PageContainer.cpp @@ -34,6 +34,7 @@ #include "settings/SettingsObject.h" +#include "ui/themes/AppearanceManager.h" #include "ui/widgets/IconLabel.h" #include "DesktopServices.h" @@ -90,6 +91,15 @@ PageContainer::PageContainer(BasePageProvider* pageProvider, QString defaultId, [this](const QModelIndex& current, const QModelIndex&) { currentChanged(current); }); + // The icons of the page list and of the header are asked of the pages + // once; a new icon theme or palette means asking again. + connect(APPLICATION->appearance(), &AppearanceManager::iconsChanged, this, + [this] { + m_model->refreshIcons(); + if (m_currentPage) { + m_iconHeader->setIcon(m_currentPage->icon()); + } + }); m_pageStack->setStackingMode(QStackedLayout::StackOne); m_pageList->setFocus(); selectPage(defaultId); diff --git a/launcher/ui/widgets/PageContainer_p.h b/launcher/ui/widgets/PageContainer_p.h index d61668767..c5917471c 100644 --- a/launcher/ui/widgets/PageContainer_p.h +++ b/launcher/ui/widgets/PageContainer_p.h @@ -73,6 +73,16 @@ class PageModel : public QAbstractListModel return QVariant(); } + /// The icons of the pages are asked for again (the icon theme or the + /// palette changed). + void refreshIcons() + { + if (!m_pages.isEmpty()) { + emit dataChanged(index(0), index(m_pages.size() - 1), + {Qt::DecorationRole}); + } + } + void setPages(const QList& pages) { beginResetModel();