From a339f5062fa572e4f276b9fe143b772b71af5a5b Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 10 Aug 2018 10:58:46 +0300 Subject: [PATCH] Add solid background in TypingDisplay --- resources/styles/nheko-dark.qss | 1 + resources/styles/nheko.qss | 1 + resources/styles/system.qss | 1 + src/TypingDisplay.cpp | 9 +++++++-- src/TypingDisplay.h | 5 +++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/resources/styles/nheko-dark.qss b/resources/styles/nheko-dark.qss index bf3d43ee..d4dca17c 100644 --- a/resources/styles/nheko-dark.qss +++ b/resources/styles/nheko-dark.qss @@ -50,6 +50,7 @@ RoomList > * { TypingDisplay { qproperty-textColor: #caccd1; + qproperty-backgroundColor: #202228; } #roomlist_area { diff --git a/resources/styles/nheko.qss b/resources/styles/nheko.qss index 3d9231d9..ef659b82 100644 --- a/resources/styles/nheko.qss +++ b/resources/styles/nheko.qss @@ -35,6 +35,7 @@ InfoMessage { TypingDisplay { qproperty-textColor: #333; + qproperty-backgroundColor: white; } SuggestionsPopup { diff --git a/resources/styles/system.qss b/resources/styles/system.qss index e518f084..9df3f1a7 100644 --- a/resources/styles/system.qss +++ b/resources/styles/system.qss @@ -33,6 +33,7 @@ QuickSwitcher { TypingDisplay { qproperty-textColor: palette(text); + qproperty-backgroundColor: palette(window); } InfoMessage { diff --git a/src/TypingDisplay.cpp b/src/TypingDisplay.cpp index cd405a7a..6b731740 100644 --- a/src/TypingDisplay.cpp +++ b/src/TypingDisplay.cpp @@ -8,6 +8,7 @@ #include "ui/Painter.h" constexpr int LEFT_PADDING = 24; +constexpr int RECT_PADDING = 2; TypingDisplay::TypingDisplay(QWidget *parent) : OverlayWidget(parent) @@ -17,7 +18,7 @@ TypingDisplay::TypingDisplay(QWidget *parent) f.setPixelSize(conf::typingNotificationFontSize); setFont(f); - setFixedHeight(QFontMetrics(font()).height() + 2); + setFixedHeight(QFontMetrics(font()).height() + RECT_PADDING); setAttribute(Qt::WA_TransparentForMouseEvents); } @@ -66,7 +67,11 @@ TypingDisplay::paintEvent(QPaintEvent *) region.translate(LEFT_PADDING, 0); QFontMetrics fm(font()); - text_ = fm.elidedText(text_, Qt::ElideRight, width() - 3 * LEFT_PADDING); + text_ = fm.elidedText(text_, Qt::ElideRight, (double)(width() * 0.75)); + QPainterPath path; + path.addRoundedRect(QRectF(0, 0, fm.width(text_) + 2 * LEFT_PADDING, height()), 3, 3); + + p.fillPath(path, backgroundColor()); p.drawText(region, Qt::AlignVCenter, text_); } diff --git a/src/TypingDisplay.h b/src/TypingDisplay.h index c4e6c357..332d9c66 100644 --- a/src/TypingDisplay.h +++ b/src/TypingDisplay.h @@ -9,6 +9,7 @@ class TypingDisplay : public OverlayWidget Q_OBJECT Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) + Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor) public: TypingDisplay(QWidget *parent = nullptr); @@ -18,6 +19,9 @@ public: void setTextColor(const QColor &color) { textColor_ = color; }; QColor textColor() const { return textColor_; }; + void setBackgroundColor(const QColor &color) { bgColor_ = color; }; + QColor backgroundColor() const { return bgColor_; }; + public slots: void setOffset(int margin); @@ -27,5 +31,6 @@ protected: private: int offset_; QColor textColor_; + QColor bgColor_; QString text_; };