diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-04-15 02:56:04 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-04-15 02:56:04 +0300 |
commit | 3b0ff1a4cdd0c7eb3ed06eec2e70ee2722b7c4e5 (patch) | |
tree | 2e243545972ee7ef4f07152359bbdd782e6ca011 /src/ui | |
parent | Update screen (diff) | |
download | nheko-3b0ff1a4cdd0c7eb3ed06eec2e70ee2722b7c4e5.tar.xz |
Add initial support for unread message count
- Add border width on Badge
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/Badge.cc | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/ui/Badge.cc b/src/ui/Badge.cc index 05531f6c..c799dbf2 100644 --- a/src/ui/Badge.cc +++ b/src/ui/Badge.cc @@ -30,12 +30,14 @@ void Badge::init() { x_ = 0; y_ = 0; - padding_ = 10; + // TODO: Make padding configurable. + padding_ = 5; + diameter_ = 24; setAttribute(Qt::WA_TransparentForMouseEvents); QFont _font(font()); - _font.setPointSizeF(10); + _font.setPointSizeF(7.5); _font.setStyleName("Bold"); setFont(_font); @@ -54,7 +56,7 @@ QIcon Badge::icon() const QSize Badge::sizeHint() const { - const int d = getDiameter(); + const int d = diameter(); return QSize(d + 4, d + 4); } @@ -141,6 +143,14 @@ void Badge::setText(const QString &text) update(); } +void Badge::setDiameter(int diameter) +{ + if (diameter > 0) { + diameter_ = diameter; + update(); + } +} + void Badge::paintEvent(QPaintEvent *) { QPainter painter(this); @@ -154,13 +164,20 @@ void Badge::paintEvent(QPaintEvent *) painter.setBrush(brush); painter.setPen(Qt::NoPen); - const int d = getDiameter(); + const int d = diameter(); QRectF r(0, 0, d, d); r.translate(QPointF((width() - d), (height() - d)) / 2); if (icon_.isNull()) { + QPen pen; + // TODO: Make badge width configurable. + pen.setWidth(1); + pen.setColor(textColor()); + + painter.setPen(pen); painter.drawEllipse(r); + painter.setPen(textColor()); painter.setBrush(Qt::NoBrush); painter.drawText(r.translated(0, -0.5), Qt::AlignCenter, text_); @@ -176,11 +193,11 @@ void Badge::paintEvent(QPaintEvent *) } } -int Badge::getDiameter() const +int Badge::diameter() const { if (icon_.isNull()) { return qMax(size_.width(), size_.height()) + padding_; } - // FIXME: Move this to Theme.h as the default - return 24; + + return diameter_; } |