forked from qt-creator/qt-creator
Unify the dimensions for all mode/action bar icons
Having icons of all different kinds of sizes makes it difficult to get the painting right in all cases. It definitely fails when the szsytem is running in multi-monitor mode with different scaling factors. Unifying the dimensions makes it possible. This change should not cause any visual difference in a purely scaled or unscaled screen. Task-number: QTCREATORBUG-18869 Change-Id: I3a864c9a86036b4f4f3b350a489077b247ca85b7 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QCommonStyle>
|
||||
#include <QStyleOption>
|
||||
#include <QWindow>
|
||||
#include <qmath.h>
|
||||
|
||||
// Clamps float color values within (0, 255)
|
||||
@@ -397,7 +398,9 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
|
||||
QPainter *p, QIcon::Mode iconMode, 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());
|
||||
const int devicePixelRatio = p->device()->devicePixelRatio();
|
||||
QString pixmapName = QString::fromLatin1("icon %0 %1 %2 %3")
|
||||
.arg(icon.cacheKey()).arg(iconMode).arg(rect.height()).arg(devicePixelRatio);
|
||||
|
||||
if (!QPixmapCache::find(pixmapName, cache)) {
|
||||
// High-dpi support: The in parameters (rect, radius, offset) are in
|
||||
@@ -405,9 +408,8 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
|
||||
// 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.
|
||||
QWindow *window = QApplication::allWidgets().first()->windowHandle();
|
||||
QWindow *window = dynamic_cast<QWidget*>(p->device())->window()->windowHandle();
|
||||
QPixmap px = icon.pixmap(window, rect.size(), iconMode);
|
||||
int devicePixelRatio = qCeil(px.devicePixelRatio());
|
||||
int radius = dipRadius * devicePixelRatio;
|
||||
QPoint offset = dipOffset * devicePixelRatio;
|
||||
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
|
||||
@@ -415,7 +417,8 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
|
||||
|
||||
QPainter cachePainter(&cache);
|
||||
if (iconMode == QIcon::Disabled) {
|
||||
const bool hasDisabledState = icon.availableSizes(QIcon::Disabled).contains(px.size());
|
||||
const bool hasDisabledState =
|
||||
icon.availableSizes().count() == icon.availableSizes(QIcon::Disabled).count();
|
||||
if (!hasDisabledState)
|
||||
px = disabledSideBarIcon(icon.pixmap(window, rect.size()));
|
||||
} else if (creatorTheme()->flag(Theme::ToolBarIconShadow)) {
|
||||
|
||||
Reference in New Issue
Block a user