diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-01 12:54:14 (GMT) | 
|---|---|---|
| committer | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-01 12:57:14 (GMT) | 
| commit | 9179b54ac93ddc88765c3cd984916d7ffd130d20 (patch) | |
| tree | ddcbacdd0228d52ba3f0ad4d6e8e5f09e8d12c87 /Swift/QtUI/Roster/QtTreeWidget.cpp | |
| parent | f90a0307a16a93376270a84be61451faa9bd9701 (diff) | |
| download | swift-contrib-9179b54ac93ddc88765c3cd984916d7ffd130d20.zip swift-contrib-9179b54ac93ddc88765c3cd984916d7ffd130d20.tar.bz2  | |
Reset roster filter when hitting enter to start chat.
Test-Information:
Enter search term and use keyboard arrows to move to select a contact and pressing enter will start a chat and clear the filter. Confirm that pressing escape still clears the filter without starting a chat and that the changes do not interfere with starting a chat normally by double clicking on a contact.
Change-Id: I90f5d431da56896eeb10f16c0ba23bdc143c4857
Diffstat (limited to 'Swift/QtUI/Roster/QtTreeWidget.cpp')
| -rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 29 | 
1 files changed, 21 insertions, 8 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index fbe85de..5333260 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -106,78 +106,71 @@ void QtTreeWidget::handleClicked(const QModelIndex& index) {  QModelIndexList QtTreeWidget::getSelectedIndexes() const {  	// Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the  	// QModelIndexList destructor.  	// This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case  	// was resolved by linking against the debug libs, ours isn't, and we're not alone)  	QItemSelection ranges = selectionModel()->selection();  	QModelIndexList selectedIndexList;  	for (int i = 0; i < ranges.count(); ++i) {  		QModelIndex parent = ranges.at(i).parent();  		int right = ranges.at(i).model()->columnCount(parent) - 1;  		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) {  	RosterItem* item = NULL;  	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()) {  		item = static_cast<RosterItem*>(current.internalPointer());  		item = dynamic_cast<ContactRosterItem*>(item);  	}  	onSomethingSelectedChanged(item);  	QTreeView::currentChanged(current, previous);  }  void QtTreeWidget::handleItemActivated(const QModelIndex& index) { -	JID target; -	if (messageTarget_ == MessageDisplayJID) { -		target = JID(Q2PSTRING(index.data(DisplayJIDRole).toString())); -		target = target.toBare(); -	} -	if (!target.isValid()) { -		target = JID(Q2PSTRING(index.data(JIDRole).toString())); -	} +	JID target = jidFromIndex(index);  	if (target.isValid()) {  		eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target)));  	}  }  void QtTreeWidget::dragEnterEvent(QDragEnterEvent *event) {  	if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {  		event->acceptProposedAction();  	}  }  void QtTreeWidget::dropEvent(QDropEvent *event) {  	QModelIndex index = indexAt(event->pos());  	if (index.isValid()) {  		RosterItem* item = static_cast<RosterItem*>(index.internalPointer());  		if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {  			if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {  				QString filename = event->mimeData()->urls().at(0).toLocalFile();  				if (!filename.isEmpty()) {  					eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(filename)));  				}  			}  		}  	}  }  void QtTreeWidget::dragMoveEvent(QDragMoveEvent* event) {  	QModelIndex index = indexAt(event->pos());  	if (index.isValid()) {  		RosterItem* item = static_cast<RosterItem*>(index.internalPointer());  		if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {  			if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {  				event->accept();  				return;  			} @@ -207,36 +200,56 @@ 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 (!index.isValid()) {  		return;  	}  	bool alreadyRight = this->isExpanded(index) == shouldExpand;  	if (alreadyRight) {  		return;  	}  	setExpanded(index, shouldExpand);  }  void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const {  }  void QtTreeWidget::show() {  	QWidget::show();  }  void QtTreeWidget::setMessageTarget(MessageTarget messageTarget) {  	messageTarget_ = messageTarget;  } +JID QtTreeWidget::jidFromIndex(const QModelIndex& index) const { +	JID target; +	if (messageTarget_ == MessageDisplayJID) { +		target = JID(Q2PSTRING(index.data(DisplayJIDRole).toString())); +		target = target.toBare(); +	} +	if (!target.isValid()) { +		target = JID(Q2PSTRING(index.data(JIDRole).toString())); +	} +	return target; +} + +JID QtTreeWidget::selectedJID() const { +	QModelIndexList list = selectedIndexes(); +	if (list.size() != 1) { +		return JID(); +	} +	return jidFromIndex(list[0]); +} +  }  | 
 Swift