X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatviewsearchcontroller.cpp;h=8e72aef36248f8e8c3cdc0650915e4c43a0e13d4;hp=997c1953b7af4b7268d82c1f68597f6eabc91d6b;hb=c80e9d81bfecf4126ed5a0a8b34802aa320ade0c;hpb=f824db0e31b54969e0b7fa0b5405b1e9173d482c diff --git a/src/qtui/chatviewsearchcontroller.cpp b/src/qtui/chatviewsearchcontroller.cpp index 997c1953..8e72aef3 100644 --- a/src/qtui/chatviewsearchcontroller.cpp +++ b/src/qtui/chatviewsearchcontroller.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2010 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,7 @@ #include #include "chatitem.h" +#include "chatline.h" #include "chatlinemodel.h" #include "chatscene.h" #include "messagemodel.h" @@ -60,6 +61,7 @@ void ChatViewSearchController::setSearchString(const QString &searchString) { if(_scene) { disconnect(_scene, 0, this, 0); + disconnect(Client::messageModel(), 0, this, 0); qDeleteAll(_highlightItems); _highlightItems.clear(); } @@ -70,6 +72,7 @@ void ChatViewSearchController::setSearchString(const QString &searchString) { connect(_scene, SIGNAL(destroyed()), this, SLOT(sceneDestroyed())); connect(_scene, SIGNAL(layoutChanged()), this, SLOT(repositionHighlights())); + connect(Client::messageModel(), SIGNAL(finishedBacklogFetch(BufferId)), this, SLOT(updateHighlights())); updateHighlights(); } @@ -133,40 +136,40 @@ void ChatViewSearchController::updateHighlights(bool reuse) { 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; - } - } + 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; + _currentHighlight = _highlightItems.count() - 1; } _highlightItems[_currentHighlight]->setHighlighted(true); emit newCurrentHighlight(_highlightItems[_currentHighlight]); @@ -189,24 +192,24 @@ void ChatViewSearchController::checkMessagesForHighlight(int start, int end) { if(_searchOnlyRegularMsgs) { index = model->index(row, 0); if(!checkType((Message::Type)index.data(MessageModel::TypeRole).toInt())) - continue; - highlightLine(_scene->chatLine(row)); + continue; } + highlightLine(_scene->chatLine(row)); } } void ChatViewSearchController::updateHighlights(ChatLine *line) { QList checkItems; if(_searchSenders) - checkItems << &(line->item(MessageModel::SenderColumn)); + checkItems << line->item(MessageModel::SenderColumn); if(_searchMsgs) - checkItems << &(line->item(MessageModel::ContentsColumn)); + checkItems << line->item(MessageModel::ContentsColumn); QHash > wordRects; foreach(ChatItem *item, checkItems) { foreach(QRectF wordRect, item->findWords(searchString(), caseSensitive())) { - wordRects[wordRect.x() + item->x()][wordRect.y()] = wordRect; + wordRects[(quint64)(wordRect.x() + item->x())][(quint64)(wordRect.y())] = wordRect; } } @@ -219,21 +222,21 @@ void ChatViewSearchController::updateHighlights(ChatLine *line) { deleteAll = true; } - + foreach(QGraphicsItem *child, line->childItems()) { SearchHighlightItem *highlightItem = qgraphicsitem_cast(child); if(!highlightItem) continue; - if(!deleteAll && wordRects.contains(highlightItem->pos().x()) && wordRects[highlightItem->pos().x()].contains(highlightItem->pos().y())) { - QRectF &wordRect = wordRects[highlightItem->pos().x()][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 { int pos = _highlightItems.indexOf(highlightItem); if(pos == _currentHighlight) { - highlightPrev(); + highlightPrev(); } else if (pos < _currentHighlight) { - _currentHighlight--; + _currentHighlight--; } _highlightItems.removeAt(pos); @@ -245,10 +248,10 @@ void ChatViewSearchController::updateHighlights(ChatLine *line) { void ChatViewSearchController::highlightLine(ChatLine *line) { QList checkItems; if(_searchSenders) - checkItems << &(line->item(MessageModel::SenderColumn)); + checkItems << line->item(MessageModel::SenderColumn); if(_searchMsgs) - checkItems << &(line->item(MessageModel::ContentsColumn)); + checkItems << line->item(MessageModel::ContentsColumn); foreach(ChatItem *item, checkItems) { foreach(QRectF wordRect, item->findWords(searchString(), caseSensitive())) { @@ -283,13 +286,13 @@ void ChatViewSearchController::repositionHighlights(ChatLine *line) { QList wordPos; if(_searchSenders) { - foreach(QRectF wordRect, line->senderItem().findWords(searchString(), caseSensitive())) { - wordPos << QPointF(wordRect.x() + line->senderItem().x(), wordRect.y()); + 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())) { - wordPos << QPointF(wordRect.x() + line->contentsItem().x(), wordRect.y()); + foreach(QRectF wordRect, line->contentsItem()->findWords(searchString(), caseSensitive())) { + wordPos << QPointF(wordRect.x() + line->contentsItem()->x(), wordRect.y()); } } @@ -360,7 +363,7 @@ SearchHighlightItem::SearchHighlightItem(QRectF wordRect, QGraphicsItem *parent) : QObject(), QGraphicsItem(parent), _highlighted(false), - _alpha(100), + _alpha(70), _timeLine(150) { setPos(wordRect.x(), wordRect.y()); @@ -384,7 +387,7 @@ void SearchHighlightItem::setHighlighted(bool highlighted) { } void SearchHighlightItem::updateHighlight(qreal value) { - _alpha = 100 + 155 * value; + _alpha = 70 + (int)(80 * value); update(); } @@ -392,7 +395,7 @@ void SearchHighlightItem::paint(QPainter *painter, const QStyleOptionGraphicsIte Q_UNUSED(option); Q_UNUSED(widget); - painter->setPen(QPen(QColor(0, 0, 0, _alpha), 1.5)); + painter->setPen(QPen(QColor(0, 0, 0), 1.5)); painter->setBrush(QColor(254, 237, 45, _alpha)); painter->setRenderHints(QPainter::Antialiasing); qreal radius = boundingRect().height() * 0.30;