diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-02-06 22:50:30 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-02-07 15:22:48 (GMT) |
commit | afcfa9dd33cfb5e36edf7d8148a7f8b24c976741 (patch) | |
tree | c16d40dbb089a9bcf70fafc2d50def34a9984e58 /Swift/QtUI/Roster | |
parent | 90a511ed523cfaf500dd27316b12e128e0c70ce3 (diff) | |
download | swift-contrib-afcfa9dd33cfb5e36edf7d8148a7f8b24c976741.zip swift-contrib-afcfa9dd33cfb5e36edf7d8148a7f8b24c976741.tar.bz2 |
Reworking contact editing.
Collapsed rename, group edit, and remove into one dialog.
Moved contact editing logic to controllers.
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 43 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.h | 3 |
2 files changed, 29 insertions, 17 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index cecb557..3c0b303 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -6,15 +6,19 @@ #include "Roster/QtTreeWidget.h" +#include <QMenu> +#include <QContextMenuEvent> +#include <QInputDialog> +#include <boost/smart_ptr/make_shared.hpp> + #include "Swiften/Base/Platform.h" #include "Swiften/Roster/ContactRosterItem.h" #include "Swiften/Roster/GroupRosterItem.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" - -#include <qdebug.h> -#include <QMenu> -#include <QContextMenuEvent> +#include "Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h" +#include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h" +#include "QtSwiftUtil.h" namespace Swift { @@ -25,7 +29,6 @@ QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeV delegate_ = new RosterDelegate(this); setItemDelegate(delegate_); setHeaderHidden(true); - contextMenu_ = NULL; #ifdef SWIFT_PLATFORM_MACOSX setAlternatingRowColors(true); #endif @@ -52,10 +55,6 @@ void QtTreeWidget::setRosterModel(Roster* roster) { expandAll(); } -void QtTreeWidget::setContextMenu(QtContextMenu* contextMenu) { - contextMenu_ = contextMenu; -} - QtTreeWidgetItem* QtTreeWidget::getRoot() { return treeRoot_; } @@ -77,13 +76,29 @@ void QtTreeWidget::handleItemActivated(const QModelIndex& index) { } void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) { - if (!contextMenu_) { + QModelIndex index = indexAt(event->pos()); + if (!index.isValid()) { return; } - QModelIndex index = indexAt(event->pos()); - RosterItem* item = index.isValid() ? static_cast<RosterItem*>(index.internalPointer()) : NULL; - if (item) { - contextMenu_->show(item); + RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); + QMenu contextMenu; + if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { + QAction* editContact = contextMenu.addAction("Edit"); + QAction* result = contextMenu.exec(event->globalPos()); + if (result == editContact) { + eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); + } + } + else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { + QAction* renameGroup = contextMenu.addAction("Rename"); + QAction* result = contextMenu.exec(event->globalPos()); + if (result == renameGroup) { + bool ok; + QString newName = QInputDialog::getText(NULL, "Rename group", "New name for " + P2QSTRING(group->getDisplayName()), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok); + if (ok) { + eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName))); + } + } } } diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h index 838c453..ff11567 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.h +++ b/Swift/QtUI/Roster/QtTreeWidget.h @@ -12,7 +12,6 @@ #include "Swift/QtUI/Roster/QtTreeWidget.h" #include "Swift/QtUI/Roster/RosterModel.h" #include "Swift/QtUI/Roster/RosterDelegate.h" -#include "Swift/QtUI/ContextMenus/QtContextMenu.h" namespace Swift { class UIEventStream; @@ -24,7 +23,6 @@ class QtTreeWidget : public QTreeView{ ~QtTreeWidget(); void show(); QtTreeWidgetItem* getRoot(); - void setContextMenu(QtContextMenu* contextMenu); void setRosterModel(Roster* roster); Roster* getRoster() {return roster_;} private slots: @@ -42,7 +40,6 @@ class QtTreeWidget : public QTreeView{ Roster* roster_; RosterDelegate* delegate_; QtTreeWidgetItem* treeRoot_; - QtContextMenu* contextMenu_; UIEventStream* eventStream_; }; |