/* * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "RosterDelegate.h" #include #include #include #include #include #include #include #include #include #include "Swift/Controllers/Roster/ContactRosterItem.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" #include "QtTreeWidget.h" #include "RosterModel.h" namespace Swift { RosterDelegate::RosterDelegate(QtTreeWidget* tree, bool compact) : compact_(compact) { tree_ = tree; groupDelegate_ = new GroupItemDelegate(); } RosterDelegate::~RosterDelegate() { delete groupDelegate_; } void RosterDelegate::setCompact(bool compact) { compact_ = compact; emit sizeHintChanged(QModelIndex()); } QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { RosterItem* item = static_cast(index.internalPointer()); if (dynamic_cast(item)) { return groupDelegate_->sizeHint(option, index); } return contactSizeHint(option, index); } QSize RosterDelegate::contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { return common_.contactSizeHint(option, index, compact_); } void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { RosterItem* item = static_cast(index.internalPointer()); if (dynamic_cast(item)) { paintGroup(painter, option, index); } else { paintContact(painter, option, index); } } void RosterDelegate::paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { if (index.isValid()) { groupDelegate_->paint(painter, option, index.data(Qt::DisplayRole).toString(), index.data(ChildCountRole).toInt(), tree_->isExpanded(index)); } } void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QColor nameColor = index.data(Qt::TextColorRole).value(); QString avatarPath; if (index.data(AvatarRole).isValid() && !index.data(AvatarRole).value().isNull()) { avatarPath = index.data(AvatarRole).value(); } QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value().isNull() ? index.data(PresenceIconRole).value() : QIcon(":/icons/offline.png"); bool isIdle = index.data(IdleRole).isValid() ? index.data(IdleRole).toBool() : false; QString name = index.data(Qt::DisplayRole).toString(); QString statusText = index.data(StatusTextRole).toString(); common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, isIdle, 0, compact_); } }