matrixion/src/TypingDisplay.cpp

55 lines
1.2 KiB
C++
Raw Normal View History

2017-10-04 11:33:34 +03:00
#include <QPainter>
#include <QPoint>
#include "Config.h"
#include "TypingDisplay.h"
TypingDisplay::TypingDisplay(QWidget *parent)
: QWidget(parent)
2017-11-06 00:04:55 +03:00
, leftPadding_{24}
2017-10-04 11:33:34 +03:00
{
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");
2017-10-04 11:33:34 +03:00
else if (uid.size() > 1)
text_ += tr(" are typing");
2017-10-04 11:33:34 +03:00
update();
}
void
TypingDisplay::paintEvent(QPaintEvent *)
{
QPen pen(QColor("#898989"));
2017-10-04 11:33:34 +03:00
QFont font("Open Sans Bold");
2017-10-04 11:33:34 +03:00
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_);
2017-10-04 11:33:34 +03:00
}