Skip to content

Commit

Permalink
Merge remote-tracking branch 'filewave/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
oclero committed Oct 1, 2024
2 parents 03573b5 + 30bf5ff commit 85dbcee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
16 changes: 15 additions & 1 deletion lib/src/utils/PrimitiveUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QPaintDevice>
#include <QPainter>
#include <QPainterPath>
#include <QPixmapCache>
#include <QWindow>
#include <QApplication>

Expand Down Expand Up @@ -1365,7 +1366,20 @@ QPixmap getPixmap(
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return icon.pixmap(getWindow(widget), iconSize, iconMode, iconState);
#else
return icon.pixmap(iconSize, widget ? widget->devicePixelRatio() : qApp->devicePixelRatio(), iconMode, iconState);
const auto devicePixelRatio = widget ? widget->devicePixelRatio() : qApp->devicePixelRatio();
if (devicePixelRatio <= 1.0) {
return icon.pixmap(iconSize, devicePixelRatio, iconMode, iconState);
}

// Qt icon pixmap cache is broken when devicePixelRatio > 1.0.
auto pixmap = icon.pixmap(iconSize * devicePixelRatio, 1.0, iconMode, iconState); // The 1.0 pixmap gives a stable cache key.
auto cacheKey = QString("qlementine_icon_pixmap_%1_%2").arg(pixmap.cacheKey()).arg(devicePixelRatio);
if (QPixmapCache::find(cacheKey, &pixmap)) {
return pixmap;
}
pixmap.setDevicePixelRatio(devicePixelRatio); // This changes the internal cache key.
QPixmapCache::insert(cacheKey, pixmap);
return pixmap;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/IconWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void IconWidget::paintEvent(QPaintEvent*) {
return;

const auto& color = palette().color(isEnabled() ? QPalette::Normal : QPalette::Disabled, QPalette::Text);
const auto& colorizedPixmap = autoIconColor != AutoIconColor::None ? colorizePixmap(pixmap, color) : pixmap;
const auto& colorizedPixmap = autoIconColor != AutoIconColor::None ? getColorizedPixmap(pixmap, color) : pixmap;

QPainter p(this);
p.setRenderHint(QPainter::Antialiasing, true);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/LineEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ QPixmap LineEdit::getPixmap() const {
const auto pixmap = qlementine::getPixmap(_icon, iconSize, MouseState::Normal, CheckState::NotChecked, this);
const auto colorGroup = isEnabled() ? QPalette::ColorGroup::Normal : QPalette::ColorGroup::Disabled;
const auto& color = palette().color(colorGroup, QPalette::ColorRole::Text);
const auto colorizedPixmap = qlementine::colorizePixmap(pixmap, color);
const auto colorizedPixmap = qlementine::getColorizedPixmap(pixmap, color);
return colorizedPixmap;
} else {
const auto mouse = isEnabled() ? MouseState::Normal : MouseState::Disabled;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/widgets/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void Switch::paintEvent(QPaintEvent*) {
// Draw icon.
const auto extent = iconSize.height();
if (hasIcon && availableW >= extent) {
const auto pixmap = icon().pixmap(extent, QIcon::Mode::Normal, QIcon::State::On);
const auto coloredPixmap = colorizePixmap(pixmap, textColor);
const auto pixmap = qlementine::getPixmap(icon(), {extent, extent}, MouseState::Normal, CheckState::Checked, this);
const auto coloredPixmap = getColorizedPixmap(pixmap, textColor);
const auto iconX = availableX;
const auto iconY = contentRect.y() + (contentRect.height() - extent) / 2;
const auto iconRect = QRect{ iconX, iconY, extent, extent };
Expand Down

0 comments on commit 85dbcee

Please sign in to comment.