summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-07-26 12:39:50 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-07-26 12:39:50 (GMT)
commita28d92f3458218d6effbfdd9a42bf8fbe8b8aa72 (patch)
treef666c221dcc899704bb80f67afe383e58b780669 /Swift/QtUI/Roster
parentc4660f404c9a0dbf1c00a20baacfc738d93eaff5 (diff)
downloadswift-contrib-a28d92f3458218d6effbfdd9a42bf8fbe8b8aa72.zip
swift-contrib-a28d92f3458218d6effbfdd9a42bf8fbe8b8aa72.tar.bz2
Begin to assage Swift model into Qt Model/View.
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp37
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h32
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetFactory.cpp0
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetFactory.h41
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.cpp17
-rw-r--r--Swift/QtUI/Roster/QtTreeWidgetItem.h65
-rw-r--r--Swift/QtUI/Roster/Roster.pri12
-rw-r--r--Swift/QtUI/Roster/Roster.pro12
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp0
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.h0
-rw-r--r--Swift/QtUI/Roster/RosterItem.cpp28
-rw-r--r--Swift/QtUI/Roster/RosterItem.h20
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp56
-rw-r--r--Swift/QtUI/Roster/RosterModel.h22
-rw-r--r--Swift/QtUI/Roster/main.cpp31
15 files changed, 373 insertions, 0 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
new file mode 100644
index 0000000..d40169f
--- /dev/null
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -0,0 +1,37 @@
+#include "Roster/QtTreeWidget.h"
+
+#include "Swiften/Base/Platform.h"
+#include "Swiften/Roster/OpenChatRosterAction.h"
+
+namespace Swift {
+
+QtTreeWidget::QtTreeWidget(QWidget* parent) : QTreeView(parent), RosterItem(NULL) {
+ model_ = new RosterModel(this);
+ setModel(model_);
+ //setWindowTitle("A roster");
+ //show();
+ setHeaderHidden(true);
+#ifdef SWIFT_PLATFORM_MACOSX
+ setAlternatingRowColors(true);
+#endif
+ setAnimated(true);
+ setIndentation(0);
+ setRootIsDecorated(true);
+ connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(handleItemActivated(QTreeWidgetItem*, int)));
+}
+
+// void QtTreeWidget::handleItemActivated(QTreeWidgetItem* item, int column) {
+// QtTreeWidgetItem* qtItem = dynamic_cast<QtTreeWidgetItem*>(item);
+// if (qtItem) {
+// qtItem->performUserAction(boost::shared_ptr<UserRosterAction>(new OpenChatRosterAction()));
+// }
+// }
+
+void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const {
+}
+
+void QtTreeWidget::show() {
+ QWidget::show();
+}
+
+}
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
new file mode 100644
index 0000000..f246e83
--- /dev/null
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -0,0 +1,32 @@
+#ifndef SWIFT_QtTreeWidget_H
+#define SWIFT_QtTreeWidget_H
+
+#include <QTreeView>
+
+#include "Swiften/Roster/TreeWidgetFactory.h"
+#include "Swiften/Roster/TreeWidget.h"
+#include "Swiften/Roster/TreeWidgetItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidget.h"
+#include "Swift/QtUI/Roster/RosterModel.h"
+#include "Swift/QtUI/Roster/RosterItem.h"
+
+namespace Swift {
+
+class QtTreeWidget : public QTreeView, public TreeWidget, public RosterItem {
+ Q_OBJECT
+ public:
+ QtTreeWidget(QWidget* parent = 0);
+ void show();
+ //private slots:
+ // void handleItemActivated(QTreeWidgetItem*, int);
+
+ private:
+ void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
+ RosterModel* model_;
+
+};
+
+}
+#endif
+
diff --git a/Swift/QtUI/Roster/QtTreeWidgetFactory.cpp b/Swift/QtUI/Roster/QtTreeWidgetFactory.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Swift/QtUI/Roster/QtTreeWidgetFactory.cpp
diff --git a/Swift/QtUI/Roster/QtTreeWidgetFactory.h b/Swift/QtUI/Roster/QtTreeWidgetFactory.h
new file mode 100644
index 0000000..353f697
--- /dev/null
+++ b/Swift/QtUI/Roster/QtTreeWidgetFactory.h
@@ -0,0 +1,41 @@
+#ifndef SWIFT_QtTreeWidgetFactory_H
+#define SWIFT_QtTreeWidgetFactory_H
+
+#include "Swiften/Roster/TreeWidgetFactory.h"
+#include "Swiften/Roster/TreeWidget.h"
+#include "Swiften/Roster/TreeWidgetItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidget.h"
+
+namespace Swift {
+
+class QtTreeWidgetFactory : public TreeWidgetFactory {
+ public:
+ QtTreeWidgetFactory() {
+ }
+
+ TreeWidget* createTreeWidget() {
+ return new QtTreeWidget();
+ }
+
+ TreeWidgetItem* createTreeWidgetItem(TreeWidgetItem* item) {
+ QtTreeWidgetItem* qtItem = dynamic_cast<QtTreeWidgetItem*>(item);
+ assert(qtItem);
+ QtTreeWidgetItem* newItem = new QtTreeWidgetItem(qtItem);
+ qtItem->addChild(newItem);
+ return newItem;
+ }
+
+ TreeWidgetItem* createTreeWidgetItem(TreeWidget* item) {
+ QtTreeWidget* qtItem = dynamic_cast<QtTreeWidget*>(item);
+ assert(qtItem);
+ QtTreeWidgetItem* newItem = new QtTreeWidgetItem(qtItem);
+ //qtItem->setItemWidget(newItem, 0, newItem->getCollapsedRosterWidget());
+ qtItem->addChild(newItem);
+ return newItem;
+ }
+};
+
+}
+#endif
+
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
new file mode 100644
index 0000000..f65c3bf
--- /dev/null
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp
@@ -0,0 +1,17 @@
+#include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidget.h"
+namespace Swift {
+
+QWidget* QtTreeWidgetItem::getCollapsedRosterWidget() {
+ QWidget* widget = new QWidget();
+
+ return widget;
+}
+
+QWidget* QtTreeWidgetItem::getExpandedRosterWidget() {
+ QWidget* widget = new QWidget();
+
+ return widget;
+}
+
+} \ No newline at end of file
diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h
new file mode 100644
index 0000000..c35a840
--- /dev/null
+++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h
@@ -0,0 +1,65 @@
+#ifndef SWIFT_QtTreeWidgetItem_H
+#define SWIFT_QtTreeWidgetItem_H
+
+#include <QColor>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Roster/TreeWidgetFactory.h"
+#include "Swiften/Roster/TreeWidget.h"
+#include "Swiften/Roster/TreeWidgetItem.h"
+#include "Swift/QtUI/Roster/QtTreeWidgetItem.h"
+#include "Swift/QtUI/Roster/RosterItem.h"
+
+
+#include "Swift/QtUI/QtSwiftUtil.h"
+
+
+namespace Swift {
+class QtTreeWidget;
+class QtTreeWidgetItem : public TreeWidgetItem, public RosterItem {
+ public:
+ QtTreeWidgetItem(RosterItem* parentItem) : RosterItem(parentItem) {
+
+ }
+
+ void setText(const String& text) {
+ displayName_ = P2QSTRING(text);
+ // QTreeWidgetItem::setText(0, P2QSTRING(text));
+ }
+
+ void setTextColor(unsigned long color) {
+ // QTreeWidgetItem::setTextColor(0, QColor(
+ // ((color & 0xFF0000)>>16),
+ // ((color & 0xFF00)>>8),
+ // (color & 0xFF)));
+ }
+
+ void setBackgroundColor(unsigned long color) {
+ // QTreeWidgetItem::setBackgroundColor(0, QColor(
+ // ((color & 0xFF0000)>>16),
+ // ((color & 0xFF00)>>8),
+ // (color & 0xFF)));
+ }
+
+ void setExpanded(bool b) {
+ //treeWidget()->setItemExpanded(this, b);
+ }
+
+ void hide() {
+ //setHidden(true);
+ }
+
+ void show() {
+ //setHidden(false);
+ }
+
+ QWidget* getCollapsedRosterWidget();
+ QWidget* getExpandedRosterWidget();
+
+ private:
+ QString displayName_;
+};
+
+}
+#endif
+
diff --git a/Swift/QtUI/Roster/Roster.pri b/Swift/QtUI/Roster/Roster.pri
new file mode 100644
index 0000000..56ff472
--- /dev/null
+++ b/Swift/QtUI/Roster/Roster.pri
@@ -0,0 +1,12 @@
+SOURCES += $$PWD/RosterDelegate.cpp \
+ $$PWD/RosterItem.cpp \
+ $$PWD/RosterModel.cpp \
+ $$PWD/QtTreeWidget.cpp \
+ $$PWD/QtTreeWidgetItem.cpp
+
+HEADERS += $$PWD/RosterDelegate.h \
+ $$PWD/RosterItem.h \
+ $$PWD/RosterModel.h \
+ $$PWD/QtTreeWidget.h \
+ $$PWD/QtTreeWidgetFactory.h \
+ $$PWD/QtTreeWidgetItem.h
diff --git a/Swift/QtUI/Roster/Roster.pro b/Swift/QtUI/Roster/Roster.pro
new file mode 100644
index 0000000..c829d5c
--- /dev/null
+++ b/Swift/QtUI/Roster/Roster.pro
@@ -0,0 +1,12 @@
+include(Roster.pri)
+SOURCES += main.cpp
+
+DEPENDPATH += ../. ../../.. ../../../3rdParty/Boost
+INCLUDEPATH += ../. ../../.. ../../../3rdParty/Boost
+
+DEFINES += BOOST_SIGNALS_NAMESPACE=bsignals BOOST_ALL_NO_LIB
+
+exists(../config.pri) {
+ LIBS += ../../Controllers/Controllers.a ../../../Swiften/Swiften.a
+ include(../config.pri)
+} \ No newline at end of file
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterDelegate.h
diff --git a/Swift/QtUI/Roster/RosterItem.cpp b/Swift/QtUI/Roster/RosterItem.cpp
new file mode 100644
index 0000000..14b4525
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterItem.cpp
@@ -0,0 +1,28 @@
+#include "RosterItem.h"
+
+namespace Swift {
+
+RosterItem::RosterItem(RosterItem* parent) {
+ parent_ = parent;
+}
+
+RosterItem* RosterItem::getParentItem() {
+ return parent_;
+}
+
+void RosterItem::addChild(RosterItem* child) {
+ children_.append(child);
+}
+
+int RosterItem::rowCount() {
+ return children_.size();
+}
+
+int RosterItem::rowOf(RosterItem* item) {
+ return children_.indexOf(item);;
+}
+
+RosterItem* RosterItem::getItem(int row) {
+ return children_[row];
+}
+} \ No newline at end of file
diff --git a/Swift/QtUI/Roster/RosterItem.h b/Swift/QtUI/Roster/RosterItem.h
new file mode 100644
index 0000000..f7cd804
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterItem.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include <QList>
+
+namespace Swift {
+ class RosterItem {
+ public:
+ RosterItem(RosterItem* parent);
+ ~RosterItem();
+ void addChild(RosterItem* child);
+ RosterItem* getParentItem();
+ int rowCount();
+ int rowOf(RosterItem* item);
+ RosterItem* getItem(int row);
+ private:
+ QList<RosterItem*> children_;
+ RosterItem* parent_;
+ };
+
+} \ No newline at end of file
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
new file mode 100644
index 0000000..2c9a2cc
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -0,0 +1,56 @@
+#include "RosterModel.h"
+
+namespace Swift {
+
+RosterModel::RosterModel(RosterItem* tree) {
+ tree_ = tree;
+}
+
+RosterModel::~RosterModel() {
+
+}
+
+int RosterModel::columnCount(const QModelIndex& parent) const {
+ Q_UNUSED(parent);
+ return 1;
+}
+
+QVariant RosterModel::data(const QModelIndex& index, int role) const {
+ if (!index.isValid()) {
+ return QVariant();
+ }
+ return QVariant("bob");
+}
+
+QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) const {
+ RosterItem* parentItem = parent.isValid() ? static_cast<RosterItem*>(parent.internalPointer()) : tree_;
+ Q_ASSERT(parentItem);
+
+ return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex();
+}
+
+QModelIndex RosterModel::parent(const QModelIndex& index) const {
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+
+ RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
+ Q_ASSERT(item);
+
+ RosterItem* parentItem = item->getParentItem();
+ return parentItem == tree_ ? QModelIndex() : createIndex(parentItem->getParentItem()->rowOf(parentItem), 0, parentItem);
+
+}
+
+int RosterModel::rowCount(const QModelIndex& parent) const {
+ if (!parent.isValid()) {
+ return 0;
+ }
+
+ RosterItem* item = static_cast<RosterItem*>(parent.internalPointer());
+ Q_ASSERT(item);
+
+ return item->rowCount();
+}
+
+} \ No newline at end of file
diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h
new file mode 100644
index 0000000..a958f0d
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterModel.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Swift/QtUI/Roster/RosterItem.h"
+
+#include <QAbstractItemModel>
+#include <QList>
+
+namespace Swift {
+class RosterModel : public QAbstractItemModel {
+public:
+ RosterModel(RosterItem* tree);
+ ~RosterModel();
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+private:
+ RosterItem* tree_;
+};
+
+} \ No newline at end of file
diff --git a/Swift/QtUI/Roster/main.cpp b/Swift/QtUI/Roster/main.cpp
new file mode 100644
index 0000000..f3623ac
--- /dev/null
+++ b/Swift/QtUI/Roster/main.cpp
@@ -0,0 +1,31 @@
+#include <QtGui>
+#include "QtTreeWidget.h"
+#include "QtTreeWidgetFactory.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ //Swift::RosterModel model;
+
+ //QTreeView view;
+ //view.setModel(&model);
+ //view.setWindowTitle("A roster");
+ //view.show();
+
+ Swift::QtTreeWidgetFactory treeWidgetFactory;
+ Swift::QtTreeWidget* tree = dynamic_cast<Swift::QtTreeWidget*>(treeWidgetFactory.createTreeWidget());
+ Swift::QtTreeWidgetItem* group = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(tree));
+ group->setText("People");
+ group->setBackgroundColor(0xBBBBBB);
+ Swift::QtTreeWidgetItem* item1 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ Swift::QtTreeWidgetItem* item2 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ Swift::QtTreeWidgetItem* item3 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ Swift::QtTreeWidgetItem* item4 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group));
+ item1->setText("Remko");
+ item2->setText("Kevin");
+ item3->setText("Cath");
+ item4->setText("Kim");
+ tree->show();
+ return app.exec();
+} \ No newline at end of file