blob: da9c1679de396d80d0e0fb2828c887047d70f362 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include <QPainter>
#include <QPoint>
#include "Config.h"
#include "TypingDisplay.h"
TypingDisplay::TypingDisplay(QWidget *parent)
: QWidget(parent)
, leftPadding_{24}
{
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("#898989"));
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);
QRect region = rect();
region.translate(leftPadding_, 0);
QFontMetrics fm(font);
text_ = fm.elidedText(text_, Qt::ElideRight, width() - 3 * leftPadding_);
p.drawText(region, Qt::AlignVCenter, text_);
}
|