diff options
author | Kevin Smith <git@kismith.co.uk> | 2011-07-10 14:08:13 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2011-07-10 14:08:13 (GMT) |
commit | 294d54ea981df9201fec656cda027eb88752f0d1 (patch) | |
tree | 7c44d01844d5b51bb52befe04ea1d1061d5dd875 /Swift/QtUI/Roster/DelegateCommons.cpp | |
parent | 72cd949dd179f0781c156544b87cb6d1d5c34862 (diff) | |
download | swift-contrib-294d54ea981df9201fec656cda027eb88752f0d1.zip swift-contrib-294d54ea981df9201fec656cda027eb88752f0d1.tar.bz2 |
Include per-chat unread count in Chats
Diffstat (limited to 'Swift/QtUI/Roster/DelegateCommons.cpp')
-rw-r--r-- | Swift/QtUI/Roster/DelegateCommons.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/Swift/QtUI/Roster/DelegateCommons.cpp b/Swift/QtUI/Roster/DelegateCommons.cpp index 1e02086..290794d 100644 --- a/Swift/QtUI/Roster/DelegateCommons.cpp +++ b/Swift/QtUI/Roster/DelegateCommons.cpp @@ -12,12 +12,12 @@ namespace Swift { -void DelegateCommons::drawElidedText(QPainter* painter, const QRect& region, const QString& text) { +void DelegateCommons::drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags) { QString adjustedText(painter->fontMetrics().elidedText(text, Qt::ElideRight, region.width(), Qt::TextShowMnemonic)); - painter->drawText(region, Qt::AlignTop, adjustedText); + painter->drawText(region, flags, adjustedText); } -void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText) const { +void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount) const { painter->save(); QRect fullRegion(option.rect); if ( option.state & QStyle::State_Selected ) { @@ -67,6 +67,20 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0)); DelegateCommons::drawElidedText(painter, statusTextRegion, statusText); + if (unreadCount > 0) { + QRect unreadRect(fullRegion.right() - unreadCountSize - horizontalMargin, fullRegion.top() + (fullRegion.height() - unreadCountSize) / 2, unreadCountSize, unreadCountSize); + QPen pen(QColor("black")); + pen.setWidth(1); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->setPen(pen); + painter->setBrush(QBrush(QColor("red"), Qt::SolidPattern)); + //painter->setBackgroundMode(Qt::OpaqueMode); + painter->drawEllipse(unreadRect); + painter->setBackgroundMode(Qt::TransparentMode); + painter->setPen(QColor("white")); + drawElidedText(painter, unreadRect, QString("%1").arg(unreadCount), Qt::AlignCenter); + } + painter->restore(); } @@ -87,6 +101,7 @@ const int DelegateCommons::farLeftMargin = 2; const int DelegateCommons::avatarSize = 20; const int DelegateCommons::presenceIconHeight = 16; const int DelegateCommons::presenceIconWidth = 16; +const int DelegateCommons::unreadCountSize = 16; |