diff options
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r-- | src/mainwindow.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9c23c58..5bc38b9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -49,6 +49,16 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge // display login dialog only in the main screen + /* + * Everything is layed out manually here, since I don't know how to represent the size constraints + * and interactions of everything using layout classes. You're welcome to improve this, but I double + * dare you to not break any combination of having/not having certain logos or elements displayed. + */ + + int newsY = 100; + int newsX = screenRect.width() / 2; + int newsBottom = screenRect.height(); + int spaceY = screenRect.height() / 2; if (showLoginForm()) { @@ -72,6 +82,7 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge int centerX = screenRect.width()/2 + screenRect.x(); int centerY = screenRect.height()/2 + screenRect.y(); QCursor::setPos(centerX, centerY); + newsX = m_LoginForm->geometry().right() + 5; } // Banner @@ -91,6 +102,7 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge yoff = 100; } banner->setGeometry((screenRect.width() - sh.width()) / 2, yoff / 2, sh.width(), sh.height()); + newsY = banner->geometry().bottom() + 10; } } int ls = (spaceY > 500 ? 500 : spaceY); @@ -100,12 +112,22 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge QSize logoSize = createLogo(logoRect); QRect distroRect(QPoint(screenRect.width() - ls, screenRect.height() - ls), QSize(ls, ls)); QSize distroSize = createDistro(distroRect); + if (distroSize.height() > 0) { + newsBottom -= distroSize.height() - 10; + } if (showLoginForm()) { + // Log window QRect lwSize(QPoint(logoSize.width(), screenRect.height() * 3/4), QPoint(screenRect.width() - distroSize.width(), screenRect.height())); lwSize.adjust(10, 10, -10, -10); - createLogWindow(lwSize); + if (createLogWindow(lwSize)) { + newsBottom = lwSize.top(); + } } createClock(); + + // News widget + QRect newsSize(QPoint(newsX, newsY), QPoint(screenRect.width() - 10, newsBottom - 10)); + createNewsWindow(newsSize); } MainWindow::~MainWindow() @@ -123,7 +145,7 @@ void MainWindow::paintEvent(QPaintEvent *event) void MainWindow::mouseDoubleClickEvent(QMouseEvent *) { if (m_Snake == nullptr) { - m_Snake = new Snake(this); + m_Snake = new GameCore(this); } else { m_Snake->addSnake(); } @@ -189,14 +211,14 @@ QSize MainWindow::createDistro(const QRect &max) return virtualSize; } -void MainWindow::createLogWindow(const QRect& geom) +bool MainWindow::createLogWindow(const QRect& geom) { QString path = Settings::logMessageFile(); if (path.isEmpty()) - return; + return false; QFile f(path); if (f.size() == 0 || !f.open(QFile::ReadOnly)) - return; + return false; m_messages = new QTextEdit(this); m_messages->setGeometry(geom); int ps = geom.height() / 20; @@ -223,6 +245,24 @@ void MainWindow::createLogWindow(const QRect& geom) } m_messages->setReadOnly(true); m_messages->setStyleSheet("border:none; background:rgba(255,255,255,.33); border-radius:5px"); + return true; +} + +void MainWindow::createNewsWindow(const QRect &size) +{ + if (size.width() < 100 || size.height() < 100) + return; + QString path = Settings::newsHtmlFile(); + if (path.isEmpty()) + return; + QFile f(path); + if (f.size() == 0 || !f.open(QFile::ReadOnly)) + return; + QTextEdit *news = new QTextEdit(this); + news->setReadOnly(true); + news->setStyleSheet("border:none; background:rgba(255,255,255,.33); border-radius:5px"); + news->setHtml(QString::fromUtf8(f.readAll())); + news->setGeometry(size); } void MainWindow::createClock() |