summaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp107
1 files changed, 83 insertions, 24 deletions
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());
}