diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindow.h | 7 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtOccupantListWidget.cpp | 59 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtOccupantListWidget.h | 23 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtRosterWidget.cpp | 100 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtRosterWidget.h | 30 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 83 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.h | 20 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 2 |
10 files changed, 225 insertions, 105 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index d7ffc65..a52d2de 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -65,19 +65,18 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt alertWidget_->hide(); logRosterSplitter_ = new QSplitter(this); logRosterSplitter_->setAutoFillBackground(true); layout->addWidget(logRosterSplitter_); messageLog_ = new QtChatView(theme, this); logRosterSplitter_->addWidget(messageLog_); treeWidget_ = new QtTreeWidget(eventStream_); - treeWidget_->setEditable(false); treeWidget_->hide(); logRosterSplitter_->addWidget(treeWidget_); logRosterSplitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(logRosterSplitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int))); QWidget* midBar = new QWidget(this); layout->addWidget(midBar); midBar->setAutoFillBackground(true); QHBoxLayout *midBarLayout = new QHBoxLayout(midBar); diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 51aaf3e..7c84773 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -18,19 +18,19 @@ #include <QPushButton> #include <QMenuBar> #include <QToolBar> #include <QAction> #include <QTabWidget> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtTabWidget.h> #include <Swift/QtUI/QtSettingsProvider.h> -#include <Roster/QtTreeWidget.h> +#include <Roster/QtRosterWidget.h> #include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> #include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h> #include <Swift/Controllers/UIEvents/RequestProfileEditorUIEvent.h> #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h> namespace Swift { @@ -56,20 +56,19 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS tabs_->setTabPosition(QTabWidget::South); mainLayout->addWidget(tabs_); contactsTabWidget_ = new QWidget(this); contactsTabWidget_->setContentsMargins(0, 0, 0, 0); QBoxLayout *contactTabLayout = new QBoxLayout(QBoxLayout::TopToBottom, contactsTabWidget_); contactsTabWidget_->setLayout(contactTabLayout); contactTabLayout->setSpacing(0); contactTabLayout->setContentsMargins(0, 0, 0, 0); - treeWidget_ = new QtTreeWidget(uiEventStream_); - treeWidget_->setEditable(true); + treeWidget_ = new QtRosterWidget(uiEventStream_); contactTabLayout->addWidget(treeWidget_); tabs_->addTab(contactsTabWidget_, tr("&Contacts")); eventWindow_ = new QtEventWindow(uiEventStream_); connect(eventWindow_, SIGNAL(onNewEventCountUpdated(int)), this, SLOT(handleEventCountUpdated(int))); chatListWindow_ = new QtChatListWindow(uiEventStream_); connect(chatListWindow_, SIGNAL(onCountUpdated(int)), this, SLOT(handleChatCountUpdated(int))); diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index bb3e9df..321fa2d 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -19,30 +19,29 @@ class QComboBox; class QLineEdit; class QPushButton; class QToolBar; class QAction; class QMenu; class QTabWidget; namespace Swift { - class QtTreeWidget; - class QtTreeWidgetFactory; + class QtRosterWidget; class TreeWidget; class UIEventStream; class QtTabWidget; class QtSettingsProvider; class QtMainWindow : public QWidget, public MainWindow { Q_OBJECT public: QtMainWindow(QtSettingsProvider*, UIEventStream* eventStream); - ~QtMainWindow(); + virtual ~QtMainWindow(); std::vector<QMenu*> getMenus() {return menus_;} void setMyNick(const std::string& name); void setMyJID(const JID& jid); void setMyAvatarPath(const std::string& path); void setMyStatusText(const std::string& status); void setMyStatusType(StatusShow::Type type); void setConnecting(); QtEventWindow* getEventWindow(); QtChatListWindow* getChatListWindow(); @@ -60,19 +59,19 @@ namespace Swift { void handleAdHocActionTriggered(bool checked); void handleEventCountUpdated(int count); void handleChatCountUpdated(int count); void handleEditProfileRequest(); void handleTabChanged(int index); private: QtSettingsProvider* settings_; std::vector<QMenu*> menus_; - QtTreeWidget* treeWidget_; + QtRosterWidget* treeWidget_; QtRosterHeader* meView_; QAction* addUserAction_; QAction* editUserAction_; QAction* chatUserAction_; QAction* showOfflineAction_; QMenu* serverAdHocMenu_; QtTabWidget* tabs_; QWidget* contactsTabWidget_; QWidget* eventsTabWidget_; diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.cpp b/Swift/QtUI/Roster/QtOccupantListWidget.cpp new file mode 100644 index 0000000..2f992bf --- /dev/null +++ b/Swift/QtUI/Roster/QtOccupantListWidget.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + + +#include "Roster/QtOccupantListWidget.h" + +#include <QContextMenuEvent> +#include <QMenu> +#include <QInputDialog> + +#include "Swift/Controllers/Roster/ContactRosterItem.h" +#include "Swift/Controllers/Roster/GroupRosterItem.h" +#include "Swift/Controllers/UIEvents/UIEventStream.h" +#include "QtSwiftUtil.h" + +namespace Swift { + +QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent) : QtTreeWidget(eventStream, parent) { + +} + +QtOccupantListWidget::~QtOccupantListWidget() { + +} + +void QtOccupantListWidget::contextMenuEvent(QContextMenuEvent* event) { +// QModelIndex index = indexAt(event->pos()); +// if (!index.isValid()) { +// return; +// } +// RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); +// QMenu contextMenu; +// if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { +// QAction* editContact = contextMenu.addAction(tr("Edit")); +// QAction* removeContact = contextMenu.addAction(tr("Remove")); +// QAction* result = contextMenu.exec(event->globalPos()); +// if (result == editContact) { +// eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); +// } +// else if (result == removeContact) { +// if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) { +// eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID())); +// } +// } +// } +// else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { +// QAction* renameGroupAction = contextMenu.addAction(tr("Rename")); +// QAction* result = contextMenu.exec(event->globalPos()); +// if (result == renameGroupAction) { +// renameGroup(group); +// } +// } +} + +} + diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.h b/Swift/QtUI/Roster/QtOccupantListWidget.h new file mode 100644 index 0000000..5444210 --- /dev/null +++ b/Swift/QtUI/Roster/QtOccupantListWidget.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swift/QtUI/Roster/QtTreeWidget.h" + +namespace Swift { + +class QtOccupantListWidget : public QtTreeWidget { + Q_OBJECT + public: + QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent = 0); + virtual ~QtOccupantListWidget(); + protected: + void contextMenuEvent(QContextMenuEvent* event); +}; + +} + diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp new file mode 100644 index 0000000..79d7f67 --- /dev/null +++ b/Swift/QtUI/Roster/QtRosterWidget.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Roster/QtRosterWidget.h" + +#include <QContextMenuEvent> +#include <QMenu> +#include <QInputDialog> + +#include "Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h" +#include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h" +#include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h" +#include "QtContactEditWindow.h" +#include "Swift/Controllers/Roster/ContactRosterItem.h" +#include "Swift/Controllers/Roster/GroupRosterItem.h" +#include "Swift/Controllers/UIEvents/UIEventStream.h" +#include "QtSwiftUtil.h" + +namespace Swift { + +QtRosterWidget::QtRosterWidget(UIEventStream* eventStream, QWidget* parent) : QtTreeWidget(eventStream, parent) { + +} + +QtRosterWidget::~QtRosterWidget() { + +} + +void QtRosterWidget::handleEditUserActionTriggered(bool /*checked*/) { + QModelIndexList selectedIndexList = getSelectedIndexes(); + if (selectedIndexList.empty()) { + return; + } + QModelIndex index = selectedIndexList[0]; + if (!index.isValid()) { + return; + } + RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); + if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { + eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); + } +} + +void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) { + QModelIndex index = indexAt(event->pos()); + if (!index.isValid()) { + return; + } + RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); + QMenu contextMenu; + if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { + QAction* editContact = contextMenu.addAction(tr("Edit")); + QAction* removeContact = contextMenu.addAction(tr("Remove")); + QAction* result = contextMenu.exec(event->globalPos()); + if (result == editContact) { + eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); + } + else if (result == removeContact) { + if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) { + eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID())); + } + } + } + else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { + QAction* renameGroupAction = contextMenu.addAction(tr("Rename")); + QAction* result = contextMenu.exec(event->globalPos()); + if (result == renameGroupAction) { + renameGroup(group); + } + } +} + +void QtRosterWidget::renameGroup(GroupRosterItem* group) { + bool ok; + QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("Enter a new name for group '%1':").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok); + if (ok) { + eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName))); + } +} + +void QtRosterWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) { + bool valid = false; + QModelIndexList selectedIndexList = getSelectedIndexes(); + if (selectedIndexList.empty() || !selectedIndexList[0].isValid()) { + /* I didn't quite understand why using current didn't seem to work here.*/ + } + else if (current.isValid()) { + RosterItem* item = static_cast<RosterItem*>(current.internalPointer()); + if (dynamic_cast<ContactRosterItem*>(item)) { + valid = true; + } + } + onSomethingSelectedChanged(valid); + QTreeView::currentChanged(current, previous); +} + +} diff --git a/Swift/QtUI/Roster/QtRosterWidget.h b/Swift/QtUI/Roster/QtRosterWidget.h new file mode 100644 index 0000000..7781e07 --- /dev/null +++ b/Swift/QtUI/Roster/QtRosterWidget.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swift/QtUI/Roster/QtTreeWidget.h" + +namespace Swift { + +class QtRosterWidget : public QtTreeWidget { + Q_OBJECT + public: + QtRosterWidget(UIEventStream* eventStream, QWidget* parent = 0); + virtual ~QtRosterWidget(); + public slots: + void handleEditUserActionTriggered(bool checked); + signals: + void onSomethingSelectedChanged(bool); + protected: + void contextMenuEvent(QContextMenuEvent* event); + protected slots: + virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous); + private: + void renameGroup(GroupRosterItem* group); +}; + +} diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index 1296872..7de4028 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -1,36 +1,29 @@ /* * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Roster/QtTreeWidget.h" -#include <QMenu> -#include <QContextMenuEvent> -#include <QInputDialog> #include <boost/smart_ptr/make_shared.hpp> #include "Swiften/Base/Platform.h" #include "Swift/Controllers/Roster/ContactRosterItem.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" -#include "Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h" -#include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h" -#include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h" #include "QtSwiftUtil.h" -#include "QtContactEditWindow.h" namespace Swift { -QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeView(parent), editable_(false) { +QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeView(parent) { eventStream_ = eventStream; model_ = new RosterModel(this); setModel(model_); delegate_ = new RosterDelegate(this); setItemDelegate(delegate_); setHeaderHidden(true); #ifdef SWIFT_PLATFORM_MACOSX setAlternatingRowColors(true); #endif @@ -82,100 +75,26 @@ QModelIndexList QtTreeWidget::getSelectedIndexes() const { if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) { for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) { selectedIndexList.append(ranges.at(i).model()->index(r, 0, parent)); } } } return selectedIndexList; } -void QtTreeWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) { - bool valid = false; - QModelIndexList selectedIndexList = getSelectedIndexes(); - if (!editable_ || selectedIndexList.empty() || !selectedIndexList[0].isValid()) { - /* I didn't quite understand why using current didn't seem to work here.*/ - } - else if (current.isValid()) { - RosterItem* item = static_cast<RosterItem*>(current.internalPointer()); - if (dynamic_cast<ContactRosterItem*>(item)) { - valid = true; - } - } - onSomethingSelectedChanged(valid); - QTreeView::currentChanged(current, previous); -} - void QtTreeWidget::handleItemActivated(const QModelIndex& index) { RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item); if (contact) { eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(contact->getJID()))); } } -void QtTreeWidget::handleEditUserActionTriggered(bool /*checked*/) { - if (!editable_) { - return; - } - QModelIndexList selectedIndexList = getSelectedIndexes(); - if (selectedIndexList.empty()) { - return; - } - QModelIndex index = selectedIndexList[0]; - if (!index.isValid()) { - return; - } - RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); - if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { - eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); - } -} - -void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) { - if (!editable_) { - return; - } - QModelIndex index = indexAt(event->pos()); - if (!index.isValid()) { - return; - } - RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); - QMenu contextMenu; - if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { - QAction* editContact = contextMenu.addAction(tr("Edit")); - QAction* removeContact = contextMenu.addAction(tr("Remove")); - QAction* result = contextMenu.exec(event->globalPos()); - if (result == editContact) { - eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); - } - else if (result == removeContact) { - if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) { - eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID())); - } - } - } - else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { - QAction* renameGroupAction = contextMenu.addAction(tr("Rename")); - QAction* result = contextMenu.exec(event->globalPos()); - if (result == renameGroupAction) { - renameGroup(group); - } - } -} - -void QtTreeWidget::renameGroup(GroupRosterItem* group) { - bool ok; - QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("Enter a new name for group '%1':").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok); - if (ok) { - eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName))); - } -} - void QtTreeWidget::handleExpanded(const QModelIndex& index) { GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer())); if (item) { item->setExpanded(true); } } void QtTreeWidget::handleCollapsed(const QModelIndex& index) { GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer())); diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h index 4ecba83..c45a1cd 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.h +++ b/Swift/QtUI/Roster/QtTreeWidget.h @@ -17,43 +17,33 @@ class UIEventStream; class QtTreeWidget : public QTreeView{ Q_OBJECT public: QtTreeWidget(UIEventStream* eventStream, QWidget* parent = 0); ~QtTreeWidget(); void show(); QtTreeWidgetItem* getRoot(); void setRosterModel(Roster* roster); Roster* getRoster() {return roster_;} - void setEditable(bool b) { editable_ = b; } - - signals: - void onSomethingSelectedChanged(bool); - - public slots: - void handleEditUserActionTriggered(bool checked); private slots: void handleItemActivated(const QModelIndex&); void handleModelItemExpanded(const QModelIndex&, bool expanded); void handleExpanded(const QModelIndex&); void handleCollapsed(const QModelIndex&); void handleClicked(const QModelIndex&); - protected: - void contextMenuEvent(QContextMenuEvent* event); - protected slots: - virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous); + protected: + QModelIndexList getSelectedIndexes() const; private: - void renameGroup(GroupRosterItem* group); void drawBranches(QPainter*, const QRect&, const QModelIndex&) const; - QModelIndexList getSelectedIndexes() const; + protected: + UIEventStream* eventStream_; + private: RosterModel* model_; Roster* roster_; RosterDelegate* delegate_; QtTreeWidgetItem* treeRoot_; - UIEventStream* eventStream_; - bool editable_; }; } diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 24299fb..33450ed 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -98,18 +98,20 @@ sources = [ "QtFormWidget.cpp", "QtLineEdit.cpp", "QtJoinMUCWindow.cpp", "Roster/RosterModel.cpp", "Roster/QtTreeWidget.cpp", # "Roster/QtTreeWidgetItem.cpp", "Roster/RosterDelegate.cpp", "Roster/GroupItemDelegate.cpp", "Roster/DelegateCommons.cpp", + "Roster/QtRosterWidget.cpp", + "Roster/QtOccupantListWidget.cpp", "EventViewer/EventModel.cpp", "EventViewer/EventDelegate.cpp", "EventViewer/TwoLineDelegate.cpp", "EventViewer/QtEventWindow.cpp", "EventViewer/QtEvent.cpp", "ChatList/QtChatListWindow.cpp", "ChatList/ChatListModel.cpp", "ChatList/ChatListDelegate.cpp", "ChatList/ChatListMUCItem.cpp", |