From 294d54ea981df9201fec656cda027eb88752f0d1 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 10 Jul 2011 15:08:13 +0100 Subject: Include per-chat unread count in Chats diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp index 0c4356c..29dba62 100644 --- a/Swift/QtUI/ChatList/ChatListDelegate.cpp +++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp @@ -109,7 +109,7 @@ void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem QString name = item->data(Qt::DisplayRole).toString(); //qDebug() << "Avatar for " << name << " = " << avatarPath; QString statusText = item->data(ChatListRecentItem::DetailTextRole).toString(); - common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText); + common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, item->getChat().unreadCount); } } 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; diff --git a/Swift/QtUI/Roster/DelegateCommons.h b/Swift/QtUI/Roster/DelegateCommons.h index c79d64b..e5e4ff9 100644 --- a/Swift/QtUI/Roster/DelegateCommons.h +++ b/Swift/QtUI/Roster/DelegateCommons.h @@ -23,10 +23,10 @@ namespace Swift { detailFont.setPointSize(nameFont.pointSize() - detailFontSizeDrop); } - static void drawElidedText(QPainter* painter, const QRect& region, const QString& text); + static void drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags = Qt::AlignTop); QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText) const; + void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount) const; int detailFontSizeDrop; QFont nameFont; @@ -37,5 +37,6 @@ namespace Swift { static const int avatarSize; static const int presenceIconHeight; static const int presenceIconWidth; + static const int unreadCountSize; }; } diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index 1adb9e3..e40907a 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -71,7 +71,7 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& : QIcon(":/icons/offline.png"); QString name = index.data(Qt::DisplayRole).toString(); QString statusText = index.data(StatusTextRole).toString(); - common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText); + common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, 0); } } -- cgit v0.10.2-6-g49f6