diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-03-28 13:36:48 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-03-28 13:36:48 (GMT) |
commit | dae28dd45e43fc6e6ef2ec4c6c65d5d736ed86f8 (patch) | |
tree | f01fe3ff891a815b7c7db511ddbabcc67f916445 /Swift/QtUI | |
parent | a7d213975040a1130ac136d61a055c5b6f5d41fa (diff) | |
parent | a59af6c6daa72dd491189335cf2d255a788eb0f6 (diff) | |
download | swift-contrib-dae28dd45e43fc6e6ef2ec4c6c65d5d736ed86f8.zip swift-contrib-dae28dd45e43fc6e6ef2ec4c6c65d5d736ed86f8.tar.bz2 |
Merge commit 'origin/master'
Conflicts:
BuildTools
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/ChatList/ChatListDelegate.cpp | 1 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListDelegate.h | 12 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListGroupItem.h | 21 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListItem.h | 15 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListMUCItem.h | 21 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.cpp | 64 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.h | 29 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 38 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.h | 27 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindowFactory.cpp | 16 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindowFactory.h | 14 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 9 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtSwift.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtSwift.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 4 |
16 files changed, 279 insertions, 2 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_; + }; +} diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 5a6c620..b8d9a5c 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -52,8 +52,11 @@ QtMainWindow::QtMainWindow(UIEventStream* uiEventStream, QtTreeWidgetFactory *tr eventWindow_ = new QtEventWindow(uiEventStream_); connect(eventWindow_, SIGNAL(onNewEventCountUpdated(int)), this, SLOT(handleEventCountUpdated(int))); + chatListWindow_ = new QtChatListWindow(uiEventStream_); + tabs_->addTab(eventWindow_, "Events"); - + tabs_->addTab(chatListWindow_, "Chats"); + this->setLayout(mainLayout); QMenu* viewMenu = new QMenu(tr("View"), this); @@ -81,6 +84,10 @@ QtEventWindow* QtMainWindow::getEventWindow() { return eventWindow_; } +QtChatListWindow* QtMainWindow::getChatListWindow() { + return chatListWindow_; +} + void QtMainWindow::handleEventCountUpdated(int count) { QColor eventTabColor = (count == 0) ? QColor(-1, -1, -1) : QColor(255, 0, 0); // invalid resets to default int eventIndex = 1; diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index 940930e..ac3e444 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -6,6 +6,7 @@ #include "Swift/Controllers/MainWindow.h" #include "Swift/QtUI/QtRosterHeader.h" #include "Swift/QtUI/EventViewer/QtEventWindow.h" +#include "Swift/QtUI/ChatList/QtChatListWindow.h" #include <vector> @@ -35,6 +36,7 @@ namespace Swift { void setMyStatusText(const String& status); void setMyStatusType(const StatusShow::Type type); QtEventWindow* getEventWindow(); + QtChatListWindow* getChatListWindow(); private slots: void handleStatusChanged(StatusShow::Type showType, const QString &statusMessage); void handleShowOfflineToggled(bool); @@ -56,6 +58,7 @@ namespace Swift { QWidget* contactsTabWidget_; QWidget* eventsTabWidget_; QtEventWindow* eventWindow_; + QtChatListWindow* chatListWindow_; UIEventStream* uiEventStream_; }; } diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 6c9dc11..1c60c12 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -9,6 +9,7 @@ #include "QtSystemTray.h" #include "QtSoundPlayer.h" #include "QtXMLConsoleWidgetFactory.h" +#include "ChatList/QtChatListWindowFactory.h" #include "EventViewer/QtEventWindowFactory.h" #include <boost/bind.hpp> #include <QSplitter> @@ -54,11 +55,12 @@ QtSwift::QtSwift(bool netbookMode) : autoUpdater_(NULL) { rosterWindowFactory_ = new QtMainWindowFactory(treeWidgetFactory_); eventWindowFactory_ = new QtEventWindowFactory(rosterWindowFactory_); xmlConsoleWidgetFactory_ = new QtXMLConsoleWidgetFactory(tabs_); + chatListWindowFactory_ = new QtChatListWindowFactory(rosterWindowFactory_); soundPlayer_ = new QtSoundPlayer(); if (splitter_) { splitter_->show(); } - mainController_ = new MainController(chatWindowFactory_, rosterWindowFactory_, loginWindowFactory_, treeWidgetFactory_, eventWindowFactory_, settings_, application_, systemTray_, soundPlayer_, xmlConsoleWidgetFactory_); + mainController_ = new MainController(chatWindowFactory_, rosterWindowFactory_, loginWindowFactory_, treeWidgetFactory_, eventWindowFactory_, settings_, application_, systemTray_, soundPlayer_, xmlConsoleWidgetFactory_, chatListWindowFactory_); PlatformAutoUpdaterFactory autoUpdaterFactory; if (autoUpdaterFactory.isSupported()) { @@ -82,6 +84,7 @@ QtSwift::~QtSwift() { delete tabs_; delete xmlConsoleWidgetFactory_; delete eventWindowFactory_; + delete chatListWindowFactory_; } } diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index 5a3f9b3..7471bc2 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -22,6 +22,7 @@ namespace Swift { class QtSystemTray; class QtSoundPlayer; class QtEventWindowFactory; + class QtChatListWindowFactory; class QtSwift : public QObject { Q_OBJECT @@ -32,6 +33,7 @@ namespace Swift { MainController *mainController_; QtTreeWidgetFactory *treeWidgetFactory_; QtChatWindowFactory *chatWindowFactory_; + QtChatListWindowFactory *chatListWindowFactory_; QtMainWindowFactory *rosterWindowFactory_; QtLoginWindowFactory *loginWindowFactory_; QtXMLConsoleWidgetFactory* xmlConsoleWidgetFactory_; diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index e6a62aa..d2e6c37 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -84,6 +84,10 @@ sources = [ "EventViewer/QtEventWindowFactory.cpp", "EventViewer/QtEventWindow.cpp", "EventViewer/QtEvent.cpp", + "ChatList/QtChatListWindow.cpp", + "ChatList/QtChatListWindowFactory.cpp", + "ChatList/ChatListModel.cpp", + "ChatList/ChatListDelegate.cpp", "QtSubscriptionRequestWindow.cpp", "QtRosterHeader.cpp", "qrc_DefaultTheme.cc", |