diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt --- a/kstyle/CMakeLists.txt +++ b/kstyle/CMakeLists.txt @@ -4,6 +4,7 @@ I18n Config GuiAddons + IconThemes ConfigWidgets WindowSystem) @@ -101,7 +102,7 @@ if( BREEZE_HAVE_QTQUICK ) target_link_libraries(breeze Qt5::Quick) endif() -target_link_libraries(breeze KF5::ConfigCore KF5::ConfigWidgets KF5::GuiAddons KF5::WindowSystem) +target_link_libraries(breeze KF5::ConfigCore KF5::ConfigWidgets KF5::GuiAddons KF5::IconThemes KF5::WindowSystem) target_link_libraries(breeze breezecommon5) if(KF5FrameworkIntegration_FOUND) diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -29,6 +29,7 @@ #include #include +#include #include namespace Breeze @@ -281,6 +282,9 @@ //* return a QRectF with the appropriate size for a rectangle with a pen stroke QRectF strokedRect( const QRect &rect, const int penWidth = PenWidth::Frame ) const; + + QPixmap coloredIcon(const QIcon &icon, const QPalette& palette, const QSize &size, + QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off); protected: diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -23,6 +23,7 @@ #include "breezestyleconfigdata.h" #include +#include #include #include @@ -1595,4 +1596,19 @@ return pixmap.devicePixelRatio(); } + QPixmap Helper::coloredIcon(const QIcon& icon, const QPalette& palette, const QSize &size, QIcon::Mode mode, QIcon::State state) + { + const QPalette activePalette = KIconLoader::global()->customPalette(); + const bool changePalette = activePalette != palette; + if (changePalette) { + KIconLoader::global()->setCustomPalette(palette); + } + const QPixmap pixmap = icon.pixmap(size, mode, state); + if (changePalette && activePalette == QPalette()) { + KIconLoader::global()->resetPalette(); + } else { + KIconLoader::global()->setCustomPalette(palette); + } + return pixmap; + } } diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -1276,9 +1276,9 @@ const auto pixmapSize( button->icon().actualSize( button->iconSize() ) ); const QRect pixmapRect( QPoint( offset.x(), button->description().isEmpty() ? (button->height() - pixmapSize.height())/2:offset.y() ), pixmapSize ); - const QPixmap pixmap( button->icon().pixmap(pixmapSize, + const QPixmap pixmap(_helper->coloredIcon(button->icon(), button->palette(), pixmapSize, enabled ? QIcon::Normal : QIcon::Disabled, - button->isChecked() ? QIcon::On : QIcon::Off) ); + button->isChecked() ? QIcon::On : QIcon::Off)); drawItemPixmap( &painter, pixmapRect, Qt::AlignCenter, pixmap ); offset.rx() += pixmapSize.width() + Metrics::Button_ItemSpacing; @@ -3888,7 +3888,7 @@ const QSize iconSize( iconWidth, iconWidth ); // get pixmap - const QPixmap pixmap( icon.pixmap( iconSize, iconMode, iconState ) ); + const QPixmap pixmap(_helper->coloredIcon(icon, option->palette, iconSize, iconMode, iconState)); // render drawItemPixmap( painter, option->rect, Qt::AlignCenter, pixmap ); @@ -4203,7 +4203,7 @@ else if( mouseOver && flat ) iconMode = QIcon::Active; else iconMode = QIcon::Normal; - const auto pixmap = buttonOption->icon.pixmap( iconSize, iconMode, iconState ); + const auto pixmap = _helper->coloredIcon(buttonOption->icon, buttonOption->palette, iconSize, iconMode, iconState); drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); } @@ -4329,7 +4329,7 @@ else if( mouseOver && flat ) iconMode = QIcon::Active; else iconMode = QIcon::Normal; - const QPixmap pixmap = toolButtonOption->icon.pixmap( iconSize, iconMode, iconState ); + const QPixmap pixmap = _helper->coloredIcon(toolButtonOption->icon, toolButtonOption->palette, iconSize, iconMode, iconState); drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); } @@ -4378,7 +4378,7 @@ if( !buttonOption->icon.isNull() ) { const QIcon::Mode mode( enabled ? QIcon::Normal : QIcon::Disabled ); - const QPixmap pixmap( buttonOption->icon.pixmap( buttonOption->iconSize, mode ) ); + const QPixmap pixmap(_helper->coloredIcon(buttonOption->icon, buttonOption->palette, buttonOption->iconSize, mode)); drawItemPixmap( painter, rect, textFlags, pixmap ); // adjust rect (copied from QCommonStyle) @@ -4472,7 +4472,8 @@ #endif } - const auto pixmap = cb->currentIcon.pixmap(window, cb->iconSize, mode); + auto pixmap = _helper->coloredIcon(cb->currentIcon,cb->palette, cb->iconSize * window->devicePixelRatio(), mode); + pixmap.setDevicePixelRatio(window->devicePixelRatio()); auto iconRect(editRect); iconRect.setWidth(cb->iconSize.width() + 4); iconRect = alignedRect(cb->direction, @@ -4557,7 +4558,7 @@ } - const auto pixmap = menuItemOption->icon.pixmap( iconSize, iconMode, iconState ); + const auto pixmap = _helper->coloredIcon(menuItemOption->icon, menuItemOption->palette, iconRect.size(), iconMode, iconState); drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); // render outline @@ -4736,7 +4737,7 @@ // icon state const QIcon::State iconState( sunken ? QIcon::On:QIcon::Off ); - const QPixmap icon = menuItemOption->icon.pixmap( iconRect.size(), mode, iconState ); + const QPixmap icon = _helper->coloredIcon(menuItemOption->icon, menuItemOption->palette, iconRect.size(), mode, iconState); painter->drawPixmap( iconRect, icon ); } @@ -5716,7 +5717,7 @@ iconRect = visualRect( option, iconRect ); const QIcon::Mode mode( enabled ? QIcon::Normal : QIcon::Disabled ); - const QPixmap pixmap( toolBoxOption->icon.pixmap( iconSize, mode ) ); + const QPixmap pixmap(_helper->coloredIcon(toolBoxOption->icon, toolBoxOption->palette, iconRect.size(), mode)); drawItemPixmap( painter, iconRect, textFlags, pixmap ); } @@ -6598,7 +6599,7 @@ } // get pixmap and render - const QPixmap pixmap = icon.pixmap( iconSize, iconMode, iconState ); + const QPixmap pixmap = _helper->coloredIcon(icon, option->palette, iconSize, iconMode, iconState); painter->drawPixmap( iconRect, pixmap ); }