From 40781f99d55c4368a2154aa2285ea5cc15b916f9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 11 Apr 2018 16:59:54 +0200 Subject: Restructure clock styling, split background and text so shadows work with bgcolor --- src/mainwindow.cpp | 22 +++++++++++++++++----- src/settings.h | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9742852..0ebdb59 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -186,14 +186,20 @@ void MainWindow::createLogWindow(const QRect& geom) void MainWindow::createClock() { QString style = Settings::clockStyle(); + QString backgroundStyle = Settings::clockBackgroundStyle(); if (style == "none") return; if (style.isEmpty()) { - style = "border:none; background:rgba(255,255,255,0); color:#888687; font-size:26pt"; + style = "border:none; color:#fff; font-size:14pt; qproperty-alignment:AlignRight"; + } + if (backgroundStyle.isEmpty()) { + backgroundStyle = "#bg { border:none; background:#888687 }"; + } else { + backgroundStyle = "#bg { " + backgroundStyle + " }"; } QStringList slist = Settings::clockShadow(); int x = 1, y = 1, blur = 1; - QString color = "#ddd"; + QString color = "#555"; if (slist.length() > 0) { x = slist.at(0).toInt(); } @@ -206,14 +212,18 @@ void MainWindow::createClock() if (slist.length() > 3) { blur = slist.at(3).toInt(); } - m_Clock = new QLabel("Today 00:00", this); + QWidget *bg = new QWidget(this); + bg->setObjectName("bg"); + bg->setFixedWidth(this->width()); + bg->setMaximumHeight(500); + bg->setStyleSheet(backgroundStyle); + m_Clock = new QLabel("Today 00:00", bg); m_Clock->setStyleSheet(style); - QGraphicsDropShadowEffect *pLabelTextShadowEffect = new QGraphicsDropShadowEffect(this); + QGraphicsDropShadowEffect *pLabelTextShadowEffect = new QGraphicsDropShadowEffect(m_Clock); 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(); } @@ -335,5 +345,7 @@ int MainWindow::drawClock() QDateTime time = QDateTime::currentDateTime(); QLocale loc; m_Clock->setText(time.toString(loc.dateFormat() + " HH:mm ")); + m_Clock->adjustSize(); + ((QWidget*)m_Clock->parent())->adjustSize(); return (60 - time.time().second()) * 1000 + 100; } diff --git a/src/settings.h b/src/settings.h index f55d6ce..d2213ae 100644 --- a/src/settings.h +++ b/src/settings.h @@ -23,7 +23,8 @@ public: static QStringList gradientColors() { return s_settings->value("greeter-background-gradient").toString().split(QRegExp("\\s"), QString::SkipEmptyParts); } static QString logMessageFile() { return s_settings->value("greeter-message-file").toString(); } static QString autoLoginCheckCmd() { return s_settings->value("auto-login-check-cmd").toString(); } - static QString clockStyle() { return s_settings->value("clock-style").toString(); } + static QString clockStyle() { return s_settings->value("clock-text-style").toString(); } + static QString clockBackgroundStyle() { return s_settings->value("clock-background-style").toString(); } static QStringList clockShadow() { return s_settings->value("clock-shadow").toString().split(QRegExp("\\s"), QString::SkipEmptyParts); } }; -- cgit v1.2.3-55-g7522