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

Merge pull request #5777

TriKriSta (2):
      fix: scroll bar stuck to bottom (fix #5755)
      docs: add comments for functions that load history
This commit is contained in:
Anthony Bilinski 2019-08-29 15:09:06 -07:00
commit badef48c3a
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
2 changed files with 36 additions and 4 deletions

View File

@ -654,6 +654,11 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const
return QDateTime();
}
/**
* @brief GenericChatForm::loadHistory load history
* @param time start date
* @param type indicates the direction of loading history
*/
void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog::LoadType type)
{
chatWidget->clear();
@ -669,6 +674,10 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog
}
}
/**
* @brief GenericChatForm::loadHistoryTo load history before to date "time" or before the first "messages" item
* @param time start date
*/
void GenericChatForm::loadHistoryTo(const QDateTime &time)
{
chatWidget->setScroll(false);
@ -695,7 +704,12 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
}
}
void GenericChatForm::loadHistoryFrom(const QDateTime &time)
/**
* @brief GenericChatForm::loadHistoryFrom load history starting from date "time" or from the last "messages" item
* @param time start date
* @return true if function loaded history else false
*/
bool GenericChatForm::loadHistoryFrom(const QDateTime &time)
{
chatWidget->setScroll(false);
auto begin = ChatLogIdx(0);
@ -709,8 +723,19 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time)
if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) {
add = chatLog.getNextIdx().get() - begin.get();
}
// The chatLog.getNextIdx() is usually 1 more than the idx on last "messages" item
// so if we have nothing to load, "add" is equal 1
if (add <= 1) {
chatWidget->setScroll(true);
return false;
}
auto end = ChatLogIdx(begin.get() + add);
renderMessages(begin, end);
return true;
}
void GenericChatForm::removeFirstsMessages(const int num)
@ -1147,11 +1172,17 @@ void GenericChatForm::goToCurrentDate()
renderMessages(begin, end);
}
/**
* @brief GenericChatForm::loadHistoryLower load history after scrolling chatlog before first "messages" item
*/
void GenericChatForm::loadHistoryLower()
{
loadHistoryTo(QDateTime());
}
/**
* @brief GenericChatForm::loadHistoryUpper load history after scrolling chatlog after last "messages" item
*/
void GenericChatForm::loadHistoryUpper()
{
if (messages.empty()) {
@ -1159,8 +1190,9 @@ void GenericChatForm::loadHistoryUpper()
}
auto msg = messages.crbegin()->second;
loadHistoryFrom(QDateTime());
chatWidget->scrollToLine(msg);
if (loadHistoryFrom(QDateTime())) {
chatWidget->scrollToLine(msg);
}
}
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)

View File

@ -137,7 +137,7 @@ private:
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);
bool loadHistoryFrom(const QDateTime& time);
void removeFirstsMessages(const int num);
void removeLastsMessages(const int num);