Browse Source

optimized ChatLog::getContentFromPos

pull/974/head
krepa098 11 years ago
parent
commit
1bf0898121
  1. 11
      src/chatlog/chatline.cpp
  2. 1
      src/chatlog/chatline.h
  3. 22
      src/chatlog/chatlog.cpp

11
src/chatlog/chatline.cpp

@ -72,6 +72,17 @@ ChatLineContent *ChatLine::getContent(int col) const @@ -72,6 +72,17 @@ ChatLineContent *ChatLine::getContent(int col) const
return nullptr;
}
ChatLineContent *ChatLine::getContent(QPointF scenePos) const
{
for(ChatLineContent* c: content)
{
if(c->sceneBoundingRect().contains(scenePos))
return c;
}
return nullptr;
}
void ChatLine::removeFromScene()
{
for(ChatLineContent* c : content)

1
src/chatlog/chatline.h

@ -76,6 +76,7 @@ public: @@ -76,6 +76,7 @@ public:
int getColumnCount();
int getRowIndex() const;
ChatLineContent* getContent(int col) const;
ChatLineContent* getContent(QPointF scenePos) const;
bool isOverSelection(QPointF scenePos);

22
src/chatlog/chatlog.cpp

@ -284,10 +284,26 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev) @@ -284,10 +284,26 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
{
QGraphicsItem* item = scene->itemAt(scenePos, QTransform());
if(lines.empty())
return nullptr;
QList<ChatLine::Ptr>::const_iterator upperBound;
upperBound = std::upper_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const qreal lhs, const ChatLine::Ptr rhs)
{
return lhs < rhs->boundingSceneRect().bottom();
});
QList<ChatLine::Ptr>::const_iterator lowerBound;
lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), [](const ChatLine::Ptr lhs, const qreal rhs)
{
return lhs->boundingSceneRect().top() < rhs;
});
if(item && item->type() == ChatLineContent::ChatLineContentType)
return static_cast<ChatLineContent*>(item);
for(auto itr = upperBound; itr != lowerBound; ++itr)
{
if((*itr)->boundingSceneRect().contains(scenePos))
return (*itr)->getContent(scenePos);
}
return nullptr;
}

Loading…
Cancel
Save