Apply scaling in renderSvgImage() similar to QIcon::pixmap() does
This commit is contained in:
parent
e10eca68f9
commit
5b2147a874
|
@ -104,7 +104,7 @@ void SyncthingFileItemActionStaticData::showAboutDialog()
|
||||||
"icons from <a href=\"https://fontawesome.com\">Font "
|
"icons from <a href=\"https://fontawesome.com\">Font "
|
||||||
"Awesome</a> (see <a href=\"https://fontawesome.com/license\">their license</a>)"),
|
"Awesome</a> (see <a href=\"https://fontawesome.com/license\">their license</a>)"),
|
||||||
QStringLiteral(APP_VERSION), CppUtilities::applicationInfo.dependencyVersions, QStringLiteral(APP_URL), QStringLiteral(APP_DESCRIPTION),
|
QStringLiteral(APP_VERSION), CppUtilities::applicationInfo.dependencyVersions, QStringLiteral(APP_URL), QStringLiteral(APP_DESCRIPTION),
|
||||||
renderSvgImage(makeSyncthingIcon()).toImage());
|
renderSvgImage(makeSyncthingIcon(), QSize(128, 128)).toImage());
|
||||||
aboutDialog->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME));
|
aboutDialog->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME));
|
||||||
aboutDialog->setWindowIcon(QIcon::fromTheme(QStringLiteral("syncthingtray")));
|
aboutDialog->setWindowIcon(QIcon::fromTheme(QStringLiteral("syncthingtray")));
|
||||||
aboutDialog->setAttribute(Qt::WA_DeleteOnClose);
|
aboutDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "./syncthingicons.h"
|
#include "./syncthingicons.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QGuiApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
@ -113,12 +113,14 @@ QByteArray makeSyncthingIcon(const StatusIconColorSet &colors, StatusEmblem stat
|
||||||
|
|
||||||
/// \cond
|
/// \cond
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
template <typename SourceType> QPixmap renderSvgImage(const SourceType &source, const QSize &size, int margin)
|
template <typename SourceType> QPixmap renderSvgImage(const SourceType &source, const QSize &givenSize, int margin)
|
||||||
{
|
{
|
||||||
|
const qreal scaleFactor = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? qGuiApp->devicePixelRatio() : 1.0;
|
||||||
QSvgRenderer renderer(source);
|
QSvgRenderer renderer(source);
|
||||||
|
QSize scaledSize(givenSize.width() * scaleFactor, givenSize.height() * scaleFactor);
|
||||||
QSize renderSize(renderer.defaultSize());
|
QSize renderSize(renderer.defaultSize());
|
||||||
renderSize.scale(size.width() - margin, size.height() - margin, Qt::KeepAspectRatio);
|
renderSize.scale(scaledSize.width() - margin, scaledSize.height() - margin, Qt::KeepAspectRatio);
|
||||||
QRect renderBounds(QPoint(), size);
|
QRect renderBounds(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);
|
||||||
|
@ -129,10 +131,11 @@ template <typename SourceType> QPixmap renderSvgImage(const SourceType &source,
|
||||||
renderBounds.setY(diff);
|
renderBounds.setY(diff);
|
||||||
renderBounds.setHeight(renderSize.height());
|
renderBounds.setHeight(renderSize.height());
|
||||||
}
|
}
|
||||||
QPixmap pm(size);
|
QPixmap pm(scaledSize);
|
||||||
pm.fill(QColor(Qt::transparent));
|
pm.fill(QColor(Qt::transparent));
|
||||||
QPainter painter(&pm);
|
QPainter painter(&pm);
|
||||||
renderer.render(&painter, renderBounds);
|
renderer.render(&painter, renderBounds);
|
||||||
|
pm.setDevicePixelRatio(scaleFactor);
|
||||||
return pm;
|
return pm;
|
||||||
}
|
}
|
||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
|
|
|
@ -56,8 +56,8 @@ inline StatusIconColorSet::StatusIconColorSet(const QString &backgroundStart, co
|
||||||
LIB_SYNCTHING_MODEL_EXPORT QByteArray makeSyncthingIcon(
|
LIB_SYNCTHING_MODEL_EXPORT QByteArray makeSyncthingIcon(
|
||||||
const StatusIconColorSet &colors = StatusIconColorSet{ QStringLiteral("#26B6DB"), QStringLiteral("#0882C8"), QStringLiteral("#FFFFFF") },
|
const StatusIconColorSet &colors = StatusIconColorSet{ QStringLiteral("#26B6DB"), QStringLiteral("#0882C8"), QStringLiteral("#FFFFFF") },
|
||||||
StatusEmblem statusEmblem = StatusEmblem::None);
|
StatusEmblem statusEmblem = StatusEmblem::None);
|
||||||
LIB_SYNCTHING_MODEL_EXPORT QPixmap renderSvgImage(const QString &path, const QSize &size = QSize(128, 128), int margin = 0);
|
LIB_SYNCTHING_MODEL_EXPORT QPixmap renderSvgImage(const QString &path, const QSize &size = QSize(32, 32), int margin = 0);
|
||||||
LIB_SYNCTHING_MODEL_EXPORT QPixmap renderSvgImage(const QByteArray &contents, const QSize &size = QSize(128, 128), int margin = 0);
|
LIB_SYNCTHING_MODEL_EXPORT QPixmap renderSvgImage(const QByteArray &contents, const QSize &size = QSize(32, 32), int margin = 0);
|
||||||
LIB_SYNCTHING_MODEL_EXPORT QByteArray loadFontAwesomeIcon(const QString &iconName, const QColor &color, bool solid = true);
|
LIB_SYNCTHING_MODEL_EXPORT QByteArray loadFontAwesomeIcon(const QString &iconName, const QColor &color, bool solid = true);
|
||||||
|
|
||||||
struct LIB_SYNCTHING_MODEL_EXPORT StatusIconSettings {
|
struct LIB_SYNCTHING_MODEL_EXPORT StatusIconSettings {
|
||||||
|
|
|
@ -326,7 +326,7 @@ void SyncthingApplet::showAboutDialog()
|
||||||
"icons from <a href=\"https://fontawesome.com\">Font "
|
"icons from <a href=\"https://fontawesome.com\">Font "
|
||||||
"Awesome</a> (see <a href=\"https://fontawesome.com/license\">their license</a>)</p>"),
|
"Awesome</a> (see <a href=\"https://fontawesome.com/license\">their license</a>)</p>"),
|
||||||
QStringLiteral(APP_VERSION), CppUtilities::applicationInfo.dependencyVersions, QStringLiteral(APP_URL), QStringLiteral(APP_DESCRIPTION),
|
QStringLiteral(APP_VERSION), CppUtilities::applicationInfo.dependencyVersions, QStringLiteral(APP_URL), QStringLiteral(APP_DESCRIPTION),
|
||||||
renderSvgImage(makeSyncthingIcon()).toImage());
|
renderSvgImage(makeSyncthingIcon(), QSize(128, 128)).toImage());
|
||||||
m_aboutDlg->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME));
|
m_aboutDlg->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME));
|
||||||
m_aboutDlg->setWindowIcon(QIcon::fromTheme(QStringLiteral("syncthingtray")));
|
m_aboutDlg->setWindowIcon(QIcon::fromTheme(QStringLiteral("syncthingtray")));
|
||||||
m_aboutDlg->setAttribute(Qt::WA_DeleteOnClose);
|
m_aboutDlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
|
@ -240,7 +240,7 @@ void TrayWidget::showAboutDialog()
|
||||||
"<br>Fallback icons from KDE/Breeze project<br>Syncthing icons from <a href=\"https://syncthing.net\">Syncthing project</a><br>Using "
|
"<br>Fallback icons from KDE/Breeze project<br>Syncthing icons from <a href=\"https://syncthing.net\">Syncthing project</a><br>Using "
|
||||||
"icons from <a href=\"https://fontawesome.com\">Font "
|
"icons from <a href=\"https://fontawesome.com\">Font "
|
||||||
"Awesome</a> (see <a href=\"https://fontawesome.com/license\">their license</a>)</p>"),
|
"Awesome</a> (see <a href=\"https://fontawesome.com/license\">their license</a>)</p>"),
|
||||||
QString(), {}, QStringLiteral(APP_URL), QString(), QImage(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg")));
|
QString(), {}, QStringLiteral(APP_URL), QString(), renderSvgImage(makeSyncthingIcon(), QSize(128, 128)).toImage());
|
||||||
s_aboutDlg->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME));
|
s_aboutDlg->setWindowTitle(tr("About") + QStringLiteral(" - " APP_NAME));
|
||||||
s_aboutDlg->setWindowIcon(QIcon(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg")));
|
s_aboutDlg->setWindowIcon(QIcon(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg")));
|
||||||
}
|
}
|
||||||
|
|
|
@ -564,6 +564,7 @@ QWidget *IconsOptionPage::setupWidget()
|
||||||
&colorMapping.setting,
|
&colorMapping.setting,
|
||||||
colorMapping.defaultEmblem,
|
colorMapping.defaultEmblem,
|
||||||
};
|
};
|
||||||
|
widgetsForColor.previewLabel->setMaximumSize(QSize(32, 32));
|
||||||
|
|
||||||
// add label for color name
|
// add label for color name
|
||||||
gridLayout->addWidget(new QLabel(colorMapping.colorName, statusIconsGroupBox), index, 0, Qt::AlignRight | Qt::AlignVCenter);
|
gridLayout->addWidget(new QLabel(colorMapping.colorName, statusIconsGroupBox), index, 0, Qt::AlignRight | Qt::AlignVCenter);
|
||||||
|
@ -577,8 +578,7 @@ QWidget *IconsOptionPage::setupWidget()
|
||||||
widgetsForColor.colorButtons[1]->color(),
|
widgetsForColor.colorButtons[1]->color(),
|
||||||
widgetsForColor.colorButtons[2]->color(),
|
widgetsForColor.colorButtons[2]->color(),
|
||||||
},
|
},
|
||||||
widgetsForColor.statusEmblem),
|
widgetsForColor.statusEmblem), widgetsForColor.previewLabel->maximumSize()));
|
||||||
QSize(32, 32)));
|
|
||||||
};
|
};
|
||||||
for (const auto &colorButton : widgetsForColor.colorButtons) {
|
for (const auto &colorButton : widgetsForColor.colorButtons) {
|
||||||
QObject::connect(colorButton, &ColorButton::colorChanged, updatePreview);
|
QObject::connect(colorButton, &ColorButton::colorChanged, updatePreview);
|
||||||
|
|
Loading…
Reference in New Issue