summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-08-09 07:41:27 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-08-09 07:41:27 (GMT)
commit89034baf34d913daae0d53d0468885c603762d8a (patch)
tree8a94b6119eae3e1f6970ee53f57118fcbd116af5 /Swift/QtUI/Roster/QtTreeWidgetItem.cpp
parent6f4fa16b1ddb0633771423a8e8d9520864ffb95d (diff)
parentf948f047401021f3afc8a015991fc81e7d69d6ce (diff)
downloadswift-contrib-89034baf34d913daae0d53d0468885c603762d8a.zip
swift-contrib-89034baf34d913daae0d53d0468885c603762d8a.tar.bz2
Replace dummy roster with Qt Model/View driven one.
Merge branch 'roster' * roster: Group expandedness in roster persists between roster changes. Plumbing in place for roster group expansion. \nDoesn't work. Conditional includes to get the QtSoundPlayer to compile on Ubuntu. Roster clicks now open chats again. Roster now includes avatars. Resize avatars to 32pix in Roster, change alignments to be relative, do item hiding. Sort out the alignments in the roster. Render status text italicised, and selection colours. Now render an ugly default icon and default status text in the roster. Use a (boring) delegate for roster rendering. Clear down some of the cruft from RosterItem. Removing RosterItem and including in QtTreeWidgetItem. Removing the dummy title from the roster. The new roster now renders (badly) the contents. Begin to assage Swift model into Qt Model/View.
Diffstat (limited to 'Swift/QtUI/Roster/QtTreeWidgetItem.cpp')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
new file mode 100644
index 0000000..1b77b26
--- /dev/null
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
@@ -0,0 +1,136 @@
+#include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidget.h"
+
+#include <qdebug.h>
+
+namespace Swift {
+
+QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject(), textColor_(0,0,0), backgroundColor_(255,255,255) {
+ parent_ = parentItem;
+ shown_ = true;
+ expanded_ = true;
+}
+
+void QtTreeWidgetItem::setText(const String& text) {
+ displayName_ = P2QSTRING(text);
+}
+
+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),
+ ((color & 0xFF00)>>8),
+ (color & 0xFF));
+}
+
+void QtTreeWidgetItem::setBackgroundColor(unsigned long color) {
+ backgroundColor_ = QColor(
+ ((color & 0xFF0000)>>16),
+ ((color & 0xFF00)>>8),
+ (color & 0xFF));
+}
+
+void QtTreeWidgetItem::setExpanded(bool b) {
+ expanded_ = true;
+ emit changed(this);
+}
+
+void QtTreeWidgetItem::hide() {
+ shown_ = false;
+ emit changed(this);
+}
+
+void QtTreeWidgetItem::show() {
+ shown_ = true;
+ emit changed(this);
+}
+
+bool QtTreeWidgetItem::isShown() {
+ return isContact() ? shown_ : shownChildren_.size() > 0;
+}
+
+QWidget* QtTreeWidgetItem::getCollapsedRosterWidget() {
+ QWidget* widget = new QWidget();
+
+ return widget;
+}
+
+QWidget* QtTreeWidgetItem::getExpandedRosterWidget() {
+ QWidget* widget = new QWidget();
+
+ return widget;
+}
+
+QtTreeWidgetItem::~QtTreeWidgetItem() {
+ qDeleteAll(children_);
+}
+
+QtTreeWidgetItem* QtTreeWidgetItem::getParentItem() {
+ return parent_;
+}
+
+void QtTreeWidgetItem::addChild(QtTreeWidgetItem* child) {
+ children_.append(child);
+ connect(child, SIGNAL(changed(QtTreeWidgetItem*)), this, SLOT(handleChanged(QtTreeWidgetItem*)));
+ handleChanged(child);
+}
+
+void QtTreeWidgetItem::handleChanged(QtTreeWidgetItem* child) {
+ shownChildren_.clear();
+ for (int i = 0; i < children_.size(); i++) {
+ if (children_[i]->isShown()) {
+ shownChildren_.append(children_[i]);
+ }
+ }
+ emit changed(child);
+}
+
+int QtTreeWidgetItem::rowCount() {
+ //qDebug() << "Returning size of " << children_.size() << " for item " << displayName_;
+ return shownChildren_.size();
+}
+
+int QtTreeWidgetItem::rowOf(QtTreeWidgetItem* item) {
+ return shownChildren_.indexOf(item);
+}
+
+int QtTreeWidgetItem::row() {
+ return parent_ ? parent_->rowOf(this) : 0;
+}
+
+QtTreeWidgetItem* QtTreeWidgetItem::getItem(int row) {
+ //qDebug() << "Returning row " << row << " from item " << displayName_;
+ Q_ASSERT(row >= 0);
+ Q_ASSERT(row < rowCount());
+ 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();
+ }
+}
+
+bool QtTreeWidgetItem::isContact() {
+ return children_.size() == 0;
+}
+
+bool QtTreeWidgetItem::isExpanded() {
+ return expanded_;
+}
+
+} \ No newline at end of file