summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-05-06 08:00:44 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-05-06 10:49:49 (GMT)
commit081fc03556708447610e9697a57235fa191a4f0d (patch)
tree505c8cc9129d2b44968d183a180f0ccddaa08810 /Swift/QtUI/Roster/RosterDelegate.cpp
parent8c53236875d2ca77f1b463449918458f6b424ab1 (diff)
downloadswift-081fc03556708447610e9697a57235fa191a4f0d.zip
swift-081fc03556708447610e9697a57235fa191a4f0d.tar.bz2
Rewrite of large amounts of roster code.
Now keeps widgets out of Swiften, keeps sorting inside Swiften, and keeps track of presences to show the correct presence per roster item. Resolves: #316 Resolves: #81 Resolves: #239
Diffstat (limited to 'Swift/QtUI/Roster/RosterDelegate.cpp')
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
index 0c12d6e..b7ba71b 100644
--- a/Swift/QtUI/Roster/RosterDelegate.cpp
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
@@ -15,11 +15,16 @@
#include <QPolygon>
#include <qdebug.h>
-#include "QtTreeWidgetItem.h"
+#include "Swiften/Roster/ContactRosterItem.h"
+#include "Swiften/Roster/GroupRosterItem.h"
+
+#include "QtTreeWidget.h"
+#include "RosterModel.h"
namespace Swift {
-RosterDelegate::RosterDelegate() {
+RosterDelegate::RosterDelegate(QtTreeWidget* tree) {
+ tree_ = tree;
groupDelegate_ = new GroupItemDelegate();
}
@@ -28,16 +33,14 @@ RosterDelegate::~RosterDelegate() {
}
QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
- QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer());
- if (!item || !item->isContact()) {
+ 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 {
- Q_UNUSED(option);
- Q_UNUSED(index);
+QSize RosterDelegate::contactSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const {
int heightByAvatar = avatarSize_ + common_.verticalMargin * 2;
QFontMetrics nameMetrics(common_.nameFont);
QFontMetrics statusMetrics(common_.detailFont);
@@ -49,8 +52,8 @@ QSize RosterDelegate::contactSizeHint(const QStyleOptionViewItem& option, const
}
void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer());
- if (item && !item->isContact()) {
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ if (dynamic_cast<GroupRosterItem*>(item)) {
paintGroup(painter, option, index);
} else {
paintContact(painter, option, index);
@@ -58,15 +61,11 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
}
void RosterDelegate::paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
- QtTreeWidgetItem* item = index.isValid() ? static_cast<QtTreeWidgetItem*>(index.internalPointer()) : NULL;
- if (item) {
- groupDelegate_->paint(painter, option, index.data(Qt::DisplayRole).toString(), item->rowCount(), item->isExpanded());
+ 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 {
//qDebug() << "painting" << index.data(Qt::DisplayRole).toString();
painter->save();