mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
revert(chatlog): "edit load history when scrolling"
This reverts commit 0a9e72020e
.
This commit is contained in:
parent
af3e0183b6
commit
b0b74cfe92
|
@ -372,7 +372,6 @@ void ChatLog::reposition(int start, int end, qreal deltaY)
|
|||
|
||||
void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
|
||||
{
|
||||
numRemove = 0;
|
||||
if (!l.get())
|
||||
return;
|
||||
|
||||
|
@ -396,14 +395,9 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
|
|||
|
||||
void ChatLog::insertChatlineAtBottom(const QList<ChatLine::Ptr>& newLines)
|
||||
{
|
||||
numRemove = 0;
|
||||
if (newLines.isEmpty())
|
||||
return;
|
||||
|
||||
if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) {
|
||||
removeFirsts(DEF_NUM_MSG_TO_LOAD);
|
||||
}
|
||||
|
||||
for (ChatLine::Ptr l : newLines) {
|
||||
l->setRow(lines.size());
|
||||
l->addToScene(scene);
|
||||
|
@ -412,17 +406,11 @@ void ChatLog::insertChatlineAtBottom(const QList<ChatLine::Ptr>& newLines)
|
|||
}
|
||||
|
||||
layout(lines.last()->getRow(), lines.size(), useableWidth());
|
||||
|
||||
if (visibleLines.size() > 1) {
|
||||
startResizeWorker(visibleLines[1]);
|
||||
} else {
|
||||
startResizeWorker();
|
||||
}
|
||||
startResizeWorker();
|
||||
}
|
||||
|
||||
void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
|
||||
{
|
||||
numRemove = 0;
|
||||
if (!l.get())
|
||||
return;
|
||||
|
||||
|
@ -431,7 +419,6 @@ void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
|
|||
|
||||
void ChatLog::insertChatlinesOnTop(const QList<ChatLine::Ptr>& newLines)
|
||||
{
|
||||
numRemove = 0;
|
||||
if (newLines.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -451,10 +438,6 @@ void ChatLog::insertChatlinesOnTop(const QList<ChatLine::Ptr>& newLines)
|
|||
combLines.push_back(l);
|
||||
}
|
||||
|
||||
if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) {
|
||||
removeLasts(DEF_NUM_MSG_TO_LOAD);
|
||||
}
|
||||
|
||||
// add the old lines
|
||||
for (ChatLine::Ptr l : lines) {
|
||||
l->setRow(i++);
|
||||
|
@ -468,12 +451,7 @@ void ChatLog::insertChatlinesOnTop(const QList<ChatLine::Ptr>& newLines)
|
|||
scene->setItemIndexMethod(oldIndexMeth);
|
||||
|
||||
// redo layout
|
||||
if (visibleLines.size() > 1) {
|
||||
startResizeWorker(visibleLines[1]);
|
||||
} else {
|
||||
startResizeWorker();
|
||||
}
|
||||
|
||||
startResizeWorker();
|
||||
}
|
||||
|
||||
bool ChatLog::stickToBottom() const
|
||||
|
@ -487,22 +465,19 @@ void ChatLog::scrollToBottom()
|
|||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
||||
|
||||
void ChatLog::startResizeWorker(ChatLine::Ptr anchorLine)
|
||||
void ChatLog::startResizeWorker()
|
||||
{
|
||||
if (lines.empty()) {
|
||||
isScroll = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// (re)start the worker
|
||||
if (!workerTimer->isActive()) {
|
||||
// these values must not be reevaluated while the worker is running
|
||||
if (anchorLine) {
|
||||
workerAnchorLine = anchorLine;
|
||||
workerStb = false;
|
||||
} else {
|
||||
workerStb = stickToBottom();
|
||||
}
|
||||
workerStb = stickToBottom();
|
||||
|
||||
if (!visibleLines.empty())
|
||||
workerAnchorLine = visibleLines.first();
|
||||
}
|
||||
|
||||
// switch to busy scene displaying the busy notification if there is a lot
|
||||
|
@ -667,13 +642,8 @@ void ChatLog::scrollToLine(ChatLine::Ptr line)
|
|||
if (!line.get())
|
||||
return;
|
||||
|
||||
if (workerTimer->isActive()) {
|
||||
workerAnchorLine = line;
|
||||
workerStb = false;
|
||||
} else {
|
||||
updateSceneRect();
|
||||
verticalScrollBar()->setValue(line->sceneBoundingRect().top()); // NOTE: start here
|
||||
}
|
||||
updateSceneRect();
|
||||
verticalScrollBar()->setValue(line->sceneBoundingRect().top());
|
||||
}
|
||||
|
||||
void ChatLog::selectAll()
|
||||
|
@ -717,7 +687,6 @@ void ChatLog::removeFirsts(const int num)
|
|||
{
|
||||
if (lines.size() > num) {
|
||||
lines.erase(lines.begin(), lines.begin()+num);
|
||||
numRemove = num;
|
||||
} else {
|
||||
lines.clear();
|
||||
}
|
||||
|
@ -733,22 +702,11 @@ void ChatLog::removeLasts(const int num)
|
|||
{
|
||||
if (lines.size() > num) {
|
||||
lines.erase(lines.end()-num, lines.end());
|
||||
numRemove = num;
|
||||
} else {
|
||||
lines.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ChatLog::setScroll(const bool scroll)
|
||||
{
|
||||
isScroll = scroll;
|
||||
}
|
||||
|
||||
int ChatLog::getNumRemove() const
|
||||
{
|
||||
return numRemove;
|
||||
}
|
||||
|
||||
void ChatLog::forceRelayout()
|
||||
{
|
||||
startResizeWorker();
|
||||
|
@ -801,7 +759,6 @@ void ChatLog::checkVisibility(bool causedWheelEvent)
|
|||
}
|
||||
|
||||
if (causedWheelEvent) {
|
||||
qDebug() << "causedWheelEvent";
|
||||
if (lowerBound != lines.cend() && lowerBound->get()->row == 0) {
|
||||
emit loadHistoryLower();
|
||||
} else if (upperBound == lines.cend()) {
|
||||
|
@ -945,7 +902,6 @@ void ChatLog::onWorkerTimeout()
|
|||
// hidden during busy screen
|
||||
verticalScrollBar()->show();
|
||||
|
||||
isScroll = true;
|
||||
emit workerTimeoutFinished();
|
||||
}
|
||||
}
|
||||
|
@ -1013,10 +969,6 @@ void ChatLog::focusOutEvent(QFocusEvent* ev)
|
|||
|
||||
void ChatLog::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (!isScroll) {
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView::wheelEvent(event);
|
||||
checkVisibility(true);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ class ChatLineContent;
|
|||
struct ToxFile;
|
||||
|
||||
static const size_t DEF_NUM_MSG_TO_LOAD = 100;
|
||||
|
||||
class ChatLog : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -58,8 +57,6 @@ public:
|
|||
void fontChanged(const QFont& font);
|
||||
void removeFirsts(const int num);
|
||||
void removeLasts(const int num);
|
||||
void setScroll(const bool scroll);
|
||||
int getNumRemove() const;
|
||||
|
||||
QString getSelectedText() const;
|
||||
|
||||
|
@ -99,7 +96,7 @@ protected:
|
|||
void updateSceneRect();
|
||||
void checkVisibility(bool causedWheelEvent = false);
|
||||
void scrollToBottom();
|
||||
void startResizeWorker(ChatLine::Ptr anchorLine = nullptr);
|
||||
void startResizeWorker();
|
||||
|
||||
void mouseDoubleClickEvent(QMouseEvent* ev) final;
|
||||
void mousePressEvent(QMouseEvent* ev) final;
|
||||
|
@ -170,7 +167,6 @@ private:
|
|||
int clickCount = 0;
|
||||
QPoint lastClickPos;
|
||||
Qt::MouseButton lastClickButton;
|
||||
bool isScroll{true};
|
||||
|
||||
// worker vars
|
||||
int workerLastIndex = 0;
|
||||
|
@ -180,7 +176,4 @@ private:
|
|||
// layout
|
||||
QMargins margins = QMargins(10, 10, 10, 10);
|
||||
qreal lineSpacing = 5.0f;
|
||||
|
||||
int numRemove{0};
|
||||
const int maxMessages{300};
|
||||
};
|
||||
|
|
|
@ -96,10 +96,9 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co
|
|||
|
||||
// NOTE: this has to be done _after_ sending all sent messages since initial
|
||||
// state of the message has to be marked according to our dispatch state
|
||||
constexpr auto defaultNumMessagesToLoad = 100;
|
||||
auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < defaultNumMessagesToLoad
|
||||
auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < DEF_NUM_MSG_TO_LOAD
|
||||
? ChatLogIdx(0)
|
||||
: sessionChatLog.getFirstIdx() - defaultNumMessagesToLoad;
|
||||
: sessionChatLog.getFirstIdx() - DEF_NUM_MSG_TO_LOAD;
|
||||
|
||||
if (canUseHistory()) {
|
||||
loadHistoryIntoSessionChatLog(firstChatLogIdx);
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
static const auto DEF_NUM_MSG_TO_LOAD = 100;
|
||||
|
||||
using ChatLogIdx =
|
||||
NamedType<size_t, struct ChatLogIdxTag, Orderable, UnderlyingAddable, UnitlessDifferencable, Incrementable>;
|
||||
Q_DECLARE_METATYPE(ChatLogIdx)
|
||||
|
|
|
@ -53,8 +53,6 @@
|
|||
#include <QStringBuilder>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#ifdef SPELL_CHECKING
|
||||
#include <KF5/SonnetUi/sonnet/spellcheckdecorator.h>
|
||||
#endif
|
||||
|
@ -693,7 +691,6 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog
|
|||
if (type == LoadHistoryDialog::from) {
|
||||
loadHistoryFrom(time);
|
||||
auto msg = messages.cbegin()->second;
|
||||
chatWidget->setScroll(true);
|
||||
chatWidget->scrollToLine(msg);
|
||||
} else {
|
||||
loadHistoryTo(time);
|
||||
|
@ -702,10 +699,15 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog
|
|||
|
||||
void GenericChatForm::loadHistoryTo(const QDateTime &time)
|
||||
{
|
||||
chatWidget->setScroll(false);
|
||||
auto end = chatLog.getFirstIdx();
|
||||
if (time.isNull()) {
|
||||
end = messages.begin()->first;
|
||||
if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) {
|
||||
end = ChatLogIdx(messages.rbegin()->first.get() - DEF_NUM_MSG_TO_LOAD);
|
||||
chatWidget->removeLasts(DEF_NUM_MSG_TO_LOAD);
|
||||
removeLastsMessages(DEF_NUM_MSG_TO_LOAD);
|
||||
} else {
|
||||
end = messages.begin()->first;
|
||||
}
|
||||
} else {
|
||||
end = firstItemAfterDate(time.date(), chatLog);
|
||||
}
|
||||
|
@ -715,27 +717,28 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
|
|||
begin = end - DEF_NUM_MSG_TO_LOAD;
|
||||
}
|
||||
|
||||
if (begin != end) {
|
||||
renderMessages(begin, end);
|
||||
} else {
|
||||
chatWidget->setScroll(true);
|
||||
}
|
||||
renderMessages(begin, end);
|
||||
}
|
||||
|
||||
void GenericChatForm::loadHistoryFrom(const QDateTime &time)
|
||||
{
|
||||
chatWidget->setScroll(false);
|
||||
auto begin = chatLog.getFirstIdx();
|
||||
if (time.isNull()) {
|
||||
begin = messages.rbegin()->first;
|
||||
if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) {
|
||||
begin = ChatLogIdx(messages.rbegin()->first.get() + DEF_NUM_MSG_TO_LOAD);
|
||||
chatWidget->removeFirsts(DEF_NUM_MSG_TO_LOAD);
|
||||
removeFirstsMessages(DEF_NUM_MSG_TO_LOAD);
|
||||
} else {
|
||||
begin = messages.rbegin()->first;
|
||||
}
|
||||
|
||||
} else {
|
||||
begin = firstItemAfterDate(time.date(), chatLog);
|
||||
}
|
||||
|
||||
int add = DEF_NUM_MSG_TO_LOAD;
|
||||
if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) {
|
||||
auto aTest = chatLog.getNextIdx().get();
|
||||
add = chatLog.getNextIdx().get() - begin.get();
|
||||
add = chatLog.getNextIdx().get() - (begin.get() + DEF_NUM_MSG_TO_LOAD);
|
||||
}
|
||||
auto end = ChatLogIdx(begin.get() + add);
|
||||
renderMessages(begin, end);
|
||||
|
@ -1070,6 +1073,10 @@ void GenericChatForm::renderItem(const ChatLogItem& item, bool hideName, bool co
|
|||
|
||||
void GenericChatForm::renderMessage(ChatLogIdx idx)
|
||||
{
|
||||
if (chatWidget->getLines().size() >= maxMessages) {
|
||||
chatWidget->removeFirsts(optimalRemove);
|
||||
removeFirstsMessages(optimalRemove);
|
||||
}
|
||||
renderMessages(idx, idx + 1);
|
||||
}
|
||||
|
||||
|
@ -1096,13 +1103,8 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end,
|
|||
}
|
||||
}
|
||||
|
||||
if (beforeLines.isEmpty() && afterLines.isEmpty()) {
|
||||
chatWidget->setScroll(true);
|
||||
}
|
||||
|
||||
chatWidget->insertChatlineAtBottom(afterLines);
|
||||
if (chatWidget->getNumRemove()) {
|
||||
removeFirstsMessages(chatWidget->getNumRemove());
|
||||
for (auto const& line : afterLines) {
|
||||
chatWidget->insertChatlineAtBottom(line);
|
||||
}
|
||||
|
||||
if (!beforeLines.empty()) {
|
||||
|
@ -1119,9 +1121,6 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end,
|
|||
}
|
||||
|
||||
chatWidget->insertChatlinesOnTop(beforeLines);
|
||||
if (chatWidget->getNumRemove()) {
|
||||
removeLastsMessages(chatWidget->getNumRemove());
|
||||
}
|
||||
} else if (onCompletion) {
|
||||
onCompletion();
|
||||
}
|
||||
|
|
|
@ -192,4 +192,8 @@ protected:
|
|||
SearchPos searchPos;
|
||||
std::map<ChatLogIdx, ChatMessage::Ptr> messages;
|
||||
bool colorizeNames = false;
|
||||
|
||||
private:
|
||||
const int maxMessages{300};
|
||||
const int optimalRemove{50};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user