summaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp86
1 files changed, 72 insertions, 14 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b46a15b..9742852 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -17,6 +17,7 @@
#include <QSvgWidget>
#include <QSvgRenderer>
#include <QAbstractTextDocumentLayout>
+#include <QDateTime>
#include <sys/types.h>
#include <sys/socket.h>
@@ -26,14 +27,13 @@
#include "settings.h"
#include "global.h"
-static const Settings _settings;
-
MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidget *parent) :
QWidget(parent),
m_ScreenRect(screenRect),
m_Primary(primary),
m_LoginForm(NULL),
- m_messages(nullptr)
+ m_messages(nullptr),
+ m_Clock(nullptr)
{
setObjectName(QString("MainWindow_%1").arg(screen));
@@ -56,8 +56,8 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge
int maxY = screenRect.height() - m_LoginForm->height();
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();
@@ -72,18 +72,22 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge
}
// Banner
- if (!_settings.bannerImagePath().isEmpty()) {
- qWarning() << "Have banner " << _settings.bannerImagePath();
- QSvgWidget *banner = new QSvgWidget(_settings.bannerImagePath(), this);
+ if (!Settings::bannerImagePath().isEmpty()) {
+ qWarning() << "Have banner " << Settings::bannerImagePath();
+ QSvgWidget *banner = new QSvgWidget(Settings::bannerImagePath(), this);
qWarning() << banner->sizeHint();
if (banner->renderer()->isValid()) {
QSize sh;
int offs = 0;
do {
offs += 20;
- sh = banner->sizeHint().scaled(screenRect.width() - offs, spaceY - offs, Qt::KeepAspectRatio);
+ sh = banner->sizeHint().scaled(screenRect.width() - offs, spaceY - offs - 50, Qt::KeepAspectRatio);
} while (offs < 200 && sh.width() > screenRect.width() / 2 && sh.height() > spaceY / 2);
- banner->setGeometry((screenRect.width() - sh.width()) / 2, (spaceY - sh.height()) / 2, sh.width(), sh.height());
+ int yoff = (spaceY - sh.height());
+ if (yoff < 100) {
+ yoff = 100;
+ }
+ banner->setGeometry((screenRect.width() - sh.width()) / 2, yoff / 2, sh.width(), sh.height());
}
}
int ls = (spaceY > 500 ? 500 : spaceY);
@@ -98,6 +102,7 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge
lwSize.adjust(10, 10, -10, -10);
createLogWindow(lwSize);
}
+ createClock();
}
MainWindow::~MainWindow()
@@ -106,7 +111,7 @@ MainWindow::~MainWindow()
QSize MainWindow::createLogo(const QRect &max)
{
- QString path = _settings.bottomLeftLogoPath();
+ QString path = Settings::bottomLeftLogoPath();
if (path.isEmpty())
return QSize(0, 0);
QSvgWidget *img = new QSvgWidget(path, this);
@@ -144,7 +149,7 @@ QSize MainWindow::createDistro(const QRect &max)
void MainWindow::createLogWindow(const QRect& geom)
{
- QString path = _settings.logMessageFile();
+ QString path = Settings::logMessageFile();
if (path.isEmpty())
return;
QFile f(path);
@@ -178,6 +183,41 @@ void MainWindow::createLogWindow(const QRect& geom)
m_messages->setStyleSheet("border:none; background:rgba(255,255,255,.33); border-radius:5px");
}
+void MainWindow::createClock()
+{
+ QString style = Settings::clockStyle();
+ if (style == "none")
+ return;
+ if (style.isEmpty()) {
+ style = "border:none; background:rgba(255,255,255,0); color:#888687; font-size:26pt";
+ }
+ QStringList slist = Settings::clockShadow();
+ int x = 1, y = 1, blur = 1;
+ QString color = "#ddd";
+ if (slist.length() > 0) {
+ x = slist.at(0).toInt();
+ }
+ if (slist.length() > 1) {
+ y = slist.at(1).toInt();
+ }
+ if (slist.length() > 2) {
+ color = slist.at(2);
+ }
+ if (slist.length() > 3) {
+ blur = slist.at(3).toInt();
+ }
+ m_Clock = new QLabel("Today 00:00", this);
+ m_Clock->setStyleSheet(style);
+ QGraphicsDropShadowEffect *pLabelTextShadowEffect = new QGraphicsDropShadowEffect(this);
+ pLabelTextShadowEffect->setColor(QColor(color));
+ pLabelTextShadowEffect->setBlurRadius(blur);
+ pLabelTextShadowEffect->setOffset(x, y);
+ m_Clock->setGraphicsEffect(pLabelTextShadowEffect);
+ m_Clock->setAlignment(Qt::AlignRight);
+ m_Clock->setFixedWidth(this->width());
+ updateClock();
+}
+
bool MainWindow::showLoginForm()
{
return m_Primary;
@@ -220,7 +260,7 @@ int MainWindow::getOffset(QString settingsOffset, int maxVal, int defaultVal)
void MainWindow::setBackground()
{
Qt::AspectRatioMode arMode = Qt::KeepAspectRatioByExpanding;
- QString bgPath = _settings.backgrundImagePath();
+ QString bgPath = Settings::backgrundImagePath();
if (bgPath.length() != 0) {
m_background = QImage(bgPath);
if (m_background.isNull()) {
@@ -271,7 +311,7 @@ void MainWindow::showStandby()
} else {
qWarning() << "Shice!";
}
- QTimer::singleShot(7000, [this, img]() {
+ QTimer::singleShot(4000, [this, img]() {
img->hide();
img->deleteLater();
if (this->m_LoginForm != NULL) {
@@ -279,3 +319,21 @@ void MainWindow::showStandby()
}
});
}
+
+void MainWindow::updateClock()
+{
+ int next = drawClock();
+ if (next > 0) {
+ QTimer::singleShot(next, this, SLOT(updateClock()));
+ }
+}
+
+int MainWindow::drawClock()
+{
+ if (m_Clock == nullptr)
+ return 0;
+ QDateTime time = QDateTime::currentDateTime();
+ QLocale loc;
+ m_Clock->setText(time.toString(loc.dateFormat() + " HH:mm "));
+ return (60 - time.time().second()) * 1000 + 100;
+}