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:
commit
badef48c3a
|
@ -654,6 +654,11 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const
|
||||||
return QDateTime();
|
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)
|
void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog::LoadType type)
|
||||||
{
|
{
|
||||||
chatWidget->clear();
|
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)
|
void GenericChatForm::loadHistoryTo(const QDateTime &time)
|
||||||
{
|
{
|
||||||
chatWidget->setScroll(false);
|
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);
|
chatWidget->setScroll(false);
|
||||||
auto begin = ChatLogIdx(0);
|
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()) {
|
if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) {
|
||||||
add = chatLog.getNextIdx().get() - begin.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);
|
auto end = ChatLogIdx(begin.get() + add);
|
||||||
|
|
||||||
renderMessages(begin, end);
|
renderMessages(begin, end);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatForm::removeFirstsMessages(const int num)
|
void GenericChatForm::removeFirstsMessages(const int num)
|
||||||
|
@ -1147,11 +1172,17 @@ void GenericChatForm::goToCurrentDate()
|
||||||
renderMessages(begin, end);
|
renderMessages(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GenericChatForm::loadHistoryLower load history after scrolling chatlog before first "messages" item
|
||||||
|
*/
|
||||||
void GenericChatForm::loadHistoryLower()
|
void GenericChatForm::loadHistoryLower()
|
||||||
{
|
{
|
||||||
loadHistoryTo(QDateTime());
|
loadHistoryTo(QDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GenericChatForm::loadHistoryUpper load history after scrolling chatlog after last "messages" item
|
||||||
|
*/
|
||||||
void GenericChatForm::loadHistoryUpper()
|
void GenericChatForm::loadHistoryUpper()
|
||||||
{
|
{
|
||||||
if (messages.empty()) {
|
if (messages.empty()) {
|
||||||
|
@ -1159,9 +1190,10 @@ void GenericChatForm::loadHistoryUpper()
|
||||||
}
|
}
|
||||||
|
|
||||||
auto msg = messages.crbegin()->second;
|
auto msg = messages.crbegin()->second;
|
||||||
loadHistoryFrom(QDateTime());
|
if (loadHistoryFrom(QDateTime())) {
|
||||||
chatWidget->scrollToLine(msg);
|
chatWidget->scrollToLine(msg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)
|
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)
|
||||||
{
|
{
|
||||||
|
|
|
@ -137,7 +137,7 @@ private:
|
||||||
QDateTime getTime(const ChatLine::Ptr& chatLine) const;
|
QDateTime getTime(const ChatLine::Ptr& chatLine) const;
|
||||||
void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type);
|
void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type);
|
||||||
void loadHistoryTo(const QDateTime& time);
|
void loadHistoryTo(const QDateTime& time);
|
||||||
void loadHistoryFrom(const QDateTime& time);
|
bool loadHistoryFrom(const QDateTime& time);
|
||||||
void removeFirstsMessages(const int num);
|
void removeFirstsMessages(const int num);
|
||||||
void removeLastsMessages(const int num);
|
void removeLastsMessages(const int num);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user