summaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp97
1 files changed, 82 insertions, 15 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 314493c..c578c43 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -11,11 +11,16 @@
#include <QPalette>
#include <QString>
#include <QDebug>
+#include <QTextEdit>
+#include <QStyleFactory>
+#include <QSvgWidget>
#include "mainwindow.h"
#include "loginform.h"
#include "settings.h"
+static const Settings _settings;
+
MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidget *parent) :
QWidget(parent),
m_Screen(screen),
@@ -28,16 +33,19 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge
setBackground();
// display login dialog only in the main screen
+
+ int spaceY = screenRect.height() / 2;
if (showLoginForm()) {
m_LoginForm = new LoginForm(this);
+ spaceY -= m_LoginForm->height() / 2;
int maxX = screenRect.width() - m_LoginForm->width();
int maxY = screenRect.height() - m_LoginForm->height();
- int defaultX = 10*maxX/100;
+ int defaultX = 50*maxX/100;
int defaultY = 50*maxY/100;
- int offsetX = getOffset(Settings().offsetX(), maxX, defaultX);
- int offsetY = getOffset(Settings().offsetY(), maxY, defaultY);
+ int offsetX = getOffset(_settings.offsetX(), maxX, defaultX);
+ int offsetY = getOffset(_settings.offsetY(), maxY, defaultY);
m_LoginForm->move(offsetX, offsetY);
m_LoginForm->show();
@@ -50,6 +58,42 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge
int centerY = screenRect.height()/2 + screenRect.y();
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->setText("TODO\nLogmessages\n\nWarnings\netc.");
+ m_messages->setReadOnly(true);
+ this->setStyle(QStyleFactory::create("#m_messages, QTextEdit { border: none; }")); // TODO: Get rid of black 1px border
+
+ // Banner
+ if (_settings.bannerImagePath().isEmpty()) {
+ QSvgWidget *banner = new QSvgWidget(_settings.bannerImagePath(), this);
+ if (banner->sizeHint().height() > 0) {
+ int bw, bh;
+ QSize sh = banner->sizeHint();
+ if (sh.height() < spaceY) {
+ banner->setFixedSize(sh);
+ bw = sh.width();
+ bh = sh.height();
+ } else {
+ int bh = spaceY - 20;
+ int bw = sh.width() * bh / sh.height();
+ banner->setFixedSize(bw, bh);
+ }
+ banner->move((screenRect.width() - bw) / 2, (spaceY - bh) / 2);
+ }
+ }
+ // TODO: UniLogo
}
MainWindow::~MainWindow()
@@ -97,23 +141,46 @@ int MainWindow::getOffset(QString settingsOffset, int maxVal, int defaultVal)
void MainWindow::setBackground()
{
- QSettings greeterSettings(CONFIG_FILE, QSettings::IniFormat);
-
- if (greeterSettings.contains(BACKGROUND_IMAGE_KEY)) {
- QString pathTom_background = greeterSettings.value(BACKGROUND_IMAGE_KEY).toString();
-
- m_background = QImage(pathTom_background);
+ Qt::AspectRatioMode arMode = Qt::KeepAspectRatioByExpanding;
+ QString bgPath = _settings.backgrundImagePath();
+ if (bgPath.length() != 0) {
+ m_background = QImage(bgPath);
if (m_background.isNull()) {
- qWarning() << "Not able to read" << pathTom_background << "as image";
+ qWarning() << "Not able to read" << bgPath << "as image";
}
}
+
+ if (m_background.isNull()) {
+ arMode = Qt::IgnoreAspectRatio;
+ QStringList cols = _settings.gradientColors();
+ if (cols.length() == 4 || cols.length() == 2) {
+ bool ok = true;
+ uint a, b, c, d;
+ if (ok) c = a = cols.at(0).toUInt(&ok, 16) | 0xff000000;
+ if (ok) d = 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;
+ }
+ 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()) {
- m_background = QImage(2, 2, QImage::Format_RGB32);
- m_background.setPixel(0, 0, 0xffffffff);
- m_background.setPixel(1, 0, 0xff888687);
- m_background.setPixel(0, 1, 0xff888687);
- m_background.setPixel(1, 1, 0xfff9a72b);
+ // Hard-coded default: Gradient
+ m_background = QImage(2, 2, QImage::Format_RGB32);
+ m_background.setPixel(0, 0, 0xffffffff);
+ m_background.setPixel(1, 0, 0xff888687);
+ m_background.setPixel(0, 1, 0xff888687);
+ m_background.setPixel(1, 1, 0xfff9a72b);
}
QPalette palette;