From 24c1d3c47b94f57236c7a961842d351122f1db1b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 18 Mar 2019 17:25:21 +0100 Subject: Make loginform-icon more flexible Scale up to 128x128; honor SVGs preferring a size smaller than 128x128 instead of scaling them up. --- src/loginform.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/loginform.cpp') diff --git a/src/loginform.cpp b/src/loginform.cpp index f6c438d..b193cb1 100644 --- a/src/loginform.cpp +++ b/src/loginform.cpp @@ -10,9 +10,11 @@ #include #include #include +#include #include #include #include +#include #include @@ -49,14 +51,25 @@ void LoginForm::setFocus(Qt::FocusReason reason) void LoginForm::initialize() { - // fallback to built-in bwlp logo - QPixmap icon(":/resources/bwlp.svg"); // This project came from Razor-qt - if (!Settings::miniIconFile().isNull() && !Settings::miniIconFile().isEmpty()) { - QPixmap configuredIcon(Settings::miniIconFile()); - if (!configuredIcon.isNull()) - icon = configuredIcon; + QString path = Settings::miniIconFile(); + QPixmap pixmap; + if (!path.isEmpty()) { + QSize size = QSvgRenderer(path).defaultSize(); + if (!size.isValid()) { + size = ui->iconLabel->maximumSize(); + } else { + QSize o(ui->iconLabel->maximumSize()); + size = QSize(qMin(size.width(), o.width()), qMin(size.height(), o.height())); + } + pixmap = QIcon(path).pixmap(size); } - ui->iconLabel->setPixmap(icon.scaled(ui->iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + if (pixmap.isNull() || pixmap.width() < 10) { + // fallback to built-in bwlp logo + pixmap = QIcon(QLatin1String(":/resources/bwlp.svg")).pixmap(ui->iconLabel->size()); + } + + ui->iconLabel->setPixmap(pixmap); + ui->iconLabel->setFixedSize(pixmap.size()); ui->leaveComboBox->setView(new QListView()); // This is required to get the stylesheet to apply -- cgit v1.2.3-55-g7522