From fed11bbc3bffd383e097ea63bb92442ce2daf6ed Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 26 Jul 2009 21:33:45 +0100 Subject: Now render an ugly default icon and default status text in the roster. diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp index 2c05053..e70983f 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp @@ -11,6 +11,11 @@ QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject() { void QtTreeWidgetItem::setText(const String& text) { displayName_ = P2QSTRING(text); + statusText_ = displayName_ + " went away"; +} + +void QtTreeWidgetItem::setStatusText(const String& text) { + statusText_ = P2QSTRING(text); } void QtTreeWidgetItem::setTextColor(unsigned long color) { @@ -86,10 +91,15 @@ QtTreeWidgetItem* QtTreeWidgetItem::getItem(int row) { } QVariant QtTreeWidgetItem::data(int role) { - if (role != Qt::DisplayRole) { - return QVariant(); + switch (role) { + case Qt::DisplayRole: return displayName_; + case StatusTextRole: return statusText_; + default: return QVariant(); } - qDebug() << "Returning name " << displayName_ << " for role " << role; - return displayName_; } + +bool QtTreeWidgetItem::isContact() { + return children_.size() == 0; +} + } \ No newline at end of file diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h index 017258b..2dac2fc 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.h +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h @@ -14,6 +14,11 @@ namespace Swift { + enum RosterRoles { + StatusTextRole = Qt::UserRole, + AvatarRole = Qt::UserRole + 1 + }; + class QtTreeWidget; class QtTreeWidgetItem : public QObject, public TreeWidgetItem { Q_OBJECT @@ -28,11 +33,13 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem { QVariant data(int role); QtTreeWidgetItem(QtTreeWidgetItem* parentItem); void setText(const String& text); + void setStatusText(const String& text); void setTextColor(unsigned long color); void setBackgroundColor(unsigned long color); void setExpanded(bool b); void hide(); void show(); + bool isContact(); QWidget* getCollapsedRosterWidget(); QWidget* getExpandedRosterWidget(); @@ -43,6 +50,7 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem { QList children_; QtTreeWidgetItem* parent_; QString displayName_; + QString statusText_; QColor textColor_; QColor backgroundColor_; }; diff --git a/Swift/QtUI/Roster/Roster.pro b/Swift/QtUI/Roster/Roster.pro index 086ef41..be0cff3 100644 --- a/Swift/QtUI/Roster/Roster.pro +++ b/Swift/QtUI/Roster/Roster.pro @@ -13,4 +13,6 @@ exists(../config.pri) { mac { DEFINES += SWIFT_PLATFORM_MACOSX -} \ No newline at end of file +} + +RESOURCES += ../Swift.qrc \ No newline at end of file diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index 925f66c..b6b9ded 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -1,15 +1,47 @@ #include "RosterDelegate.h" #include +#include + +#include "QtTreeWidgetItem.h" namespace Swift { QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { - return QSize(100,50); + QtTreeWidgetItem* item = static_cast(index.internalPointer()); + if (item && !item->isContact()) { + return QStyledItemDelegate::sizeHint(option, index); + } + //Doesn't work, yay! FIXME: why? + QSize size = (option.state & QStyle::State_Selected) ? QSize(200, 50) : QSize(100,50); + qDebug() << "Returning size" << size; + return size; } -void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex index) const { +void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + QtTreeWidgetItem* item = static_cast(index.internalPointer()); + if (item && !item->isContact()) { + QStyledItemDelegate::paint(painter, option, index); + return; + } + qDebug() << "painting" << index.data(Qt::DisplayRole).toString(); painter->save(); - QStyledItemDelegate::paint(painter, option, index); + //QStyledItemDelegate::paint(painter, option, index); + //initStyleOption(option, index); + QRect fullRegion(option.rect); + + QRect avatarRegion(QPoint(0, fullRegion.top()), QSize(32, 32)); + QIcon icon = index.data(AvatarRole).isValid() && !index.data(AvatarRole).value().isNull() + ? index.data(AvatarRole).value() + : QIcon(":/icons/avatar.png"); + icon.paint(painter, avatarRegion, Qt::AlignVCenter | Qt::AlignHCenter); + + QRect textRegion(fullRegion.adjusted(avatarRegion.width(), 0, 0, 0)); + QRect nameRegion(textRegion.adjusted(0,0,0,-25)); + painter->drawText(nameRegion, Qt::AlignVCenter, index.data(Qt::DisplayRole).toString()); + + QRect statusTextRegion(textRegion.adjusted(0, 25, 0, 0)); + painter->drawText(statusTextRegion, Qt::AlignVCenter, index.data(StatusTextRole).toString()); + painter->restore(); } diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h index 32bba80..a48b30f 100644 --- a/Swift/QtUI/Roster/RosterDelegate.h +++ b/Swift/QtUI/Roster/RosterDelegate.h @@ -4,7 +4,8 @@ namespace Swift { class RosterDelegate : public QStyledItemDelegate { + public: QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex index) const; + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; }; } \ No newline at end of file -- cgit v0.10.2-6-g49f6