+ foreach(ChatLine *line, QList<ChatLine *>(chatLines.toList())) {
+ updateHighlights(line);
+ }
+ } else {
+ QPointF oldHighlightPos;
+ if(!_highlightItems.isEmpty() && _currentHighlight < _highlightItems.count()) {
+ oldHighlightPos = _highlightItems[_currentHighlight]->scenePos();
+ }
+ qDeleteAll(_highlightItems);
+ _highlightItems.clear();
+ Q_ASSERT(_highlightItems.isEmpty());
+
+ if(searchString().isEmpty() || !(_searchSenders || _searchMsgs))
+ return;
+
+ checkMessagesForHighlight();
+
+ if(!_highlightItems.isEmpty()) {
+ if(!oldHighlightPos.isNull()) {
+ int start = 0; int end = _highlightItems.count() - 1;
+ QPointF startPos;
+ QPointF endPos;
+ while(1) {
+ startPos = _highlightItems[start]->scenePos();
+ endPos = _highlightItems[end]->scenePos();
+ if(startPos == oldHighlightPos) {
+ _currentHighlight = start;
+ break;
+ }
+ if(endPos == oldHighlightPos) {
+ _currentHighlight = end;
+ break;
+ }
+ if(end - start == 1) {
+ _currentHighlight = start;
+ break;
+ }
+ int pivot = (end + start) / 2;
+ QPointF pivotPos = _highlightItems[pivot]->scenePos();
+ if(startPos.y() == endPos.y()) {
+ if(oldHighlightPos.x() <= pivotPos.x())
+ end = pivot;
+ else
+ start = pivot;
+ } else {
+ if(oldHighlightPos.y() <= pivotPos.y())
+ end = pivot;
+ else
+ start = pivot;
+ }
+ }
+ } else {
+ _currentHighlight = _highlightItems.count() - 1;
+ }
+ _highlightItems[_currentHighlight]->setHighlighted(true);
+ emit newCurrentHighlight(_highlightItems[_currentHighlight]);
+ }
+ }
+}
+
+void ChatViewSearchController::checkMessagesForHighlight(int start, int end) {
+ QAbstractItemModel *model = _scene->model();
+ Q_ASSERT(model);
+
+ if(end == -1) {
+ end = model->rowCount() - 1;
+ if(end == -1)
+ return;
+ }
+
+ QModelIndex index;
+ for(int row = start; row <= end; row++) {
+ if(_searchOnlyRegularMsgs) {
+ index = model->index(row, 0);
+ if(!checkType((Message::Type)index.data(MessageModel::TypeRole).toInt()))
+ continue;
+ }
+ highlightLine(_scene->chatLine(row));