From aa16101b27e0e7d55e1690fceda1a284f871427b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 29 Nov 2017 15:08:04 +0100 Subject: Add support for distro logo --- src/mainwindow.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++------ src/mainwindow.h | 2 ++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 79a5190..75a1dcb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -91,8 +92,10 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge if (ls > screenRect.width() / 5) ls = screenRect.width() / 5; QRect logoRect(QPoint(0, screenRect.height() - ls), QSize(ls, ls)); QSize logoSize = createLogo(logoRect); + QRect distroRect(QPoint(screenRect.width() - ls, screenRect.height() - ls), QSize(ls, ls)); + QSize distroSize = createDistro(distroRect); if (showLoginForm()) { - QRect lwSize(QPoint(logoSize.width(), screenRect.height() * 3/4), QPoint(screenRect.width(), screenRect.height())); + QRect lwSize(QPoint(logoSize.width(), screenRect.height() * 3/4), QPoint(screenRect.width() - distroSize.width(), screenRect.height())); lwSize.adjust(10, 10, -10, -10); createLogWindow(lwSize); } @@ -132,6 +135,43 @@ QSize MainWindow::createLogo(const QRect &max) return size; } +QSize MainWindow::createDistro(const QRect &max) +{ + QImage img(QString("/etc/distro.png")); + if (img.isNull()) + return QSize(0, 0); + int w = img.width(), h = img.height(); + if (w+20 > max.width() || h+20 > max.height()) { + // This requires that the given rect is square + QRect cmp(max); + cmp.adjust(0, 0, -20, -20); + if (w > h) { + if (w != cmp.width()) { + h = h * cmp.width() / w; + w = cmp.width(); + } + } else { + if (h != cmp.height()) { + w = w * cmp.height() / h; + h = cmp.height(); + } + } + img = img.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation); + cmp.adjust(0, 0, 20, 20); + } + w += 20; + h += 20; + QPixmap pixmap(QPixmap::fromImage(img)); + QLabel *lbl = new QLabel(this); + lbl->setPixmap(pixmap); + QSize size(w, h); + QRect c(max); + c.adjust(max.width() - w, max.height() - h, 0, 0); + c.adjust(10, 10, -10, -10); + lbl->setGeometry(c); + return size; +} + void MainWindow::createLogWindow(const QRect& geom) { QString path = _settings.logMessageFile(); @@ -216,7 +256,6 @@ void MainWindow::setBackground() if (m_background.isNull()) { qWarning() << "Not able to read" << bgPath << "as image"; } - } if (m_background.isNull()) { @@ -231,7 +270,7 @@ void MainWindow::setBackground() m_background.setPixel(0, 1, 0xff888687); m_background.setPixel(1, 1, 0xfff9a72b); } - + QPalette palette; if (m_background.isNull()) { palette.setColor(QPalette::Background, Qt::black); @@ -240,9 +279,9 @@ void MainWindow::setBackground() m_background = m_background.scaled(m_ScreenRect.width(), m_ScreenRect.height(), arMode, Qt::SmoothTransformation); int xoff = (m_background.width() - m_ScreenRect.width()) / 2; int yoff = (m_background.height() - m_ScreenRect.height()) / 2; - if (xoff != 0 || yoff != 0) { - m_background = m_background.copy(xoff, yoff, m_background.width(), m_background.height()); - } + if (xoff != 0 || yoff != 0) { + m_background = m_background.copy(xoff, yoff, m_background.width(), m_background.height()); + } QBrush brush(m_background); palette.setBrush(this->backgroundRole(), brush); } diff --git a/src/mainwindow.h b/src/mainwindow.h index ccaa073..53c54e0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -34,6 +34,8 @@ public: QSize createLogo(const QRect &max); + QSize createDistro(const QRect &max); + void createLogWindow(const QRect& geom); bool showLoginForm(); -- cgit v1.2.3-55-g7522