summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-13 00:50:48 +0100
committerSimon Rettberg2017-11-13 00:50:48 +0100
commiteaaae9d7105836d4223c95bdcb41a15b58003c9f (patch)
treeab0e2cfe8273ebcad894b59dfd6519236c83031c
parentFix banner display, gradient parsing, add test mode (--test) (diff)
downloadslxgreeter-eaaae9d7105836d4223c95bdcb41a15b58003c9f.tar.gz
slxgreeter-eaaae9d7105836d4223c95bdcb41a15b58003c9f.tar.xz
slxgreeter-eaaae9d7105836d4223c95bdcb41a15b58003c9f.zip
Implement log/messages display + logo display
-rw-r--r--src/loginform.cpp1
-rw-r--r--src/main.cpp51
-rw-r--r--src/mainwindow.cpp107
-rw-r--r--src/mainwindow.h7
-rw-r--r--src/settings.h2
5 files changed, 119 insertions, 49 deletions
diff --git a/src/loginform.cpp b/src/loginform.cpp
index 3b86830..8c48f5f 100644
--- a/src/loginform.cpp
+++ b/src/loginform.cpp
@@ -7,7 +7,6 @@
* It is distributed under the LGPL 2.1 or later license.
* Please refer to the LICENSE file for a copy of the license.
*/
-#include <QDebug>
#include <QAbstractListModel>
#include <QModelIndex>
#include <QPixmap>
diff --git a/src/main.cpp b/src/main.cpp
index 769c570..ece6b87 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,7 +36,7 @@ static inline int size(const QRect& r)
int main(int argc, char *argv[])
{
//dup2(2, 1)
- // I have no idea why, but Qt's stock qDebug() output never makes it
+ // I have no idea why, but Qt's stock qWarning() output never makes it
// to /var/log/lightdm/x-0-greeter.log, so we use std::cerr instead..
qInstallMessageHandler(messageHandler);
@@ -55,28 +55,34 @@ int main(int argc, char *argv[])
entire = QImage(desktopSize, QImage::Format_RGB32);
QPainter painter(&entire);
+ const bool testMode = argc > 1 && QString(argv[1]) == QString("--test");
+
// Get a list of non-overlapping screens, as this might lead to a broken
// greeter with main windows covering other login forms
QMap<int, QRect> screens;
- for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
- QRect r = QApplication::desktop()->screenGeometry(i);
- QMutableMapIterator<int, QRect>it(screens);
- while (it.hasNext()) {
- it.next();
- if (!it.value().intersects(r))
- continue;
- // Overlap, bigger wins
- if (size(it.value()) >= size(r)) {
- // Existing is bigger
- goto skip_rect;
- }
- // New is bigger, remove existing and keep going
- it.remove();
- }
- // We reached here, so add new window
- screens.insert(i, r);
- skip_rect: ; // Do nothing
- }
+ if (testMode) {
+ screens.insert(0, QRect(0, 0, 1024, 768));
+ } else {
+ for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
+ QRect r = QApplication::desktop()->screenGeometry(i);
+ QMutableMapIterator<int, QRect>it(screens);
+ while (it.hasNext()) {
+ it.next();
+ if (!it.value().intersects(r))
+ continue;
+ // Overlap, bigger wins
+ if (size(it.value()) >= size(r)) {
+ // Existing is bigger
+ goto skip_rect;
+ }
+ // New is bigger, remove existing and keep going
+ it.remove();
+ }
+ // We reached here, so add new window
+ screens.insert(i, r);
+ skip_rect: ; // Do nothing
+ }
+ }
// Determine primary screen
int primary;
if (screens.contains(QApplication::desktop()->primaryScreen())) {
@@ -87,8 +93,7 @@ int main(int argc, char *argv[])
primary = screens.begin().key();
}
- // Now set up all the screens
- bool testMode = argc > 1 && QString(argv[1]) == QString("--test");
+ // Now set up all the screens
MainWindow *focusWindow = 0;
QMapIterator<int, QRect> it(screens);
while (it.hasNext()) {
@@ -105,7 +110,7 @@ int main(int argc, char *argv[])
}
if (!entire.isNull()) {
- qDebug() << "Setting x background";
+ qWarning() << "Setting x background";
AddPixmapToBackground(entire.constBits(), entire.width(), entire.height(), 24, entire.bytesPerLine(), entire.byteCount());
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f5bd274..404feb1 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -14,6 +14,8 @@
#include <QTextEdit>
#include <QStyleFactory>
#include <QSvgWidget>
+#include <QSvgRenderer>
+#include <QAbstractTextDocumentLayout>
#include "mainwindow.h"
#include "loginform.h"
@@ -23,8 +25,9 @@ static const Settings _settings;
MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, bool testMode, QWidget *parent) :
QWidget(parent),
- m_Screen(screen),
- m_Primary(primary)
+ m_ScreenRect(screenRect),
+ m_Primary(primary),
+ m_messages(nullptr)
{
setObjectName(QString("MainWindow_%1").arg(screen));
@@ -59,29 +62,12 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, bool t
QCursor::setPos(centerX, centerY);
}
- // Message log at the bottom
- m_messages = new QTextEdit(this);
- int logHeight = screenRect.height() * 3 / 4;
- if (logHeight > spaceY - 10) {
- logHeight = spaceY - 10;
- }
- m_messages->move(0, screenRect.height() * 2 / 3);
- m_messages->setFixedSize(screenRect.width(), screenRect.height() / 3);
- QPalette p = m_messages->palette();
- p.setColor(QPalette::Base, QColor(0,0,0,0)); // r,g,b,A
- QPalette::Light;
- m_messages->setPalette(p);
- m_messages->setFontPointSize(16);
- //m_messages->setText("TODO\nLogmessages\n\nWarnings\netc."); TODO
- m_messages->setReadOnly(true);
- m_messages->setStyleSheet("border:none;");
-
// Banner
if (!_settings.bannerImagePath().isEmpty()) {
qWarning() << "Have banner " << _settings.bannerImagePath();
QSvgWidget *banner = new QSvgWidget(_settings.bannerImagePath(), this);
qWarning() << banner->sizeHint();
- if (banner->sizeHint().height() > 0) {
+ if (banner->renderer()->isValid()) {
int bw, bh;
QSize sh = banner->sizeHint();
if (sh.height() < spaceY) {
@@ -97,12 +83,86 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, bool t
}
}
// TODO: UniLogo
+ int ls = (spaceY > 400 ? 400 : spaceY);
+ QRect logoRect(QPoint(0, screenRect.height() - ls), QSize(ls, ls));
+ QSize logoSize = createLogo(logoRect);
+ if (showLoginForm()) {
+ QRect lwSize(QPoint(logoSize.width(), screenRect.height() * 3/4), QPoint(screenRect.width(), screenRect.height()));
+ lwSize.adjust(10, 10, -10, -10);
+ createLogWindow(lwSize);
+ }
}
MainWindow::~MainWindow()
{
}
+QSize MainWindow::createLogo(const QRect &max)
+{
+ QString path = _settings.bottomLeftLogoPath();
+ if (path.isEmpty())
+ return QSize(0, 0);
+ QSvgWidget *img = new QSvgWidget(path, this);
+ if (!img->renderer()->isValid())
+ return QSize(0, 0);
+ QSize sh = img->sizeHint();
+ int w = sh.width(), h = sh.height();
+ // This requires that the given rect is square
+ if (w > h) {
+ if (w != max.width()) {
+ h = h * max.width() / w;
+ w = max.width();
+ }
+ } else {
+ if (h != max.height()) {
+ w = w * max.height() / h;
+ h = max.height();
+ }
+ }
+ QSize size(w, h);
+ QRect c(max);
+ c.setSize(size);
+ c.adjust(10, 10, -10, -10);
+ img->setGeometry(c);
+ return size;
+}
+
+void MainWindow::createLogWindow(const QRect& geom)
+{
+ QString path = _settings.logMessageFile();
+ if (path.isEmpty())
+ return;
+ QFile f(path);
+ if (f.size() == 0 || !f.open(QFile::ReadOnly))
+ return;
+ m_messages = new QTextEdit(this);
+ m_messages->setGeometry(geom);
+ int ps = geom.height() / 20;
+ if (ps > 20) ps = 20;
+ m_messages->setFontPointSize(ps);
+ QTextStream stream(&f);
+ const QColor black(Qt::black);
+ while (!stream.atEnd()) {
+ bool ok = false;
+ QString line(stream.readLine());
+ int i = line.indexOf(' ');
+ if (i > 0) {
+ QString scol(line.left(i));
+ uint col = scol.toUInt(&ok, 16);
+ if (ok) {
+ m_messages->setTextColor(QColor(QRgb(col)));
+ line = line.mid(i + 1);
+ }
+ }
+ if (!ok) {
+ m_messages->setTextColor(black);
+ }
+ m_messages->append(line);
+ }
+ m_messages->setReadOnly(true);
+ m_messages->setStyleSheet("border:none; background:rgba(255,255,255,.33); border-radius:5px");
+}
+
bool MainWindow::showLoginForm()
{
return m_Primary;
@@ -191,14 +251,13 @@ void MainWindow::setBackground()
}
QPalette palette;
- QRect rect = QApplication::desktop()->screenGeometry(m_Screen);
if (m_background.isNull()) {
palette.setColor(QPalette::Background, Qt::black);
}
else {
- m_background = m_background.scaled(rect.width(), rect.height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
- int xoff = (m_background.width() - rect.width()) / 2;
- int yoff = (m_background.height() - rect.height()) / 2;
+ m_background = m_background.scaled(m_ScreenRect.width(), m_ScreenRect.height(), Qt::KeepAspectRatioByExpanding, 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());
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index a6d8196..42d494e 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -12,6 +12,7 @@
#include <QImage>
#include <QRect>
+#include <QSize>
#include "loginform.h"
@@ -31,6 +32,10 @@ public:
void setFocus(Qt::FocusReason reason);
+ QSize createLogo(const QRect &max);
+
+ void createLogWindow(const QRect& geom);
+
bool showLoginForm();
QImage& getBackground() { return m_background; }
@@ -39,7 +44,7 @@ public:
private:
int getOffset(QString offset, int maxVal, int defaultVal);
void setBackground();
- int m_Screen;
+ QRect m_ScreenRect;
bool m_Primary;
LoginForm* m_LoginForm;
QImage m_background;
diff --git a/src/settings.h b/src/settings.h
index 544adcd..81b1381 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -15,7 +15,9 @@ public:
QString offsetY() const { return value("loginform-offset-y").toString(); }
QString miniIconPath() const { return value("loginform-mini-icon").toString(); }
QString bannerImagePath() const { return value("greeter-banner-image").toString(); }
+ QString bottomLeftLogoPath() const { return value("greeter-bottom-left-logo-path").toString(); }
QStringList gradientColors() const { return value("greeter-background-gradient").toString().split(QRegExp("\\s"), QString::SkipEmptyParts); }
+ QString logMessageFile() const { return value("greeter-message-file").toString(); }
};