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