summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-08-29 16:15:27 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-08-29 16:15:27 (GMT)
commit030c2d8a448dbf17808b840df1d0379639867e99 (patch)
treee510f94602c35707a59759d7c27027ef8b957ae8 /Swift/QtUI/Roster/QtTreeWidget.cpp
parent2ceddd421319cbab2deb89821e81fb1a7bf724ae (diff)
downloadswift-030c2d8a448dbf17808b840df1d0379639867e99.zip
swift-030c2d8a448dbf17808b840df1d0379639867e99.tar.bz2
Show contact count on collapsed roster groups
Diffstat (limited to 'Swift/QtUI/Roster/QtTreeWidget.cpp')
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp51
1 files changed, 47 insertions, 4 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index b678e0c..75863fc 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -3,13 +3,15 @@
#include "Swiften/Base/Platform.h"
#include "Swiften/Roster/OpenChatRosterAction.h"
+#include <qdebug.h>
+
namespace Swift {
QtTreeWidget::QtTreeWidget(QWidget* parent) : QTreeView(parent) {
treeRoot_ = new QtTreeWidgetItem(NULL);
model_ = new RosterModel();
model_->setRoot(treeRoot_);
- setModel(model_);
+ setModel(model_);
delegate_ = new RosterDelegate();
setItemDelegate(delegate_);
setHeaderHidden(true);
@@ -20,7 +22,10 @@ QtTreeWidget::QtTreeWidget(QWidget* parent) : QTreeView(parent) {
setIndentation(0);
setRootIsDecorated(true);
connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
- connect(model_, SIGNAL(itemExpanded(const QModelIndex&, bool)), this, SLOT(handleItemExpanded(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&)));
}
QtTreeWidget::~QtTreeWidget() {
@@ -39,8 +44,46 @@ void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
}
}
-void QtTreeWidget::handleItemExpanded(const QModelIndex& index, bool expanded) {
- setExpanded(index, expanded);
+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::handleDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
+ Q_UNUSED(bottomRight);
+ //in our model, this is only thrown with topLeft == bottomRight
+ if (!topLeft.isValid()) {
+ return;
+ }
+ QtTreeWidgetItem* qtItem = static_cast<QtTreeWidgetItem*>(topLeft.internalPointer());
+ if (qtItem) {
+ //qDebug() << "Item changed, passing expanded state to view: " << qtItem->isExpanded();
+ setExpanded(topLeft, qtItem->isExpanded());
+ }
+
}
void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const {