From d89fe10079f298fc16e851b8a0495b6275758b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Mon, 11 Oct 2021 22:24:38 +0200 Subject: [PATCH] Change overlay message style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Haris Gušić --- src/widgets/capture/overlaymessage.cpp | 25 ++++++++++++++++--------- src/widgets/capture/overlaymessage.h | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/widgets/capture/overlaymessage.cpp b/src/widgets/capture/overlaymessage.cpp index 8af2198b..767d4137 100644 --- a/src/widgets/capture/overlaymessage.cpp +++ b/src/widgets/capture/overlaymessage.cpp @@ -1,7 +1,6 @@ #include "overlaymessage.h" #include "colorutils.h" #include "confighandler.h" -#include "qguiappcurrentscreen.h" #include #include @@ -21,6 +20,17 @@ OverlayMessage::OverlayMessage(QWidget* parent, const QRect& targetArea) setAttribute(Qt::WA_AlwaysStackOnTop); setAlignment(Qt::AlignCenter); setTextFormat(Qt::RichText); + + m_fillColor = ConfigHandler().uiColor(); + int opacity = ConfigHandler().contrastOpacity(); + m_textColor = + (ColorUtils::colorIsDark(m_fillColor) ? Qt::white : Qt::black); + // map a background opacity range 0-255 to a fill opacity range 190-160 + // we do this because an opaque background makes the box look opaque too + m_fillColor.setAlpha(160 + (180 - 220) / (255.0 - 0) * (opacity - 255)); + setStyleSheet( + QStringLiteral("QLabel { color: %1; }").arg(m_textColor.name())); + setMargin(QApplication::fontMetrics().height() / 2); QWidget::hide(); } @@ -89,16 +99,13 @@ QString OverlayMessage::compileKeyMap(const QList>& map) void OverlayMessage::paintEvent(QPaintEvent* e) { QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); - QColor rectColor(ConfigHandler().uiColor()); - rectColor.setAlpha(180); - QColor textColor( - (ColorUtils::colorIsDark(rectColor) ? Qt::white : Qt::black)); - - painter.setBrush(QBrush(rectColor, Qt::SolidPattern)); - painter.setPen(QPen(textColor)); + painter.setBrush(QBrush(m_fillColor, Qt::SolidPattern)); + painter.setPen(QPen(m_textColor, 1.5)); float margin = painter.pen().widthF(); - painter.drawRect(rect() - QMarginsF(margin, margin, margin, margin)); + painter.drawRoundedRect( + rect() - QMarginsF(margin, margin, margin, margin), 5, 5); return QLabel::paintEvent(e); } diff --git a/src/widgets/capture/overlaymessage.h b/src/widgets/capture/overlaymessage.h index d8f40584..0fbbbc4a 100644 --- a/src/widgets/capture/overlaymessage.h +++ b/src/widgets/capture/overlaymessage.h @@ -34,6 +34,7 @@ public: private: QStack m_messageStack; QRect m_targetArea; + QColor m_fillColor, m_textColor; static OverlayMessage* m_instance; OverlayMessage(QWidget* parent, const QRect& center);