Add solid background in TypingDisplay

This commit is contained in:
Konstantinos Sideris 2018-08-10 10:58:46 +03:00
parent d0b3254d10
commit a339f5062f
5 changed files with 15 additions and 2 deletions

View file

@ -50,6 +50,7 @@ RoomList > * {
TypingDisplay { TypingDisplay {
qproperty-textColor: #caccd1; qproperty-textColor: #caccd1;
qproperty-backgroundColor: #202228;
} }
#roomlist_area { #roomlist_area {

View file

@ -35,6 +35,7 @@ InfoMessage {
TypingDisplay { TypingDisplay {
qproperty-textColor: #333; qproperty-textColor: #333;
qproperty-backgroundColor: white;
} }
SuggestionsPopup { SuggestionsPopup {

View file

@ -33,6 +33,7 @@ QuickSwitcher {
TypingDisplay { TypingDisplay {
qproperty-textColor: palette(text); qproperty-textColor: palette(text);
qproperty-backgroundColor: palette(window);
} }
InfoMessage { InfoMessage {

View file

@ -8,6 +8,7 @@
#include "ui/Painter.h" #include "ui/Painter.h"
constexpr int LEFT_PADDING = 24; constexpr int LEFT_PADDING = 24;
constexpr int RECT_PADDING = 2;
TypingDisplay::TypingDisplay(QWidget *parent) TypingDisplay::TypingDisplay(QWidget *parent)
: OverlayWidget(parent) : OverlayWidget(parent)
@ -17,7 +18,7 @@ TypingDisplay::TypingDisplay(QWidget *parent)
f.setPixelSize(conf::typingNotificationFontSize); f.setPixelSize(conf::typingNotificationFontSize);
setFont(f); setFont(f);
setFixedHeight(QFontMetrics(font()).height() + 2); setFixedHeight(QFontMetrics(font()).height() + RECT_PADDING);
setAttribute(Qt::WA_TransparentForMouseEvents); setAttribute(Qt::WA_TransparentForMouseEvents);
} }
@ -66,7 +67,11 @@ TypingDisplay::paintEvent(QPaintEvent *)
region.translate(LEFT_PADDING, 0); region.translate(LEFT_PADDING, 0);
QFontMetrics fm(font()); 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_); p.drawText(region, Qt::AlignVCenter, text_);
} }

View file

@ -9,6 +9,7 @@ class TypingDisplay : public OverlayWidget
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor)
Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor)
public: public:
TypingDisplay(QWidget *parent = nullptr); TypingDisplay(QWidget *parent = nullptr);
@ -18,6 +19,9 @@ public:
void setTextColor(const QColor &color) { textColor_ = color; }; void setTextColor(const QColor &color) { textColor_ = color; };
QColor textColor() const { return textColor_; }; QColor textColor() const { return textColor_; };
void setBackgroundColor(const QColor &color) { bgColor_ = color; };
QColor backgroundColor() const { return bgColor_; };
public slots: public slots:
void setOffset(int margin); void setOffset(int margin);
@ -27,5 +31,6 @@ protected:
private: private:
int offset_; int offset_;
QColor textColor_; QColor textColor_;
QColor bgColor_;
QString text_; QString text_;
}; };