+ 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));
+ }
+}
+
+
+void ChatViewSearchController::updateHighlights(ChatLine *line)
+{
+ QList<ChatItem *> checkItems;
+ if (_searchSenders)
+ checkItems << line->item(MessageModel::SenderColumn);
+
+ if (_searchMsgs)
+ checkItems << line->item(MessageModel::ContentsColumn);
+
+ QHash<quint64, QHash<quint64, QRectF> > wordRects;
+ foreach(ChatItem *item, checkItems) {
+ foreach(QRectF wordRect, item->findWords(searchString(), caseSensitive())) {
+ wordRects[(quint64)(wordRect.x() + item->x())][(quint64)(wordRect.y())] = wordRect;
+ }
+ }
+
+ bool deleteAll = false;
+ QAbstractItemModel *model = _scene->model();
+ Q_ASSERT(model);
+ if (_searchOnlyRegularMsgs) {
+ QModelIndex index = model->index(line->row(), 0);
+ if (!checkType((Message::Type)index.data(MessageModel::TypeRole).toInt()))
+ deleteAll = true;
+ }
+
+ foreach(QGraphicsItem *child, line->childItems()) {
+ SearchHighlightItem *highlightItem = qgraphicsitem_cast<SearchHighlightItem *>(child);
+ if (!highlightItem)
+ continue;
+
+ if (!deleteAll && wordRects.contains((quint64)(highlightItem->pos().x())) && wordRects[(quint64)(highlightItem->pos().x())].contains((quint64)(highlightItem->pos().y()))) {
+ QRectF &wordRect = wordRects[(quint64)(highlightItem->pos().x())][(quint64)(highlightItem->pos().y())];
+ highlightItem->updateGeometry(wordRect.width(), wordRect.height());
+ }
+ else {
+ int pos = _highlightItems.indexOf(highlightItem);
+ if (pos == _currentHighlight) {
+ highlightPrev();
+ }
+ else if (pos < _currentHighlight) {
+ _currentHighlight--;
+ }
+
+ _highlightItems.removeAt(pos);
+ delete highlightItem;
+ }
+ }
+}
+
+
+void ChatViewSearchController::highlightLine(ChatLine *line)
+{
+ QList<ChatItem *> checkItems;
+ if (_searchSenders)
+ checkItems << line->item(MessageModel::SenderColumn);
+
+ if (_searchMsgs)
+ checkItems << line->item(MessageModel::ContentsColumn);
+
+ foreach(ChatItem *item, checkItems) {
+ foreach(QRectF wordRect, item->findWords(searchString(), caseSensitive())) {
+ _highlightItems << new SearchHighlightItem(wordRect.adjusted(item->x(), 0, item->x(), 0), line);
+ }
+ }
+}
+