1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

ChatLog::insertChatlineOnTop: overload taking a list

This commit is contained in:
krepa098 2015-01-05 10:51:01 +01:00
parent c7fe34c077
commit 77fe3f7256
3 changed files with 32 additions and 4 deletions

View File

@ -399,6 +399,34 @@ void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
checkVisibility(); checkVisibility();
} }
void ChatLog::insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines)
{
if(newLines.isEmpty())
return;
//move all lines down by n
int n = newLines.size();
for(ChatLine::Ptr l : lines)
l->setRowIndex(l->getRowIndex() + n);
//add the new line
for(ChatLine::Ptr l : newLines)
{
l->addToScene(scene);
l->setRowIndex(--n);
lines.prepend(l);
}
//full refresh is required
layout(0, lines.size(), useableWidth());
updateSceneRect();
if(stickToBtm)
scrollToBottom();
checkVisibility();
}
bool ChatLog::stickToBottom() bool ChatLog::stickToBottom()
{ {
return verticalScrollBar()->value() == verticalScrollBar()->maximum(); return verticalScrollBar()->value() == verticalScrollBar()->maximum();
@ -521,7 +549,7 @@ void ChatLog::checkVisibility()
visibleLines = newVisibleLines; visibleLines = newVisibleLines;
// assure order // enforce order
std::sort(visibleLines.begin(), visibleLines.end(), [](const ChatLine::Ptr lhs, const ChatLine::Ptr rhs) std::sort(visibleLines.begin(), visibleLines.end(), [](const ChatLine::Ptr lhs, const ChatLine::Ptr rhs)
{ {
return lhs->getRowIndex() < rhs->getRowIndex(); return lhs->getRowIndex() < rhs->getRowIndex();

View File

@ -39,6 +39,7 @@ public:
void insertChatlineAtBottom(ChatLine::Ptr l); void insertChatlineAtBottom(ChatLine::Ptr l);
void insertChatlineOnTop(ChatLine::Ptr l); void insertChatlineOnTop(ChatLine::Ptr l);
void insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines);
void clearSelection(); void clearSelection();
void clear(); void clear();
void copySelectedText() const; void copySelectedText() const;

View File

@ -704,7 +704,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
ToxID storedPrevId = previousId; ToxID storedPrevId = previousId;
ToxID prevId; ToxID prevId;
QList<ChatMessage::Ptr> historyMessages; QList<ChatLine::Ptr> historyMessages;
QDate lastDate(1,0,0); QDate lastDate(1,0,0);
for (const auto &it : msgs) for (const auto &it : msgs)
@ -758,8 +758,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
earliestMessage = since; earliestMessage = since;
for(ChatMessage::Ptr m : historyMessages) chatWidget->insertChatlineOnTop(historyMessages);
chatWidget->insertChatlineOnTop(m);
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos; savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
chatWidget->verticalScrollBar()->setValue(savedSliderPos); chatWidget->verticalScrollBar()->setValue(savedSliderPos);