1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
This commit is contained in:
krepa098 2015-01-14 10:34:52 +01:00
parent fb0c372c81
commit bde32d2171

View File

@ -330,19 +330,20 @@ ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
if(lines.empty()) if(lines.empty())
return nullptr; return nullptr;
QVector<ChatLine::Ptr>::const_iterator upperBound; //the first visible line
upperBound = std::upper_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const qreal lhs, const ChatLine::Ptr rhs) auto lowerBound = std::upper_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const qreal lhs, const ChatLine::Ptr rhs)
{ {
return lhs < rhs->boundingSceneRect().bottom(); return lhs < rhs->boundingSceneRect().bottom();
}); });
QVector<ChatLine::Ptr>::const_iterator lowerBound; //the last visible line
lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const ChatLine::Ptr lhs, const qreal rhs) auto upperBound = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const ChatLine::Ptr lhs, const qreal rhs)
{ {
return lhs->boundingSceneRect().top() < rhs; return lhs->boundingSceneRect().top() < rhs;
}); });
for(auto itr = upperBound; itr != lowerBound; ++itr) //find content
for(auto itr = lowerBound; itr != upperBound; ++itr)
{ {
if((*itr)->boundingSceneRect().contains(scenePos)) if((*itr)->boundingSceneRect().contains(scenePos))
return (*itr)->getContent(scenePos); return (*itr)->getContent(scenePos);
@ -582,23 +583,21 @@ void ChatLog::checkVisibility()
updateSceneRect(); updateSceneRect();
// find first visible row // find first visible line
QVector<ChatLine::Ptr>::const_iterator upperBound; auto lowerBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs)
upperBound = std::upper_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), [](const qreal lhs, const ChatLine::Ptr rhs)
{ {
return lhs < rhs->boundingSceneRect().bottom(); return lhs < rhs->boundingSceneRect().bottom();
}); });
// find last visible row // find last visible line
QVector<ChatLine::Ptr>::const_iterator lowerBound; auto upperBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().bottom(), [](const ChatLine::Ptr lhs, const qreal rhs)
lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().bottom(), [](const ChatLine::Ptr lhs, const qreal rhs)
{ {
return lhs->boundingSceneRect().top() < rhs; return lhs->boundingSceneRect().top() < rhs;
}); });
// set visibilty // set visibilty
QList<ChatLine::Ptr> newVisibleLines; QList<ChatLine::Ptr> newVisibleLines;
for(auto itr = upperBound; itr != lowerBound; ++itr) for(auto itr = lowerBound; itr != upperBound; ++itr)
{ {
newVisibleLines.append(*itr); newVisibleLines.append(*itr);
@ -608,6 +607,7 @@ void ChatLog::checkVisibility()
visibleLines.removeOne(*itr); visibleLines.removeOne(*itr);
} }
// these lines are no longer visible
for(ChatLine::Ptr line : visibleLines) for(ChatLine::Ptr line : visibleLines)
line->visibilityChanged(false); line->visibilityChanged(false);
@ -627,7 +627,6 @@ void ChatLog::scrollContentsBy(int dx, int dy)
{ {
QGraphicsView::scrollContentsBy(dx, dy); QGraphicsView::scrollContentsBy(dx, dy);
partialUpdate(); partialUpdate();
checkVisibility();
} }
void ChatLog::resizeEvent(QResizeEvent* ev) void ChatLog::resizeEvent(QResizeEvent* ev)