summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.cpp55
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.h12
2 files changed, 67 insertions, 0 deletions
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
index 793d89a..7d307f9 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.cpp
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -5,8 +5,17 @@
*/
#include "Swift/QtUI/ChatList/QtChatListWindow.h"
+
+#include <QMenu>
+#include <QContextMenuEvent>
+
#include "Swift/QtUI/ChatList/ChatListMUCItem.h"
+#include "Swift/QtUI/QtAddBookmarkWindow.h"
+#include "Swift/QtUI/QtEditBookmarkWindow.h"
#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h"
+#include "Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h"
+#include "Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h"
+#include "Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h"
namespace Swift {
@@ -23,12 +32,25 @@ QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, QWidget* parent
setAnimated(true);
setIndentation(0);
setRootIsDecorated(true);
+ setupContextMenus();
connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
}
QtChatListWindow::~QtChatListWindow() {
delete model_;
delete delegate_;
+ delete mucMenu_;
+ delete emptyMenu_;
+}
+
+void QtChatListWindow::setupContextMenus() {
+ mucMenu_ = new QMenu();
+ mucMenu_->addAction("Add New Bookmark", this, SLOT(handleAddBookmark()));
+ mucMenu_->addAction("Edit Bookmark", this, SLOT(handleEditBookmark()));
+ mucMenu_->addAction("Remove Bookmark", this, SLOT(handleRemoveBookmark()));
+ emptyMenu_ = new QMenu();
+ emptyMenu_->addAction("Add New Bookmark", this, SLOT(handleAddBookmark()));
+
}
void QtChatListWindow::handleItemActivated(const QModelIndex& index) {
@@ -48,4 +70,37 @@ void QtChatListWindow::removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark
model_->removeMUCBookmark(bookmark);
}
+void QtChatListWindow::handleRemoveBookmark() {
+ ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_);
+ if (!mucItem) return;
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveMUCBookmarkUIEvent(mucItem->getBookmark())));
+}
+
+void QtChatListWindow::handleAddBookmark() {
+ (new QtAddBookmarkWindow(eventStream_))->show();
+}
+
+
+void QtChatListWindow::handleEditBookmark() {
+ ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_);
+ if (!mucItem) return;
+ QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark());
+ window->show();
+}
+
+
+void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {
+ QModelIndex index = indexAt(event->pos());
+ ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL;
+ contextMenuItem_ = baseItem;
+ if (!baseItem) {
+ emptyMenu_->exec(QCursor::pos());
+ return;
+ }
+ ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem);
+ if (mucItem) {
+ mucMenu_->exec(QCursor::pos());
+ }
+}
+
}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h
index af4d3bf..2055e6b 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.h
+++ b/Swift/QtUI/ChatList/QtChatListWindow.h
@@ -12,6 +12,7 @@
#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "Swift/QtUI/ChatList/ChatListModel.h"
#include "Swift/QtUI/ChatList/ChatListDelegate.h"
+#include "Swift/QtUI/ContextMenus/QtContextMenu.h"
namespace Swift {
@@ -24,10 +25,21 @@ namespace Swift {
void removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
private slots:
void handleItemActivated(const QModelIndex&);
+ void handleAddBookmark();
+ void handleEditBookmark();
+ void handleRemoveBookmark();
+
+ protected:
+ void contextMenuEvent(QContextMenuEvent* event);
private:
+ void setupContextMenus();
UIEventStream* eventStream_;
ChatListModel* model_;
ChatListDelegate* delegate_;
+ QtContextMenu* contextMenu_;
+ QMenu* mucMenu_;
+ QMenu* emptyMenu_;
+ ChatListItem* contextMenuItem_;
};
}