diff options
| author | Kevin Smith <git@kismith.co.uk> | 2011-11-01 23:04:03 (GMT) |
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2011-11-01 23:04:03 (GMT) |
| commit | 16d50c0df983e96a28a6572da27b3633b40a41d7 (patch) | |
| tree | 9b7a74f074e33d00966b2e8bf71d31162fa619dc /Swift/QtUI/Roster/RosterDelegate.cpp | |
| parent | a710cb325c7827679c35c61ab41b821a5bc77673 (diff) | |
| download | swift-contrib-16d50c0df983e96a28a6572da27b3633b40a41d7.zip swift-contrib-16d50c0df983e96a28a6572da27b3633b40a41d7.tar.bz2 | |
Having a play with a compact roster mode
Diffstat (limited to 'Swift/QtUI/Roster/RosterDelegate.cpp')
| -rw-r--r-- | Swift/QtUI/Roster/RosterDelegate.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index e40907a..7e6428b 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -1,78 +1,82 @@ /* * 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 <QApplication> #include <QPainter> #include <QColor> #include <QBrush> #include <QFontMetrics> #include <QPainterPath> #include <QPolygon> #include <qdebug.h> #include <QBitmap> #include "Swift/Controllers/Roster/ContactRosterItem.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" #include "QtTreeWidget.h" #include "RosterModel.h" namespace Swift { -RosterDelegate::RosterDelegate(QtTreeWidget* tree) { +RosterDelegate::RosterDelegate(QtTreeWidget* tree, bool compact) : compact_(compact) { tree_ = tree; groupDelegate_ = new GroupItemDelegate(); } RosterDelegate::~RosterDelegate() { delete groupDelegate_; } + +void RosterDelegate::setCompact(bool compact) { + compact_ = compact; +} QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); if (dynamic_cast<GroupRosterItem*>(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); + return common_.contactSizeHint(option, index, compact_); } void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); if (dynamic_cast<GroupRosterItem*>(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<QColor>(); 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, 0); + common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, 0, compact_); } } |
Swift