summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.cpp18
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.h8
-rw-r--r--Swift/QtUI/Roster/Roster.pro4
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp38
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.h3
5 files changed, 62 insertions, 9 deletions
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<QtTreeWidgetItem*> 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 <QPainter>
+#include <qdebug.h>
+
+#include "QtTreeWidgetItem.h"
namespace Swift {
QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
- return QSize(100,50);
+ QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(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<QtTreeWidgetItem*>(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<QIcon>().isNull()
+ ? index.data(AvatarRole).value<QIcon>()
+ : 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