summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-07-09 18:54:55 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-07-09 18:54:55 (GMT)
commit26ac55fc087fb49abbdd164e125e41207e66f9fd (patch)
treec2187cd35e1c55af023de38d72150ab6e1530d91 /Swift/QtUI/ChatList
parent54ae49f8485bce7794b1f061f4d1a305f2063f10 (diff)
downloadswift-contrib-26ac55fc087fb49abbdd164e125e41207e66f9fd.zip
swift-contrib-26ac55fc087fb49abbdd164e125e41207e66f9fd.tar.bz2
Update QtChatList for recent backend changes
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r--Swift/QtUI/ChatList/ChatListDelegate.cpp39
-rw-r--r--Swift/QtUI/ChatList/ChatListRecentItem.cpp19
-rw-r--r--Swift/QtUI/ChatList/ChatListRecentItem.h6
3 files changed, 31 insertions, 33 deletions
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp
index b2bfe0a..520b40e 100644
--- a/Swift/QtUI/ChatList/ChatListDelegate.cpp
+++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp
@@ -30,7 +30,7 @@ QSize ChatListDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode
return mucSizeHint(option, index);
}
else if (item && dynamic_cast<ChatListRecentItem*>(item)) {
- return recentSizeHint(option, index);
+ return common_.contactSizeHint(option, index);
}
else if (item && dynamic_cast<ChatListGroupItem*>(item)) {
return groupDelegate_->sizeHint(option, index);
@@ -98,34 +98,17 @@ void ChatListDelegate::paintMUC(QPainter* painter, const QStyleOptionViewItem& o
}
void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) 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 {
- QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
- painter->setPen(QPen(nameColor));
+ QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
+ QString avatarPath;
+ if (item->data(ChatListRecentItem::AvatarRole).isValid() && !item->data(ChatListRecentItem::AvatarRole).value<QString>().isNull()) {
+ QString avatarPath = item->data(ChatListRecentItem::AvatarRole).value<QString>();
}
-
- QFontMetrics nameMetrics(common_.nameFont);
- painter->setFont(common_.nameFont);
- int extraFontWidth = nameMetrics.width("H");
- int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2;
- QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0));
-
- int nameHeight = nameMetrics.height() + common_.verticalMargin;
- QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0));
-
- DelegateCommons::drawElidedText(painter, nameRegion, item->data(Qt::DisplayRole).toString());
-
- painter->setFont(common_.detailFont);
- painter->setPen(QPen(QColor(160,160,160)));
-
- QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0));
- DelegateCommons::drawElidedText(painter, detailRegion, item->data(ChatListRecentItem::DetailTextRole).toString());
-
- painter->restore();
+ 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();
+ QString statusText = item->data(ChatListRecentItem::DetailTextRole).toString();
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText);
}
}
diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.cpp b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
index 38f9a5e..e7c9599 100644
--- a/Swift/QtUI/ChatList/ChatListRecentItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
@@ -24,11 +24,24 @@ QVariant ChatListRecentItem::data(int role) const {
/*case Qt::TextColorRole: return textColor_;
case Qt::BackgroundColorRole: return backgroundColor_;
case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
- case StatusTextRole: return statusText_;
- case AvatarRole: return avatar_;
- case PresenceIconRole: return getPresenceIcon();*/
+ case StatusTextRole: return statusText_;*/
+ case AvatarRole: return chat_.avatarPath.string().c_str();
+ case PresenceIconRole: return getPresenceIcon();
default: return QVariant();
}
}
+QIcon ChatListRecentItem::getPresenceIcon() const {
+ QString iconString;
+ switch (chat_.statusType) {
+ case StatusShow::Online: iconString = "online";break;
+ case StatusShow::Away: iconString = "away";break;
+ case StatusShow::XA: iconString = "away";break;
+ case StatusShow::FFC: iconString = "online";break;
+ case StatusShow::DND: iconString = "dnd";break;
+ case StatusShow::None: iconString = "offline";break;
+ }
+ return QIcon(":/icons/" + iconString + ".png");
+}
+
}
diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.h b/Swift/QtUI/ChatList/ChatListRecentItem.h
index f88de77..4e7bc3e 100644
--- a/Swift/QtUI/ChatList/ChatListRecentItem.h
+++ b/Swift/QtUI/ChatList/ChatListRecentItem.h
@@ -7,6 +7,7 @@
#pragma once
#include <QList>
+#include <QIcon>
#include <boost/shared_ptr.hpp>
@@ -19,15 +20,16 @@ namespace Swift {
class ChatListRecentItem : public ChatListItem {
public:
enum RecentItemRoles {
- DetailTextRole = Qt::UserRole/*,
+ DetailTextRole = Qt::UserRole,
AvatarRole = Qt::UserRole + 1,
- PresenceIconRole = Qt::UserRole + 2,
+ PresenceIconRole = Qt::UserRole + 2/*,
StatusShowTypeRole = Qt::UserRole + 3*/
};
ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent);
const ChatListWindow::Chat& getChat() const;
QVariant data(int role) const;
private:
+ QIcon getPresenceIcon() const;
ChatListWindow::Chat chat_;
};
}