summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-28 13:25:13 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-28 13:25:35 (GMT)
commita59af6c6daa72dd491189335cf2d255a788eb0f6 (patch)
treea09c9b67e6ba5ea0ac87ab06a0b9836d61571a3e /Swift/QtUI/ChatList
parent625d6a9f18c2377cdc3180e74b773ce3cbb2dcba (diff)
downloadswift-contrib-a59af6c6daa72dd491189335cf2d255a788eb0f6.zip
swift-contrib-a59af6c6daa72dd491189335cf2d255a788eb0f6.tar.bz2
Chat list in the gui (mostly non-functional).
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r--Swift/QtUI/ChatList/ChatListDelegate.cpp1
-rw-r--r--Swift/QtUI/ChatList/ChatListDelegate.h12
-rw-r--r--Swift/QtUI/ChatList/ChatListGroupItem.h21
-rw-r--r--Swift/QtUI/ChatList/ChatListItem.h15
-rw-r--r--Swift/QtUI/ChatList/ChatListMUCItem.h21
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.cpp64
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.h29
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.cpp38
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.h27
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindowFactory.cpp16
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindowFactory.h14
11 files changed, 258 insertions, 0 deletions
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp
new file mode 100644
index 0000000..6bfc9b3
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp
@@ -0,0 +1 @@
+#include "Swift/QtUI/ChatList/ChatListDelegate.h"
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.h b/Swift/QtUI/ChatList/ChatListDelegate.h
new file mode 100644
index 0000000..e2e5b6f
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListDelegate.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <QStyledItemDelegate>
+
+namespace Swift {
+
+ class ChatListDelegate : public QStyledItemDelegate {
+
+ };
+
+}
+
diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h
new file mode 100644
index 0000000..82c9616
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListGroupItem.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <QList>
+
+#include "Swift/QtUI/ChatList/ChatListItem.h"
+
+namespace Swift {
+ class ChatListGroupItem : public ChatListItem {
+ public:
+ ChatListGroupItem(const QString& name, ChatListGroupItem* parent) : ChatListItem(parent), name_(name) {};
+ void addItem(ChatListItem* item) {items_.push_back(item);};
+ void remove(int index) {items_.removeAt(index);};
+ int rowCount() {return items_.size();};
+ ChatListItem* item(int i) {return items_[i];};
+ int row(ChatListItem* item) {return items_.indexOf(item);};
+ QVariant data(int role) {return "Bob";};
+ private:
+ QString name_;
+ QList<ChatListItem*> items_;
+ };
+}
diff --git a/Swift/QtUI/ChatList/ChatListItem.h b/Swift/QtUI/ChatList/ChatListItem.h
new file mode 100644
index 0000000..f9e9fe7
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListItem.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <QVariant>
+
+namespace Swift {
+ class ChatListGroupItem;
+ class ChatListItem {
+ public:
+ ChatListItem(ChatListGroupItem* parent) {parent_ = parent;};
+ ChatListGroupItem* parent() {return parent_;};
+ virtual QVariant data(int role) = 0;
+ private:
+ ChatListGroupItem* parent_;
+ };
+}
diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.h b/Swift/QtUI/ChatList/ChatListMUCItem.h
new file mode 100644
index 0000000..53574b5
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListMUCItem.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <QList>
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/MUC/MUCBookmark.h"
+
+#include "Swift/QtUI/ChatList/ChatListItem.h"
+
+namespace Swift {
+ class ChatListMUCItem : public ChatListItem {
+ public:
+ ChatListMUCItem(boost::shared_ptr<MUCBookmark> bookmark, ChatListGroupItem* parent) : ChatListItem(parent), bookmark_(bookmark) {};
+ boost::shared_ptr<MUCBookmark> getBookmark() {return bookmark_;};
+ QVariant data(int role) {};
+ private:
+ boost::shared_ptr<MUCBookmark> bookmark_;
+ QList<ChatListItem*> items_;
+ };
+}
diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp
new file mode 100644
index 0000000..246d45d
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListModel.cpp
@@ -0,0 +1,64 @@
+#include "Swift/QtUI/ChatList/ChatListModel.h"
+
+#include "Swift/QtUI/ChatList/ChatListMUCItem.h"
+
+namespace Swift {
+
+ChatListModel::ChatListModel() {
+ root_ = new ChatListGroupItem("", NULL);
+ mucBookmarks_ = new ChatListGroupItem("MUC Bookmarks", root_);
+}
+
+void ChatListModel::addMUCBookmark(boost::shared_ptr<Swift::MUCBookmark> bookmark) {
+ emit layoutAboutToBeChanged();
+ mucBookmarks_->addItem(new ChatListMUCItem(bookmark, mucBookmarks_));
+ emit layoutChanged();
+}
+
+void ChatListModel::removeMUCBookmark(boost::shared_ptr<Swift::MUCBookmark> bookmark) {
+ for (int i = 0; i < mucBookmarks_->rowCount(); i++) {
+ ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
+ if (item->getBookmark() == bookmark) {
+ emit layoutAboutToBeChanged();
+ mucBookmarks_->remove(i);
+ emit layoutChanged();
+ break;
+ }
+ }
+}
+
+int ChatListModel::columnCount(const QModelIndex& /*parent*/) const {
+ return 1;
+}
+
+QVariant ChatListModel::data(const QModelIndex& index, int role) const {
+ return index.isValid() ? static_cast<ChatListItem*>(index.internalPointer())->data(role) : QVariant();
+}
+
+QModelIndex ChatListModel::index(int row, int column, const QModelIndex & parent) const {
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
+
+ ChatListGroupItem *parentItem = parent.isValid() ? static_cast<ChatListGroupItem*>(parent.internalPointer()) : root_;
+
+ return row < parentItem->rowCount() ? createIndex(row, column, parentItem->item(row)) : QModelIndex();
+}
+
+QModelIndex ChatListModel::parent(const QModelIndex& index) const {
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+ ChatListGroupItem* parent = static_cast<ChatListGroupItem*>(index.internalPointer())->parent();
+ return (parent == root_) ? QModelIndex() : createIndex(parent->parent()->row(parent), 0, parent);
+}
+
+int ChatListModel::rowCount(const QModelIndex& parentIndex) const {
+ ChatListGroupItem* parent = root_;
+ if (parentIndex.isValid()) {
+ parent = static_cast<ChatListGroupItem*>(parentIndex.internalPointer());
+ }
+ return parent ? parent->rowCount() : 0;
+}
+
+}
diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h
new file mode 100644
index 0000000..da65547
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListModel.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <QAbstractItemModel>
+#include <QList>
+
+#include "Swiften/MUC/MUCBookmark.h"
+
+#include "Swift/QtUI/ChatList/ChatListGroupItem.h"
+
+namespace Swift {
+ class ChatListModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ ChatListModel();
+ void addMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ void removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ 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:
+ ChatListGroupItem* mucBookmarks_;
+ ChatListGroupItem* root_;
+ };
+
+}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
new file mode 100644
index 0000000..b9d645d
--- /dev/null
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -0,0 +1,38 @@
+#include "Swift/QtUI/ChatList/QtChatListWindow.h"
+
+namespace Swift {
+
+QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, QWidget* parent) : QTreeView(parent) {
+ eventStream_ = uiEventStream;
+ model_ = new ChatListModel();
+ setModel(model_);
+ delegate_ = new ChatListDelegate();
+ setItemDelegate(delegate_);
+ setHeaderHidden(true);
+ #ifdef SWIFT_PLATFORM_MACOSX
+ setAlternatingRowColors(true);
+#endif
+ setAnimated(true);
+ setIndentation(0);
+ setRootIsDecorated(true);
+ connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
+}
+
+QtChatListWindow::~QtChatListWindow() {
+ delete model_;
+ delete delegate_;
+}
+
+void QtChatListWindow::handleItemActivated(const QModelIndex& item) {
+
+}
+
+void QtChatListWindow::addMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
+ model_->addMUCBookmark(bookmark);
+}
+
+void QtChatListWindow::removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
+ model_->removeMUCBookmark(bookmark);
+}
+
+}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h
new file mode 100644
index 0000000..b7fe6d2
--- /dev/null
+++ b/Swift/QtUI/ChatList/QtChatListWindow.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <QTreeView>
+
+#import "Swift/Controllers/UIInterfaces/ChatListWindow.h"
+#import "Swift/Controllers/UIEvents/UIEventStream.h"
+#import "Swift/QtUI/ChatList/ChatListModel.h"
+#import "Swift/QtUI/ChatList/ChatListDelegate.h"
+
+namespace Swift {
+
+ class QtChatListWindow : public QTreeView, public ChatListWindow {
+ Q_OBJECT
+ public:
+ QtChatListWindow(UIEventStream *uiEventStream, QWidget* parent = NULL);
+ virtual ~QtChatListWindow();
+ void addMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ void removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ private slots:
+ void handleItemActivated(const QModelIndex&);
+ private:
+ UIEventStream* eventStream_;
+ ChatListModel* model_;
+ ChatListDelegate* delegate_;
+ };
+
+}
diff --git a/Swift/QtUI/ChatList/QtChatListWindowFactory.cpp b/Swift/QtUI/ChatList/QtChatListWindowFactory.cpp
new file mode 100644
index 0000000..5540206
--- /dev/null
+++ b/Swift/QtUI/ChatList/QtChatListWindowFactory.cpp
@@ -0,0 +1,16 @@
+#include "Swift/QtUI/ChatList/QtChatListWindowFactory.h"
+
+#include "Swift/QtUI/QtMainWindowFactory.h"
+#include "Swift/QtUI/QtMainWindow.h"
+
+namespace Swift {
+
+QtChatListWindowFactory::QtChatListWindowFactory(QtMainWindowFactory* mainWindowFactory) {
+ mainWindowFactory_ = mainWindowFactory;
+}
+
+ChatListWindow* QtChatListWindowFactory::createWindow(UIEventStream* uiEventStream) {
+ return ((QtMainWindow*)mainWindowFactory_->getLastCreatedWindow())->getChatListWindow();
+}
+
+}
diff --git a/Swift/QtUI/ChatList/QtChatListWindowFactory.h b/Swift/QtUI/ChatList/QtChatListWindowFactory.h
new file mode 100644
index 0000000..47efe14
--- /dev/null
+++ b/Swift/QtUI/ChatList/QtChatListWindowFactory.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "Swift/Controllers/UIInterfaces/ChatListWindowFactory.h"
+
+namespace Swift {
+ class QtMainWindowFactory;
+ class QtChatListWindowFactory : public ChatListWindowFactory{
+ public:
+ QtChatListWindowFactory(QtMainWindowFactory* mainWindowFactory);
+ ChatListWindow* createWindow(UIEventStream* uiEventStream);
+ private:
+ QtMainWindowFactory* mainWindowFactory_;
+ };
+}