summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp61
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h6
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp14
-rw-r--r--Swift/QtUI/Roster/RosterModel.h2
4 files changed, 47 insertions, 36 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index 97b055b..ba57421 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -8,6 +8,7 @@
#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"
@@ -33,10 +34,10 @@ QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeV
setIndentation(0);
setRootIsDecorated(true);
connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
-// connect(model_, SIGNAL(itemExpanded(const QModelIndex&, bool)), this, SLOT(handleModelItemExpanded(const QModelIndex&, bool)));
+ connect(model_, SIGNAL(itemExpanded(const QModelIndex&, bool)), this, SLOT(handleModelItemExpanded(const QModelIndex&, bool)));
// connect(model_, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(handleDataChanged(const QModelIndex&, const QModelIndex&)));
-// connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(handleExpanded(const QModelIndex&)));
-// connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(handleCollapsed(const QModelIndex&)));
+ connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(handleExpanded(const QModelIndex&)));
+ connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(handleCollapsed(const QModelIndex&)));
}
QtTreeWidget::~QtTreeWidget() {
@@ -76,33 +77,33 @@ void QtTreeWidget::contextMenuEvent(QContextMenuEvent* event) {
}
}
-//void QtTreeWidget::handleExpanded(const QModelIndex& index) {
-// QtTreeWidgetItem* qtItem = static_cast<QtTreeWidgetItem*>(index.internalPointer());
-// if (qtItem) {
-// qtItem->setExpanded(true);
-// }
-//}
-
-//void QtTreeWidget::handleCollapsed(const QModelIndex& index) {
-// QtTreeWidgetItem* qtItem = static_cast<QtTreeWidgetItem*>(index.internalPointer());
-// if (qtItem) {
-// qtItem->setExpanded(false);
-// }
-//}
-
-//void QtTreeWidget::handleModelItemExpanded(const QModelIndex& index, bool shouldExpand) {
-// if (this->isExpanded(index) == shouldExpand) {
-// return;
-// }
-// //setExpanded(index, shouldExpand);
-// if (shouldExpand) {
-// expand(index);
-// emit expanded(index);
-// } else {
-// collapse(index);
-// emit collapsed(index);
-// }
-//}
+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()));
+ if (item) {
+ item->setExpanded(false);
+ }
+}
+
+void QtTreeWidget::handleModelItemExpanded(const QModelIndex& index, bool shouldExpand) {
+ if (this->isExpanded(index) == shouldExpand) {
+ return;
+ }
+ //setExpanded(index, shouldExpand);
+ if (shouldExpand) {
+ expand(index);
+ emit expanded(index);
+ } else {
+ collapse(index);
+ emit collapsed(index);
+ }
+}
// void QtTreeWidget::handleDataChanged(const QModelIndex& topLeft, const QModelIndex& /*bottomRight*/) {
// //in our model, this is only thrown with topLeft == bottomRight
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index c03f2e2..b45701e 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -28,9 +28,9 @@ class QtTreeWidget : public QTreeView{
void setRosterModel(Roster* roster);
private slots:
void handleItemActivated(const QModelIndex&);
-// void handleModelItemExpanded(const QModelIndex&, bool expanded);
-// void handleExpanded(const QModelIndex&);
-// void handleCollapsed(const QModelIndex&);
+ void handleModelItemExpanded(const QModelIndex&, bool expanded);
+ void handleExpanded(const QModelIndex&);
+ void handleCollapsed(const QModelIndex&);
// void handleDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
protected:
void contextMenuEvent(QContextMenuEvent* event);
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index d5b4002..00a032d 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -38,10 +38,15 @@ void RosterModel::setRoster(Roster* roster) {
}
void RosterModel::handleGroupAdded(GroupRosterItem* group) {
- view_->setExpanded(index(group), true);
+ emit itemExpanded(index(group), group->isExpanded());
}
-void RosterModel::handleChildrenChanged(GroupRosterItem* /*group*/) {
+void RosterModel::handleChildrenChanged(GroupRosterItem* group) {
+ foreach (RosterItem* item, group->getDisplayedChildren()) {
+ GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(item);
+ if (!child) continue;
+ emit itemExpanded(index(child), child->isExpanded());
+ }
emit layoutChanged();
}
@@ -49,7 +54,10 @@ void RosterModel::handleDataChanged(RosterItem* item) {
Q_ASSERT(item);
QModelIndex modelIndex = index(item);
if (modelIndex.isValid()) {
- //emit itemExpanded(modelIndex, item->isExpanded());
+ GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
+ if (group) {
+ emit itemExpanded(modelIndex, group->isExpanded());
+ }
emit dataChanged(modelIndex, modelIndex);
}
}
diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h
index 17fdd3e..10aeccd 100644
--- a/Swift/QtUI/Roster/RosterModel.h
+++ b/Swift/QtUI/Roster/RosterModel.h
@@ -34,6 +34,8 @@ namespace Swift {
QModelIndex index(RosterItem* item) const;
QModelIndex parent(const QModelIndex& index) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ signals:
+ void itemExpanded(const QModelIndex& item, bool expanded);
private:
void handleDataChanged(RosterItem* item);
void handleChildrenChanged(GroupRosterItem* item);