diff options
author | Simon Rettberg | 2017-11-14 21:47:12 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-14 21:47:12 +0100 |
commit | bdecd0561bc6ffcb4927296cd62b945822a2da67 (patch) | |
tree | 23347d1ce4d7f823565199e8787d8b90560b6b56 | |
parent | Super cool and awesome loginform style (diff) | |
download | slxgreeter-bdecd0561bc6ffcb4927296cd62b945822a2da67.tar.gz slxgreeter-bdecd0561bc6ffcb4927296cd62b945822a2da67.tar.xz slxgreeter-bdecd0561bc6ffcb4927296cd62b945822a2da67.zip |
Minor fixes, improvements
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/global.cpp | 31 | ||||
-rw-r--r-- | src/global.h | 3 | ||||
-rw-r--r-- | src/main.cpp | 14 | ||||
-rw-r--r-- | src/mainwindow.cpp | 32 |
5 files changed, 52 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e33c334..bdd2d15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) # Since some distro (debian) doesn't have a qt5 version of liblightdm-qt5, let's just ship it OPTION(USE_INCLUDED_LDMQT "Use included liblightdm-qt" OFF) -PROJECT(qt-lightdm-greeter) +PROJECT(qt-lightdm-greeter CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_BUILD_TYPE Debug) diff --git a/src/global.cpp b/src/global.cpp index 7039bc1..1a3cf80 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -1,10 +1,12 @@ #include "global.h" +#include "settings.h" #include <QTimer> #include <QModelIndex> #include <QString> #include <QEventLoop> #include <QDebug> #include <QCoreApplication> +#include <QStringList> bool Global::m_testMode = false; @@ -49,3 +51,32 @@ bool Global::startSession() QString s = m_Sessions->data(i, QLightDM::SessionsModel::KeyRole).toString(); return m_Greeter->startSessionSync(s); } + +QImage Global::getConfigGradient() +{ + QImage img; + const QStringList cols = Settings().gradientColors(); + qWarning() << "Got gradient color list: " << cols; + if (cols.length() == 4 || cols.length() == 2) { + bool ok = true; + uint a, b, c, d; + if (ok) a = cols.at(0).toUInt(&ok, 16) | 0xff000000; + if (ok) b = cols.at(1).toUInt(&ok, 16) | 0xff000000; + if (cols.length() == 4) { + if (ok) c = cols.at(2).toUInt(&ok, 16) | 0xff000000; + if (ok) d = cols.at(3).toUInt(&ok, 16) | 0xff000000; + } else if (ok) { + c = b; + } + if (ok) { + img = QImage(cols.length() / 2, 2, QImage::Format_RGB32); + img.setPixel(0, 0, a); + img.setPixel(0, 1, c); + if (cols.length() == 4) { + img.setPixel(1, 0, b); + img.setPixel(1, 1, d); + } + } + } + return img; +} diff --git a/src/global.h b/src/global.h index bdfda89..91b878f 100644 --- a/src/global.h +++ b/src/global.h @@ -4,6 +4,7 @@ #include <QLightDM/Power> #include <QLightDM/Greeter> #include <QLightDM/SessionsModel> +#include <QImage> class Global { public: @@ -45,6 +46,8 @@ public: static bool startSession(); + static QImage getConfigGradient(); + private: static bool m_testMode; static QLightDM::Greeter *m_Greeter; diff --git a/src/main.cpp b/src/main.cpp index 8eee16f..7ba8758 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,8 @@ #include "x11util.h" #include "global.h" +static void createSimpleBackground(); + static void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg) { std::cerr << type << ": " << msg.toUtf8().constData() << '\n'; @@ -56,8 +58,8 @@ int main(int argc, char *argv[]) if (ret == 0) { if (Global::autoLoginGuest()) { qWarning() << "Guest login ok"; - return a.exec(); - // TODO: Background? + createSimpleBackground(); + return a.exec(); } else { qWarning() << "Guest login failed"; // TODO: Set error message, display somewhere @@ -142,3 +144,11 @@ int main(int argc, char *argv[]) return a.exec(); } +static void createSimpleBackground() +{ + QImage img = Global::getConfigGradient(); + if (img.isNull()) + return; + img = img.scaled(QApplication::desktop()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + AddPixmapToBackground(img.constBits(), img.width(), img.height(), 24, img.bytesPerLine(), img.byteCount()); +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2eb84c9..79a5190 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -20,6 +20,7 @@ #include "mainwindow.h" #include "loginform.h" #include "settings.h" +#include "global.h" static const Settings _settings; @@ -78,8 +79,8 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge bw = sh.width(); bh = sh.height(); } else { - int bh = spaceY - 20; - int bw = sh.width() * bh / sh.height(); + bh = spaceY - 20; + bw = sh.width() * bh / sh.height(); banner->setFixedSize(bw, bh); } banner->move((screenRect.width() - bw) / 2, (spaceY - bh) / 2); @@ -219,31 +220,8 @@ void MainWindow::setBackground() } if (m_background.isNull()) { + m_background = Global::getConfigGradient(); arMode = Qt::IgnoreAspectRatio; - QStringList cols = _settings.gradientColors(); - qWarning() << "Got list: " << cols; - if (cols.length() == 4 || cols.length() == 2) { - bool ok = true; - uint a, b, c, d; - if (ok) a = cols.at(0).toUInt(&ok, 16) | 0xff000000; - if (ok) b = cols.at(1).toUInt(&ok, 16) | 0xff000000; - if (cols.length() == 4) { - if (ok) c = cols.at(2).toUInt(&ok, 16) | 0xff000000; - if (ok) d = cols.at(3).toUInt(&ok, 16) | 0xff000000; - } else { - c = b; - } - qWarning() << a << b << c << d; - if (ok) { - m_background = QImage(cols.length() / 2, 2, QImage::Format_RGB32); - m_background.setPixel(0, 0, a); - m_background.setPixel(0, 1, c); - if (cols.length() == 4) { - m_background.setPixel(1, 0, b); - m_background.setPixel(1, 1, d); - } - } - } } if (m_background.isNull()) { // Hard-coded default: Gradient @@ -259,7 +237,7 @@ void MainWindow::setBackground() palette.setColor(QPalette::Background, Qt::black); } else { - m_background = m_background.scaled(m_ScreenRect.width(), m_ScreenRect.height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + 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) { |