diff options
author | Simon Rettberg | 2019-03-18 17:25:21 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-03-18 17:25:21 +0100 |
commit | 24c1d3c47b94f57236c7a961842d351122f1db1b (patch) | |
tree | 1e46097d70ede539dd82340f5b6fda9ab66d042e /src/loginform.cpp | |
parent | Add second logo key for better migration from old slx-admin (diff) | |
download | slxgreeter-24c1d3c47b94f57236c7a961842d351122f1db1b.tar.gz slxgreeter-24c1d3c47b94f57236c7a961842d351122f1db1b.tar.xz slxgreeter-24c1d3c47b94f57236c7a961842d351122f1db1b.zip |
Make loginform-icon more flexible
Scale up to 128x128; honor SVGs preferring a size smaller than 128x128
instead of scaling them up.
Diffstat (limited to 'src/loginform.cpp')
-rw-r--r-- | src/loginform.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
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 <QAbstractListModel> #include <QModelIndex> #include <QPixmap> +#include <QIcon> #include <QMessageBox> #include <QMenu> #include <QListView> +#include <QSvgRenderer> #include <iostream> @@ -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 |