Use more uniform coding style in syncthingicons.cpp

This commit is contained in:
Martchus 2021-03-24 20:02:07 +01:00
parent 18352a6ce1
commit 832fec0ffe
1 changed files with 10 additions and 10 deletions

View File

@ -117,16 +117,16 @@ QByteArray makeSyncthingIcon(const StatusIconColorSet &colors, StatusEmblem stat
namespace Detail { namespace Detail {
template <typename SourceType> QPixmap renderSvgImage(const SourceType &source, const QSize &givenSize, int margin) template <typename SourceType> QPixmap renderSvgImage(const SourceType &source, const QSize &givenSize, int margin)
{ {
const qreal scaleFactor = const auto scaleFactor =
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
!QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1.0 : !QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1.0 :
#endif #endif
qGuiApp->devicePixelRatio(); qGuiApp->devicePixelRatio();
QSvgRenderer renderer(source); const auto scaledSize = QSize(givenSize * scaleFactor);
QSize scaledSize(static_cast<int>(givenSize.width() * scaleFactor), static_cast<int>(givenSize.height() * scaleFactor)); auto renderer = QSvgRenderer(source);
QSize renderSize(renderer.defaultSize()); auto renderSize = QSize(renderer.defaultSize());
renderSize.scale(scaledSize.width() - margin, scaledSize.height() - margin, Qt::KeepAspectRatio); renderSize.scale(scaledSize.width() - margin, scaledSize.height() - margin, Qt::KeepAspectRatio);
QRect renderBounds(QPoint(), scaledSize); auto renderBounds = QRect(QPoint(), scaledSize);
if (renderSize.width() < renderBounds.width()) { if (renderSize.width() < renderBounds.width()) {
const auto diff = (renderBounds.width() - renderSize.width()) / 2; const auto diff = (renderBounds.width() - renderSize.width()) / 2;
renderBounds.setX(diff); renderBounds.setX(diff);
@ -137,9 +137,9 @@ template <typename SourceType> QPixmap renderSvgImage(const SourceType &source,
renderBounds.setY(diff); renderBounds.setY(diff);
renderBounds.setHeight(renderSize.height()); renderBounds.setHeight(renderSize.height());
} }
QPixmap pm(scaledSize); auto pm = QPixmap(scaledSize);
pm.fill(QColor(Qt::transparent)); pm.fill(QColor(Qt::transparent));
QPainter painter(&pm); auto painter = QPainter(&pm);
renderer.render(&painter, renderBounds); renderer.render(&painter, renderBounds);
pm.setDevicePixelRatio(scaleFactor); pm.setDevicePixelRatio(scaleFactor);
return pm; return pm;
@ -170,9 +170,9 @@ QPixmap renderSvgImage(const QByteArray &contents, const QSize &size, int margin
*/ */
QByteArray loadFontAwesomeIcon(const QString &iconName, const QColor &color, bool solid) QByteArray loadFontAwesomeIcon(const QString &iconName, const QColor &color, bool solid)
{ {
QByteArray result; auto result = QByteArray();
QFile icon(QString((solid ? QStringLiteral(":/icons/hicolor/scalable/fa/") : QStringLiteral(":/icons/hicolor/scalable/fa-non-solid/")) % iconName auto icon = QFile(QString((solid ? QStringLiteral(":/icons/hicolor/scalable/fa/") : QStringLiteral(":/icons/hicolor/scalable/fa-non-solid/"))
% QStringLiteral(".svg"))); % iconName % QStringLiteral(".svg")));
if (!icon.open(QFile::ReadOnly)) { if (!icon.open(QFile::ReadOnly)) {
return result; return result;
} }