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 | |
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')
-rw-r--r-- | Swift/QtUI/ChatList/ChatListDelegate.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/Roster/DelegateCommons.cpp | 21 | ||||
-rw-r--r-- | Swift/QtUI/Roster/DelegateCommons.h | 5 | ||||
-rw-r--r-- | Swift/QtUI/Roster/RosterDelegate.cpp | 2 |
4 files changed, 23 insertions, 7 deletions
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 @@ -103,13 +103,13 @@ void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem if (item->data(ChatListRecentItem::AvatarRole).isValid() && !item->data(ChatListRecentItem::AvatarRole).value<QString>().isNull()) { avatarPath = item->data(ChatListRecentItem::AvatarRole).value<QString>(); } QIcon presenceIcon = item->data(ChatListRecentItem::PresenceIconRole).isValid() && !item->data(ChatListRecentItem::PresenceIconRole).value<QIcon>().isNull() ? item->data(ChatListRecentItem::PresenceIconRole).value<QIcon>() : QIcon(":/icons/offline.png"); 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 @@ -6,24 +6,24 @@ #include "DelegateCommons.h" #include <QtScaledAvatarCache.h> #include <QFileInfo> 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 ) { painter->fillRect(fullRegion, option.palette.highlight()); painter->setPen(option.palette.highlightedText().color()); } else { painter->setPen(QPen(nameColor)); } @@ -61,18 +61,32 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem DelegateCommons::drawElidedText(painter, nameRegion, name); painter->setFont(detailFont); painter->setPen(QPen(QColor(160,160,160))); 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(); } QSize DelegateCommons::contactSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const { int heightByAvatar = avatarSize + verticalMargin * 2; QFontMetrics nameMetrics(nameFont); QFontMetrics statusMetrics(detailFont); int sizeByText = 2 * verticalMargin + nameMetrics.height() + statusMetrics.height(); //Doesn't work, yay! FIXME: why? @@ -81,13 +95,14 @@ QSize DelegateCommons::contactSizeHint(const QStyleOptionViewItem& /*option*/, c return QSize(150, sizeByText > heightByAvatar ? sizeByText : heightByAvatar); } const int DelegateCommons::horizontalMargin = 2; const int DelegateCommons::verticalMargin = 2; 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 @@ -17,25 +17,26 @@ namespace Swift { class DelegateCommons { public: DelegateCommons() : nameFont(QApplication::font()), detailFont(QApplication::font()) { detailFontSizeDrop = nameFont.pointSize() >= 10 ? 2 : 0; detailFont.setStyle(QFont::StyleItalic); 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; QFont detailFont; static const int horizontalMargin; static const int verticalMargin; static const int farLeftMargin; 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 @@ -65,14 +65,14 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& QString avatarPath; if (index.data(AvatarRole).isValid() && !index.data(AvatarRole).value<QString>().isNull()) { avatarPath = index.data(AvatarRole).value<QString>(); } QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value<QIcon>().isNull() ? index.data(PresenceIconRole).value<QIcon>() : 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); } } |