summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-08-01 17:21:06 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-08-01 17:21:06 (GMT)
commit9e3d7f4183f515a4d768be8166936340dee5a9b9 (patch)
tree1238b84a06e67b493b781259b80e770f5f3e2e41 /Swift/QtUI/Roster
parentc3b4fc7dcf8475e4dcf7b42b496e332df4a4f7b1 (diff)
downloadswift-contrib-9e3d7f4183f515a4d768be8166936340dee5a9b9.zip
swift-contrib-9e3d7f4183f515a4d768be8166936340dee5a9b9.tar.bz2
Roster now includes avatars.
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.cpp18
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.h3
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp8
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp2
4 files changed, 22 insertions, 9 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
index bbb5e98..aa1836c 100644
--- a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
@@ -5,20 +5,24 @@
namespace Swift {
-QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject() {
+QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject(), textColor_(0,0,0), backgroundColor_(255,255,255) {
parent_ = parentItem;
shown_ = true;
}
void QtTreeWidgetItem::setText(const String& text) {
displayName_ = P2QSTRING(text);
- statusText_ = displayName_ + " went away";
}
void QtTreeWidgetItem::setStatusText(const String& text) {
statusText_ = P2QSTRING(text);
}
+void QtTreeWidgetItem::setAvatarPath(const String& path) {
+ qDebug() << "Setting avatar to " << P2QSTRING(path);
+ avatar_ = QIcon(P2QSTRING(path));
+}
+
void QtTreeWidgetItem::setTextColor(unsigned long color) {
textColor_ = QColor(
((color & 0xFF0000)>>16),
@@ -48,7 +52,7 @@ void QtTreeWidgetItem::show() {
}
bool QtTreeWidgetItem::isShown() {
- return shown_;
+ return isContact() ? shown_ : shownChildren_.size() > 0;
}
QWidget* QtTreeWidgetItem::getCollapsedRosterWidget() {
@@ -88,7 +92,7 @@ void QtTreeWidgetItem::handleChanged() {
}
int QtTreeWidgetItem::rowCount() {
- qDebug() << "Returning size of " << children_.size() << " for item " << displayName_;
+ //qDebug() << "Returning size of " << children_.size() << " for item " << displayName_;
return shownChildren_.size();
}
@@ -101,14 +105,18 @@ int QtTreeWidgetItem::row() {
}
QtTreeWidgetItem* QtTreeWidgetItem::getItem(int row) {
- qDebug() << "Returning row " << row << " from item " << displayName_;
+ //qDebug() << "Returning row " << row << " from item " << displayName_;
return shownChildren_[row];
}
+
QVariant QtTreeWidgetItem::data(int role) {
switch (role) {
case Qt::DisplayRole: return displayName_;
+ case Qt::TextColorRole: return textColor_;
+ case Qt::BackgroundColorRole: return backgroundColor_;
case StatusTextRole: return statusText_;
+ case AvatarRole: return avatar_;
default: return QVariant();
}
}
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h
index e3bfff3..0a32940 100644
--- a/Swift/QtUI/Roster/QtTreeWidgetItem.h
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h
@@ -2,6 +2,7 @@
#define SWIFT_QtTreeWidgetItem_H
#include <QColor>
+#include <QVariant>
#include "Swiften/Base/String.h"
#include "Swiften/Roster/TreeWidgetFactory.h"
@@ -33,6 +34,7 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem {
QVariant data(int role);
QtTreeWidgetItem(QtTreeWidgetItem* parentItem);
void setText(const String& text);
+ void setAvatarPath(const String& path);
void setStatusText(const String& text);
void setTextColor(unsigned long color);
void setBackgroundColor(unsigned long color);
@@ -57,6 +59,7 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem {
QString statusText_;
QColor textColor_;
QColor backgroundColor_;
+ QVariant avatar_;
bool shown_;
};
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
index 2447e8f..b05bbb1 100644
--- a/Swift/QtUI/Roster/RosterDelegate.cpp
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
@@ -16,7 +16,7 @@ QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelI
}
//Doesn't work, yay! FIXME: why?
QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2);
- qDebug() << "Returning size" << size;
+ //qDebug() << "Returning size" << size;
return size;
}
@@ -26,7 +26,7 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
QStyledItemDelegate::paint(painter, option, index);
return;
}
- qDebug() << "painting" << index.data(Qt::DisplayRole).toString();
+ //qDebug() << "painting" << index.data(Qt::DisplayRole).toString();
painter->save();
//QStyledItemDelegate::paint(painter, option, index);
//initStyleOption(option, index);
@@ -48,8 +48,10 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
QRect textRegion(fullRegion.adjusted(avatarSize_ + margin_ * 2, 0, 0, 0));
QFontMetrics nameMetrics(nameFont);
- int nameHeight = nameMetrics.height() + margin_ * 2;
+ int nameHeight = nameMetrics.height() + margin_;
QRect nameRegion(textRegion.adjusted(0, margin_, 0, 0));
+ QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
+ painter->setPen(QPen(nameColor));
painter->drawText(nameRegion, Qt::AlignTop, index.data(Qt::DisplayRole).toString());
statusFont.setStyle(QFont::StyleItalic);
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index 147aa67..f322792 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -18,7 +18,7 @@ void RosterModel::setRoot(QtTreeWidgetItem* root) {
void RosterModel::handleItemChanged() {
//FIXME: This is just a lazy hack to cause the view to refresh until it works.
// Then I'll replace it with the proper implementation.
- printf("Changed\n");
+ //printf("Changed\n");
reset();
emit layoutChanged();
}