Remove hardcoded colors from the typing display

This commit is contained in:
Konstantinos Sideris 2018-08-08 12:51:40 +03:00
parent 88e535debe
commit 8d3ef470f9
5 changed files with 38 additions and 20 deletions

View file

@ -48,6 +48,10 @@ RoomList > * {
border: none; border: none;
} }
TypingDisplay {
qproperty-textColor: #caccd1;
}
#roomlist_area { #roomlist_area {
background-color: #2d3139; background-color: #2d3139;
} }

View file

@ -33,6 +33,10 @@ InfoMessage {
qproperty-boxColor: rgba(220, 220, 220, 120); qproperty-boxColor: rgba(220, 220, 220, 120);
} }
TypingDisplay {
qproperty-textColor: #333;
}
SuggestionsPopup { SuggestionsPopup {
background-color: white; background-color: white;
} }

View file

@ -31,6 +31,10 @@ QuickSwitcher {
background-color: palette(window); background-color: palette(window);
} }
TypingDisplay {
qproperty-textColor: palette(text);
}
InfoMessage { InfoMessage {
qproperty-textColor: palette(text); qproperty-textColor: palette(text);
qproperty-boxColor: palette(window); qproperty-boxColor: palette(window);

View file

@ -3,23 +3,29 @@
#include "Config.h" #include "Config.h"
#include "TypingDisplay.h" #include "TypingDisplay.h"
#include "ui/Painter.h"
constexpr int LEFT_PADDING = 24;
TypingDisplay::TypingDisplay(QWidget *parent) TypingDisplay::TypingDisplay(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, leftPadding_{24}
{ {
QFont font; QFont f;
font.setPixelSize(conf::typingNotificationFontSize); f.setPixelSize(conf::typingNotificationFontSize);
setFixedHeight(QFontMetrics(font).height() + 2); setFont(f);
setFixedHeight(QFontMetrics(font()).height() + 2);
} }
void void
TypingDisplay::setUsers(const QStringList &uid) TypingDisplay::setUsers(const QStringList &uid)
{ {
if (uid.isEmpty()) if (uid.isEmpty()) {
text_.clear(); text_.clear();
else return;
}
text_ = uid.join(", "); text_ = uid.join(", ");
if (uid.size() == 1) if (uid.size() == 1)
@ -33,22 +39,17 @@ TypingDisplay::setUsers(const QStringList &uid)
void void
TypingDisplay::paintEvent(QPaintEvent *) TypingDisplay::paintEvent(QPaintEvent *)
{ {
QPen pen(QColor("#898989")); Painter p(this);
PainterHighQualityEnabler hq(p);
QFont font("Open Sans Bold"); p.setFont(font());
font.setPixelSize(conf::typingNotificationFontSize); p.setPen(QPen(textColor()));
font.setItalic(true);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setFont(font);
p.setPen(pen);
QRect region = rect(); QRect region = rect();
region.translate(leftPadding_, 0); region.translate(LEFT_PADDING, 0);
QFontMetrics fm(font); QFontMetrics fm(font());
text_ = fm.elidedText(text_, Qt::ElideRight, width() - 3 * leftPadding_); text_ = fm.elidedText(text_, Qt::ElideRight, width() - 3 * LEFT_PADDING);
p.drawText(region, Qt::AlignVCenter, text_); p.drawText(region, Qt::AlignVCenter, text_);
} }

View file

@ -7,15 +7,20 @@ class TypingDisplay : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor)
public: public:
TypingDisplay(QWidget *parent = nullptr); TypingDisplay(QWidget *parent = nullptr);
void setUsers(const QStringList &user_ids); void setUsers(const QStringList &user_ids);
void setTextColor(const QColor &color) { textColor_ = color; };
QColor textColor() const { return textColor_; };
protected: protected:
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
private: private:
QColor textColor_;
QString text_; QString text_;
int leftPadding_;
}; };