diff --git a/resources/styles/nheko-dark.qss b/resources/styles/nheko-dark.qss index 7c9ca37b..bf3d43ee 100644 --- a/resources/styles/nheko-dark.qss +++ b/resources/styles/nheko-dark.qss @@ -48,6 +48,10 @@ RoomList > * { border: none; } +TypingDisplay { + qproperty-textColor: #caccd1; +} + #roomlist_area { background-color: #2d3139; } diff --git a/resources/styles/nheko.qss b/resources/styles/nheko.qss index 1752c061..3d9231d9 100644 --- a/resources/styles/nheko.qss +++ b/resources/styles/nheko.qss @@ -33,6 +33,10 @@ InfoMessage { qproperty-boxColor: rgba(220, 220, 220, 120); } +TypingDisplay { + qproperty-textColor: #333; +} + SuggestionsPopup { background-color: white; } diff --git a/resources/styles/system.qss b/resources/styles/system.qss index 7dc37418..e518f084 100644 --- a/resources/styles/system.qss +++ b/resources/styles/system.qss @@ -31,6 +31,10 @@ QuickSwitcher { background-color: palette(window); } +TypingDisplay { + qproperty-textColor: palette(text); +} + InfoMessage { qproperty-textColor: palette(text); qproperty-boxColor: palette(window); diff --git a/src/TypingDisplay.cpp b/src/TypingDisplay.cpp index da9c1679..30ba0652 100644 --- a/src/TypingDisplay.cpp +++ b/src/TypingDisplay.cpp @@ -3,24 +3,30 @@ #include "Config.h" #include "TypingDisplay.h" +#include "ui/Painter.h" + +constexpr int LEFT_PADDING = 24; TypingDisplay::TypingDisplay(QWidget *parent) : QWidget(parent) - , leftPadding_{24} { - QFont font; - font.setPixelSize(conf::typingNotificationFontSize); + QFont f; + f.setPixelSize(conf::typingNotificationFontSize); - setFixedHeight(QFontMetrics(font).height() + 2); + setFont(f); + + setFixedHeight(QFontMetrics(font()).height() + 2); } void TypingDisplay::setUsers(const QStringList &uid) { - if (uid.isEmpty()) + if (uid.isEmpty()) { text_.clear(); - else - text_ = uid.join(", "); + return; + } + + text_ = uid.join(", "); if (uid.size() == 1) text_ += tr(" is typing"); @@ -33,22 +39,17 @@ TypingDisplay::setUsers(const QStringList &uid) void TypingDisplay::paintEvent(QPaintEvent *) { - QPen pen(QColor("#898989")); + Painter p(this); + PainterHighQualityEnabler hq(p); - QFont font("Open Sans Bold"); - font.setPixelSize(conf::typingNotificationFontSize); - font.setItalic(true); - - QPainter p(this); - p.setRenderHint(QPainter::Antialiasing); - p.setFont(font); - p.setPen(pen); + p.setFont(font()); + p.setPen(QPen(textColor())); QRect region = rect(); - region.translate(leftPadding_, 0); + region.translate(LEFT_PADDING, 0); - QFontMetrics fm(font); - text_ = fm.elidedText(text_, Qt::ElideRight, width() - 3 * leftPadding_); + QFontMetrics fm(font()); + text_ = fm.elidedText(text_, Qt::ElideRight, width() - 3 * LEFT_PADDING); p.drawText(region, Qt::AlignVCenter, text_); } diff --git a/src/TypingDisplay.h b/src/TypingDisplay.h index db8a9519..d5e2f29c 100644 --- a/src/TypingDisplay.h +++ b/src/TypingDisplay.h @@ -7,15 +7,20 @@ class TypingDisplay : public QWidget { Q_OBJECT + Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) + public: TypingDisplay(QWidget *parent = nullptr); void setUsers(const QStringList &user_ids); + void setTextColor(const QColor &color) { textColor_ = color; }; + QColor textColor() const { return textColor_; }; + protected: void paintEvent(QPaintEvent *event) override; private: + QColor textColor_; QString text_; - int leftPadding_; };