diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-10-04 11:33:34 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-10-04 11:33:34 +0300 |
commit | d60c2b76e30dcbdb1eae2a69b2d3ddff128d00c5 (patch) | |
tree | b54dfe5e789c3f42ce8ef26f988a2f30ab62ad4c /src/TypingDisplay.cc | |
parent | Recover from corrupted cache data (diff) | |
download | nheko-d60c2b76e30dcbdb1eae2a69b2d3ddff128d00c5.tar.xz |
Receive typing notifications (#88)
Diffstat (limited to 'src/TypingDisplay.cc')
-rw-r--r-- | src/TypingDisplay.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/TypingDisplay.cc b/src/TypingDisplay.cc new file mode 100644 index 00000000..619b70cb --- /dev/null +++ b/src/TypingDisplay.cc @@ -0,0 +1,56 @@ +#include <QDebug> +#include <QPainter> +#include <QPoint> + +#include "Config.h" +#include "TypingDisplay.h" + +TypingDisplay::TypingDisplay(QWidget *parent) + : QWidget(parent) + , leftPadding_{ 57 } +{ + QFont font; + font.setPixelSize(conf::typingNotificationFontSize); + + setFixedHeight(QFontMetrics(font).height() + 2); +} + +void +TypingDisplay::setUsers(const QStringList &uid) +{ + if (uid.isEmpty()) + text_.clear(); + else + text_ = uid.join(", "); + + if (uid.size() == 1) + text_ += tr(" is typing ..."); + else if (uid.size() > 1) + text_ += tr(" are typing ..."); + + update(); +} + +void +TypingDisplay::paintEvent(QPaintEvent *) +{ + QPen pen(QColor("#333")); + + QFont font; + font.setPixelSize(conf::typingNotificationFontSize); + font.setWeight(40); + font.setItalic(true); + + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + p.setFont(font); + p.setPen(pen); + + QRect region = rect(); + region.translate(leftPadding_, 0); + + QFontMetrics fm(font); + text_ = fm.elidedText(text_, Qt::ElideRight, width() - 3 * leftPadding_); + + p.drawText(region, Qt::AlignTop, text_); +} |