Make the number of unread messages fit in the bubble

fixes #330
pull/1/head
Konstantinos Sideris 7 years ago
parent 5e9d8373e4
commit 5538a04690
  1. 1
      include/RoomInfoListItem.h
  2. 32
      src/RoomInfoListItem.cc

@ -200,6 +200,7 @@ private:
QFont timestampFont_;
QFont usernameFont_;
QFont unreadCountFont_;
int bubbleDiameter_;
QColor timestampColor_;
QColor highlightedTimestampColor_;

@ -31,7 +31,7 @@
#include "Theme.h"
#include "Utils.h"
constexpr int BubbleDiameter = 18;
constexpr int MaxUnreadCountDisplayed = 99;
constexpr int Padding = 9;
constexpr int IconSize = 44;
@ -65,6 +65,7 @@ RoomInfoListItem::init(QWidget *parent)
unreadCountFont_.setPixelSize(conf::roomlist::fonts::badge);
unreadCountFont_.setBold(true);
bubbleDiameter_ = QFontMetrics(unreadCountFont_).averageCharWidth() * 3;
timestampFont_ = font_;
timestampFont_.setPixelSize(conf::roomlist::fonts::timestamp);
@ -274,16 +275,22 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
p.setPen(Qt::NoPen);
p.setFont(unreadCountFont_);
QRectF r(width() - BubbleDiameter - Padding,
bottom_y - BubbleDiameter / 2 - 5,
BubbleDiameter,
BubbleDiameter);
// Extra space on the x-axis to accomodate the extra character space
// inside the bubble.
const int x_width = unreadMsgCount_ > MaxUnreadCountDisplayed
? QFontMetrics(p.font()).averageCharWidth()
: 0;
QRectF r(width() - bubbleDiameter_ - Padding - x_width,
bottom_y - bubbleDiameter_ / 2 - 5,
bubbleDiameter_ + x_width,
bubbleDiameter_);
if (width() == ui::sidebar::SmallSize)
r = QRectF(width() - BubbleDiameter - 5,
height() - BubbleDiameter - 5,
BubbleDiameter,
BubbleDiameter);
r = QRectF(width() - bubbleDiameter_ - 5,
height() - bubbleDiameter_ - 5,
bubbleDiameter_ + x_width,
bubbleDiameter_);
p.setPen(Qt::NoPen);
p.drawEllipse(r);
@ -293,9 +300,12 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
if (isPressed_)
p.setPen(QPen(bubbleBgColor()));
auto countTxt = unreadMsgCount_ > MaxUnreadCountDisplayed
? QString("99+")
: QString::number(unreadMsgCount_);
p.setBrush(Qt::NoBrush);
p.drawText(
r.translated(0, -0.5), Qt::AlignCenter, QString::number(unreadMsgCount_));
p.drawText(r.translated(0, -0.5), Qt::AlignCenter, countTxt);
}
}

Loading…
Cancel
Save