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:
parent
c7fe34c077
commit
77fe3f7256
|
@ -399,6 +399,34 @@ void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
|
|||
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()
|
||||
{
|
||||
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
||||
|
@ -521,7 +549,7 @@ void ChatLog::checkVisibility()
|
|||
|
||||
visibleLines = newVisibleLines;
|
||||
|
||||
// assure order
|
||||
// enforce order
|
||||
std::sort(visibleLines.begin(), visibleLines.end(), [](const ChatLine::Ptr lhs, const ChatLine::Ptr rhs)
|
||||
{
|
||||
return lhs->getRowIndex() < rhs->getRowIndex();
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
void insertChatlineAtBottom(ChatLine::Ptr l);
|
||||
void insertChatlineOnTop(ChatLine::Ptr l);
|
||||
void insertChatlineOnTop(const QList<ChatLine::Ptr>& newLines);
|
||||
void clearSelection();
|
||||
void clear();
|
||||
void copySelectedText() const;
|
||||
|
|
|
@ -704,7 +704,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
ToxID storedPrevId = previousId;
|
||||
ToxID prevId;
|
||||
|
||||
QList<ChatMessage::Ptr> historyMessages;
|
||||
QList<ChatLine::Ptr> historyMessages;
|
||||
|
||||
QDate lastDate(1,0,0);
|
||||
for (const auto &it : msgs)
|
||||
|
@ -758,8 +758,7 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
|
||||
earliestMessage = since;
|
||||
|
||||
for(ChatMessage::Ptr m : historyMessages)
|
||||
chatWidget->insertChatlineOnTop(m);
|
||||
chatWidget->insertChatlineOnTop(historyMessages);
|
||||
|
||||
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
||||
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
||||
|
|
Loading…
Reference in New Issue
Block a user