Browse Source

revert(chatlog): "edit position chat after load history"

This reverts commit c2d5b422b3.
reviewable/pr6374/r3
Anthony Bilinski 5 years ago
parent
commit
b9cf7f428d
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 14
      src/chatlog/chatlog.cpp
  2. 2
      src/chatlog/chatlog.h
  3. 60
      src/widget/form/genericchatform.cpp
  4. 2
      src/widget/form/genericchatform.h

14
src/chatlog/chatlog.cpp

@ -684,7 +684,7 @@ void ChatLog::forceRelayout() @@ -684,7 +684,7 @@ void ChatLog::forceRelayout()
startResizeWorker();
}
void ChatLog::checkVisibility(bool causedWheelEvent)
void ChatLog::checkVisibility(bool causedByScroll)
{
if (lines.empty())
return;
@ -729,10 +729,10 @@ void ChatLog::checkVisibility(bool causedWheelEvent) @@ -729,10 +729,10 @@ void ChatLog::checkVisibility(bool causedWheelEvent)
emit firstVisibleLineChanged(lastLineBeforeVisible, visibleLines.at(0));
}
if (causedWheelEvent) {
if (causedByScroll) {
if (lowerBound != lines.cend() && lowerBound->get()->row == 0) {
emit loadHistoryLower();
} else if (upperBound == lines.cend()) {
} else if (upperBound != lines.cend() && upperBound->get()->row >= lines.size() - 10) {
emit loadHistoryUpper();
}
}
@ -741,7 +741,7 @@ void ChatLog::checkVisibility(bool causedWheelEvent) @@ -741,7 +741,7 @@ void ChatLog::checkVisibility(bool causedWheelEvent)
void ChatLog::scrollContentsBy(int dx, int dy)
{
QGraphicsView::scrollContentsBy(dx, dy);
checkVisibility();
checkVisibility(true);
}
void ChatLog::resizeEvent(QResizeEvent* ev)
@ -937,12 +937,6 @@ void ChatLog::focusOutEvent(QFocusEvent* ev) @@ -937,12 +937,6 @@ void ChatLog::focusOutEvent(QFocusEvent* ev)
}
}
void ChatLog::wheelEvent(QWheelEvent *event)
{
QGraphicsView::wheelEvent(event);
checkVisibility(true);
}
void ChatLog::retranslateUi()
{
copyAction->setText(tr("Copy"));

2
src/chatlog/chatlog.h

@ -92,7 +92,7 @@ protected: @@ -92,7 +92,7 @@ protected:
void reposition(int start, int end, qreal deltaY);
void updateSceneRect();
void checkVisibility(bool causedWheelEvent = false);
void checkVisibility(bool causedByScroll = false);
void scrollToBottom();
void startResizeWorker();

60
src/widget/form/genericchatform.cpp

@ -688,47 +688,16 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog @@ -688,47 +688,16 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog
chatWidget->clear();
messages.clear();
if (type == LoadHistoryDialog::from) {
loadHistoryFrom(time);
auto msg = messages.cbegin()->second;
chatWidget->scrollToLine(msg);
} else {
loadHistoryTo(time);
}
}
void GenericChatForm::loadHistoryTo(const QDateTime &time)
{
auto end = chatLog.getFirstIdx();
if (time.isNull()) {
end = messages.begin()->first;
} else {
end = firstItemAfterDate(time.date(), chatLog);
}
auto begin = chatLog.getFirstIdx();
if (end - begin > DEF_NUM_MSG_TO_LOAD) {
begin = end - DEF_NUM_MSG_TO_LOAD;
}
auto begin = firstItemAfterDate(time.date(), chatLog);
auto end = ChatLogIdx(begin.get() + 1);
renderMessages(begin, end);
}
void GenericChatForm::loadHistoryFrom(const QDateTime &time)
{
auto begin = chatLog.getFirstIdx();
if (time.isNull()) {
begin = messages.rbegin()->first;
if (type == LoadHistoryDialog::from) {
loadHistoryUpper();
} else {
begin = firstItemAfterDate(time.date(), chatLog);
loadHistoryLower();
}
int add = 100;
if (begin.get() + 100 > chatLog.getNextIdx().get()) {
add = chatLog.getNextIdx().get() - (begin.get() + 100);
}
auto end = ChatLogIdx(begin.get() + add);
renderMessages(begin, end);
}
@ -1104,14 +1073,25 @@ void GenericChatForm::goToCurrentDate() @@ -1104,14 +1073,25 @@ void GenericChatForm::goToCurrentDate()
void GenericChatForm::loadHistoryLower()
{
loadHistoryTo(QDateTime());
auto end = messages.begin()->first;
auto begin = ChatLogIdx(0);
if (end.get() > 100) {
begin = ChatLogIdx(end.get() - 100);
}
renderMessages(begin, end);
}
void GenericChatForm::loadHistoryUpper()
{
auto msg = messages.crbegin()->second;
loadHistoryFrom(QDateTime());
chatWidget->scrollToLine(msg);
auto begin = messages.rbegin()->first;
int add = 100;
if (begin.get() + 100 > chatLog.getNextIdx().get()) {
add = chatLog.getNextIdx().get() - (begin.get() + 100);
}
auto end = ChatLogIdx(begin.get() + add);
renderMessages(begin, end);
}
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& prevLine, const ChatLine::Ptr& topLine)

2
src/widget/form/genericchatform.h

@ -129,8 +129,6 @@ private: @@ -129,8 +129,6 @@ private:
void addSystemDateMessage(const QDate& date);
QDateTime getTime(const ChatLine::Ptr& chatLine) const;
void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type);
void loadHistoryTo(const QDateTime& time);
void loadHistoryFrom(const QDateTime& time);
void renderItem(const ChatLogItem &item, bool hideName, bool colorizeNames, ChatMessage::Ptr &chatMessage);
void renderFile(QString displayName, ToxFile file, bool isSelf, QDateTime timestamp, ChatMessage::Ptr &chatMessage);

Loading…
Cancel
Save