X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatviewsearchcontroller.cpp;h=dd1ca08a59b332bd2dff20cf6104407cbe4dbac0;hp=f12bfa01142c72aee6725eae8331e469b2bdcd92;hb=52209badc8e769e50aa3019b63689dda0e79e9d0;hpb=6eefdfc697067d184a589fc8a231b16316c09106 diff --git a/src/qtui/chatviewsearchcontroller.cpp b/src/qtui/chatviewsearchcontroller.cpp index f12bfa01..dd1ca08a 100644 --- a/src/qtui/chatviewsearchcontroller.cpp +++ b/src/qtui/chatviewsearchcontroller.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,6 +20,8 @@ #include "chatviewsearchcontroller.h" +#include + #include #include @@ -29,13 +31,11 @@ #include "chatscene.h" #include "messagemodel.h" -ChatViewSearchController::ChatViewSearchController(QObject *parent) +ChatViewSearchController::ChatViewSearchController(QObject* parent) : QObject(parent) -{ -} +{} - -void ChatViewSearchController::setSearchString(const QString &searchString) +void ChatViewSearchController::setSearchString(const QString& searchString) { QString oldSearchString = _searchString; _searchString = searchString; @@ -51,8 +51,7 @@ void ChatViewSearchController::setSearchString(const QString &searchString) } } - -void ChatViewSearchController::setScene(ChatScene *scene) +void ChatViewSearchController::setScene(ChatScene* scene) { Q_ASSERT(scene); if (scene == _scene) @@ -75,7 +74,6 @@ void ChatViewSearchController::setScene(ChatScene *scene) updateHighlights(); } - void ChatViewSearchController::highlightNext() { if (_highlightItems.isEmpty()) @@ -92,7 +90,6 @@ void ChatViewSearchController::highlightNext() emit newCurrentHighlight(_highlightItems.at(_currentHighlight)); } - void ChatViewSearchController::highlightPrev() { if (_highlightItems.isEmpty()) @@ -109,20 +106,19 @@ void ChatViewSearchController::highlightPrev() emit newCurrentHighlight(_highlightItems.at(_currentHighlight)); } - void ChatViewSearchController::updateHighlights(bool reuse) { if (!_scene) return; if (reuse) { - QSet chatLines; - foreach(SearchHighlightItem *highlightItem, _highlightItems) { - auto *line = qgraphicsitem_cast(highlightItem->parentItem()); + QSet chatLines; + foreach (SearchHighlightItem* highlightItem, _highlightItems) { + auto* line = qgraphicsitem_cast(highlightItem->parentItem()); if (line) chatLines << line; } - foreach(ChatLine *line, QList(chatLines.toList())) { + foreach (ChatLine* line, chatLines) { updateHighlights(line); } } @@ -142,7 +138,8 @@ void ChatViewSearchController::updateHighlights(bool reuse) if (!_highlightItems.isEmpty()) { if (!oldHighlightPos.isNull()) { - int start = 0; int end = _highlightItems.count() - 1; + int start = 0; + int end = _highlightItems.count() - 1; QPointF startPos; QPointF endPos; while (true) { @@ -209,10 +206,9 @@ void ChatViewSearchController::updateHighlights(bool reuse) } } - void ChatViewSearchController::checkMessagesForHighlight(int start, int end) { - QAbstractItemModel *model = _scene->model(); + QAbstractItemModel* model = _scene->model(); Q_ASSERT(model); if (end == -1) { @@ -232,25 +228,24 @@ void ChatViewSearchController::checkMessagesForHighlight(int start, int end) } } - -void ChatViewSearchController::updateHighlights(ChatLine *line) +void ChatViewSearchController::updateHighlights(ChatLine* line) { - QList checkItems; + QList checkItems; if (_searchSenders) checkItems << line->item(MessageModel::SenderColumn); if (_searchMsgs) checkItems << line->item(MessageModel::ContentsColumn); - QHash > wordRects; - foreach(ChatItem *item, checkItems) { - foreach(QRectF wordRect, item->findWords(searchString(), caseSensitive())) { + QHash> 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(); + QAbstractItemModel* model = _scene->model(); Q_ASSERT(model); if (_searchOnlyRegularMsgs) { QModelIndex index = model->index(line->row(), 0); @@ -258,13 +253,14 @@ void ChatViewSearchController::updateHighlights(ChatLine *line) deleteAll = true; } - foreach(QGraphicsItem *child, line->childItems()) { - auto *highlightItem = qgraphicsitem_cast(child); + foreach (QGraphicsItem* child, line->childItems()) { + auto* highlightItem = qgraphicsitem_cast(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())]; + 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 { @@ -282,44 +278,40 @@ void ChatViewSearchController::updateHighlights(ChatLine *line) } } - -void ChatViewSearchController::highlightLine(ChatLine *line) +void ChatViewSearchController::highlightLine(ChatLine* line) { - QList checkItems; + QList 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())) { + foreach (ChatItem* item, checkItems) { + foreach (QRectF wordRect, item->findWords(searchString(), caseSensitive())) { _highlightItems << new SearchHighlightItem(wordRect.adjusted(item->x(), 0, item->x(), 0), line); } } } - void ChatViewSearchController::repositionHighlights() { - QSet chatLines; - foreach(SearchHighlightItem *item, _highlightItems) { - auto *line = qgraphicsitem_cast(item->parentItem()); + QSet chatLines; + foreach (SearchHighlightItem* item, _highlightItems) { + auto* line = qgraphicsitem_cast(item->parentItem()); if (line) chatLines << line; } - QList chatLineList(chatLines.toList()); - foreach(ChatLine *line, chatLineList) { + foreach (ChatLine* line, chatLines) { repositionHighlights(line); } } - -void ChatViewSearchController::repositionHighlights(ChatLine *line) +void ChatViewSearchController::repositionHighlights(ChatLine* line) { - QList searchHighlights; - foreach(QGraphicsItem *child, line->childItems()) { - auto *highlightItem = qgraphicsitem_cast(child); + QList searchHighlights; + foreach (QGraphicsItem* child, line->childItems()) { + auto* highlightItem = qgraphicsitem_cast(child); if (highlightItem) searchHighlights << highlightItem; } @@ -329,17 +321,17 @@ void ChatViewSearchController::repositionHighlights(ChatLine *line) QList wordPos; if (_searchSenders) { - foreach(QRectF wordRect, line->senderItem()->findWords(searchString(), caseSensitive())) { + foreach (QRectF wordRect, line->senderItem()->findWords(searchString(), caseSensitive())) { wordPos << QPointF(wordRect.x() + line->senderItem()->x(), wordRect.y()); } } if (_searchMsgs) { - foreach(QRectF wordRect, line->contentsItem()->findWords(searchString(), caseSensitive())) { + foreach (QRectF wordRect, line->contentsItem()->findWords(searchString(), caseSensitive())) { wordPos << QPointF(wordRect.x() + line->contentsItem()->x(), wordRect.y()); } } - qSort(searchHighlights.begin(), searchHighlights.end(), SearchHighlightItem::firstInLine); + std::sort(searchHighlights.begin(), searchHighlights.end(), SearchHighlightItem::firstInLine); Q_ASSERT(wordPos.count() == searchHighlights.count()); for (int i = 0; i < searchHighlights.count(); i++) { @@ -347,7 +339,6 @@ void ChatViewSearchController::repositionHighlights(ChatLine *line) } } - void ChatViewSearchController::sceneDestroyed() { // WARNING: don't call any methods on scene! @@ -357,7 +348,6 @@ void ChatViewSearchController::sceneDestroyed() _highlightItems.clear(); } - void ChatViewSearchController::setCaseSensitive(bool caseSensitive) { if (_caseSensitive == caseSensitive) @@ -370,7 +360,6 @@ void ChatViewSearchController::setCaseSensitive(bool caseSensitive) updateHighlights(caseSensitive); } - void ChatViewSearchController::setSearchSenders(bool searchSenders) { if (_searchSenders == searchSenders) @@ -382,7 +371,6 @@ void ChatViewSearchController::setSearchSenders(bool searchSenders) updateHighlights(!searchSenders); } - void ChatViewSearchController::setSearchMsgs(bool searchMsgs) { if (_searchMsgs == searchMsgs) @@ -395,7 +383,6 @@ void ChatViewSearchController::setSearchMsgs(bool searchMsgs) updateHighlights(!searchMsgs); } - void ChatViewSearchController::setSearchOnlyRegularMsgs(bool searchOnlyRegularMsgs) { if (_searchOnlyRegularMsgs == searchOnlyRegularMsgs) @@ -408,16 +395,15 @@ void ChatViewSearchController::setSearchOnlyRegularMsgs(bool searchOnlyRegularMs updateHighlights(searchOnlyRegularMsgs); } - // ================================================== // SearchHighlightItem // ================================================== -SearchHighlightItem::SearchHighlightItem(QRectF wordRect, QGraphicsItem *parent) - : QObject(), - QGraphicsItem(parent), - _highlighted(false), - _alpha(70), - _timeLine(150) +SearchHighlightItem::SearchHighlightItem(QRectF wordRect, QGraphicsItem* parent) + : QObject() + , QGraphicsItem(parent) + , _highlighted(false) + , _alpha(70) + , _timeLine(150) { setPos(wordRect.x(), wordRect.y()); updateGeometry(wordRect.width(), wordRect.height()); @@ -425,7 +411,6 @@ SearchHighlightItem::SearchHighlightItem(QRectF wordRect, QGraphicsItem *parent) connect(&_timeLine, &QTimeLine::valueChanged, this, &SearchHighlightItem::updateHighlight); } - void SearchHighlightItem::setHighlighted(bool highlighted) { _highlighted = highlighted; @@ -441,15 +426,13 @@ void SearchHighlightItem::setHighlighted(bool highlighted) update(); } - void SearchHighlightItem::updateHighlight(qreal value) { _alpha = 70 + (int)(80 * value); update(); } - -void SearchHighlightItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void SearchHighlightItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); @@ -461,7 +444,6 @@ void SearchHighlightItem::paint(QPainter *painter, const QStyleOptionGraphicsIte painter->drawRoundedRect(boundingRect(), radius, radius); } - void SearchHighlightItem::updateGeometry(qreal width, qreal height) { prepareGeometryChange(); @@ -470,8 +452,7 @@ void SearchHighlightItem::updateGeometry(qreal width, qreal height) update(); } - -bool SearchHighlightItem::firstInLine(QGraphicsItem *item1, QGraphicsItem *item2) +bool SearchHighlightItem::firstInLine(QGraphicsItem* item1, QGraphicsItem* item2) { if (item1->pos().y() != item2->pos().y()) return item1->pos().y() < item2->pos().y();