summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp50
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h9
2 files changed, 52 insertions, 7 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index a76dc70..3198ca5 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -66,8 +66,23 @@ void QtTreeWidget::handleClicked(const QModelIndex& index) {
if (item) {
setExpanded(index, !isExpanded(index));
}
+ currentChanged(index, QModelIndex());
}
+void QtTreeWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) {
+ bool valid = false;
+ if (!editable_ || selectedIndexes().empty() || !selectedIndexes()[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());
@@ -77,6 +92,23 @@ void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
}
}
+void QtTreeWidget::handleEditUserActionTriggered(bool /*checked*/) {
+ if (!editable_) {
+ return;
+ }
+ if (selectedIndexes().empty()) {
+ return;
+ }
+ QModelIndex index = selectedIndexes()[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;
@@ -101,18 +133,22 @@ void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) {
}
}
else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) {
- QAction* renameGroup = contextMenu.addAction(tr("Rename"));
+ QAction* renameGroupAction = contextMenu.addAction(tr("Rename"));
QAction* result = contextMenu.exec(event->globalPos());
- if (result == renameGroup) {
- bool ok;
- QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("New name for %1").arg(P2QSTRING(group->getDisplayName())), QLineEdit::Normal, P2QSTRING(group->getDisplayName()), &ok);
- if (ok) {
- eventStream_->send(boost::make_shared<RenameGroupUIEvent>(group->getDisplayName(), Q2PSTRING(newName)));
- }
+ if (result == renameGroupAction) {
+ renameGroup(group);
}
}
}
+void QtTreeWidget::renameGroup(GroupRosterItem* group) {
+ bool ok;
+ QString newName = QInputDialog::getText(NULL, tr("Rename group"), tr("New name for %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) {
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index ce2351b..1ab8c8e 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -25,6 +25,12 @@ class QtTreeWidget : public QTreeView{
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);
@@ -33,8 +39,11 @@ class QtTreeWidget : public QTreeView{
void handleClicked(const QModelIndex&);
protected:
void contextMenuEvent(QContextMenuEvent* event);
+ protected slots:
+ virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
private:
+ void renameGroup(GroupRosterItem* group);
void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
RosterModel* model_;
Roster* roster_;