From 0612305ea8e10d28fa39c1a26a9f5757e2fc105d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 3 Apr 2017 12:39:17 +0300 Subject: [PATCH] Fixed issue #650. "Seam allowance tool" icons are not showing correctly. --HG-- branch : develop --- src/libs/vwidgets/fancytabbar/stylehelper.cpp | 22 ++++++++++++++----- src/libs/vwidgets/fancytabbar/stylehelper.h | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libs/vwidgets/fancytabbar/stylehelper.cpp b/src/libs/vwidgets/fancytabbar/stylehelper.cpp index f6620320a..98c43c3ca 100644 --- a/src/libs/vwidgets/fancytabbar/stylehelper.cpp +++ b/src/libs/vwidgets/fancytabbar/stylehelper.cpp @@ -38,6 +38,8 @@ #include #include +#include "../vmisc/vmath.h" + //--------------------------------------------------------------------------------------------------------------------- qreal StyleHelper::sidebarFontSize() { @@ -122,14 +124,22 @@ void StyleHelper::setBaseColor(const QColor &newcolor) //--------------------------------------------------------------------------------------------------------------------- // Draws a cached pixmap with shadow void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, - int radius, const QColor &color, const QPoint &offset) + int dipRadius, const QColor &color, const QPoint &dipOffset) { QPixmap cache; QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); if (!QPixmapCache::find(pixmapName, cache)) { + // High-dpi support: The in parameters (rect, radius, offset) are in + // device-independent pixels. The call to QIcon::pixmap() below might + // return a high-dpi pixmap, which will in that case have a devicePixelRatio + // different than 1. The shadow drawing caluculations are done in device + // pixels. QPixmap px = icon.pixmap(rect.size()); + int devicePixelRatio = qCeil(px.devicePixelRatio()); + int radius = dipRadius * devicePixelRatio; + QPoint offset = dipOffset * devicePixelRatio; cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); cache.fill(Qt::transparent); @@ -157,7 +167,7 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPain QPainter tmpPainter(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); - tmpPainter.drawPixmap(QPoint(radius, radius), px); + tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px); tmpPainter.end(); // blur the alpha channel @@ -184,11 +194,13 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPain cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp); // Draw the actual pixmap... - cachePainter.drawPixmap(QPoint(radius, radius) + offset, px); + cachePainter.drawPixmap(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px); + cache.setDevicePixelRatio(devicePixelRatio); QPixmapCache::insert(pixmapName, cache); } QRect targetRect = cache.rect(); - targetRect.moveCenter(rect.center()); - p->drawPixmap(targetRect.topLeft() - offset, cache); + targetRect.setSize(targetRect.size() / cache.devicePixelRatio()); + targetRect.moveCenter(rect.center() - dipOffset); + p->drawPixmap(targetRect, cache); } diff --git a/src/libs/vwidgets/fancytabbar/stylehelper.h b/src/libs/vwidgets/fancytabbar/stylehelper.h index 12198eb47..ab22893cd 100644 --- a/src/libs/vwidgets/fancytabbar/stylehelper.h +++ b/src/libs/vwidgets/fancytabbar/stylehelper.h @@ -57,8 +57,8 @@ public: // Sets the base color and makes sure all top level widgets are updated static void setBaseColor(const QColor &color); static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, - int radius = 3, const QColor &color = QColor(0, 0, 0, 130), - const QPoint &offset = QPoint(1, -2)); + int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130), + const QPoint &dipOffset = QPoint(1, -2)); private: static QColor m_baseColor;