Solutions: Enable theming and dpr for spinner images

Change-Id: I2105b9c1032940d26f3f3bf2083f88e1133e8757
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Alessandro Portale
2023-07-15 12:58:31 +02:00
parent a9663d65ad
commit b5808cdd56
9 changed files with 43 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 765 B

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 315 B

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

View File

@@ -3,7 +3,9 @@
#include "spinner.h"
#include <QApplication>
#include <QEvent>
#include <QIcon>
#include <QPainter>
#include <QTimer>
#include <QWidget>
@@ -81,7 +83,7 @@ private:
int m_rotationStep = 45;
int m_rotation = 0;
QTimer m_timer;
QPixmap m_pixmap;
mutable QPixmap m_pixmap;
UpdateCallback m_callback;
};
@@ -98,6 +100,18 @@ static QString imageFileNameForSpinnerSize(SpinnerSize size)
return {};
}
static QPixmap themedPixmapForSpinnerSize(SpinnerSize size, qreal dpr)
{
QImage mask(qt_findAtNxFile(imageFileNameForSpinnerSize(size), dpr));
mask.invertPixels();
QImage themedImage(mask.size(), QImage::Format_ARGB32);
themedImage.fill(qApp->palette().text().color());
themedImage.setAlphaChannel(mask);
QPixmap themedPixmap = QPixmap::fromImage(themedImage);
themedPixmap.setDevicePixelRatio(mask.devicePixelRatio());
return themedPixmap;
}
SpinnerPainter::SpinnerPainter(SpinnerSize size)
{
m_timer.setSingleShot(false);
@@ -114,11 +128,14 @@ void SpinnerPainter::setSize(SpinnerSize size)
m_size = size;
m_rotationStep = size == SpinnerSize::Small ? 45 : 30;
m_timer.setInterval(size == SpinnerSize::Small ? 100 : 80);
m_pixmap = QPixmap(imageFileNameForSpinnerSize(size));
m_pixmap = themedPixmapForSpinnerSize(size, qApp->devicePixelRatio());
}
void SpinnerPainter::paint(QPainter &painter, const QRect &rect) const
{
const qreal dpr = painter.device()->devicePixelRatioF();
if (!qFuzzyCompare(m_pixmap.devicePixelRatio(), dpr))
m_pixmap = themedPixmapForSpinnerSize(m_size, dpr);
painter.save();
painter.setRenderHint(QPainter::SmoothPixmapTransform);
QPoint translate(rect.x() + rect.width() / 2, rect.y() + rect.height() / 2);

View File

@@ -1,7 +1,10 @@
<RCC>
<qresource prefix="/" >
<file>icons/spinner_large.png</file>
<file>icons/spinner_large@2x.png</file>
<file>icons/spinner_medium.png</file>
<file>icons/spinner_medium@2x.png</file>
<file>icons/spinner_small.png</file>
<file>icons/spinner_small@2x.png</file>
</qresource>
</RCC>

View File

@@ -1200,6 +1200,27 @@
y="0"
x="0" />
</g>
<use
x="0"
y="0"
xlink:href="#src/libs/utils/images/progressindicator_big"
id="src/libs/solutions/spinner/icons/spinner_large"
transform="translate(97,-29)"
style="display:inline" />
<use
x="0"
y="0"
xlink:href="#src/libs/utils/images/progressindicator_medium"
id="src/libs/solutions/spinner/icons/spinner_medium"
transform="translate(98,-61)"
style="display:inline" />
<use
x="0"
y="0"
xlink:href="#src/libs/utils/images/progressindicator_small"
id="src/libs/solutions/spinner/icons/spinner_small"
transform="translate(243,-177)"
style="display:inline" />
<g
id="src/plugins/coreplugin/find/images/wrapindicator">
<rect

Before

Width:  |  Height:  |  Size: 364 KiB

After

Width:  |  Height:  |  Size: 365 KiB