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

feat: edit function "Load chat history"

This commit is contained in:
TriKriSta 2019-05-20 00:29:09 +03:00
parent b705ac8060
commit 6de1173c17
4 changed files with 83 additions and 22 deletions

View File

@ -811,12 +811,22 @@ void GenericChatForm::onLoadHistory()
{
LoadHistoryDialog dlg(&chatLog);
if (dlg.exec()) {
QDateTime time = dlg.getFromDate();
auto idx = firstItemAfterDate(dlg.getFromDate().date(), chatLog);
auto end = ChatLogIdx(idx.get() + 100);
chatWidget->clear();
messages.clear();
renderMessages(idx, end);
QDateTime time = dlg.getFromDate();
auto type = dlg.getLoadType();
auto begin = firstItemAfterDate(dlg.getFromDate().date(), chatLog);
auto end = ChatLogIdx(begin.get() + 1);
renderMessages(begin, end);
if (type == LoadHistoryDialog::from) {
loadHistoryUpper();
} else {
loadHistoryLower();
}
}
}
@ -986,15 +996,13 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end,
void GenericChatForm::loadHistoryLower()
{
auto begin = messages.begin()->first;
if (begin.get() > 100) {
begin = ChatLogIdx(begin.get() - 100);
} else {
begin = ChatLogIdx(0);
auto end = messages.begin()->first;
auto begin = ChatLogIdx(0);
if (end.get() > 100) {
begin = ChatLogIdx(end.get() - 100);
}
renderMessages(begin, chatLog.getNextIdx());
renderMessages(begin, end);
}
void GenericChatForm::loadHistoryUpper()

View File

@ -62,6 +62,15 @@ QDateTime LoadHistoryDialog::getFromDate()
return res;
}
LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType()
{
if (ui->loadTypeComboBox->currentIndex() == 0) {
return LoadType::from;
}
return LoadType::to;
}
void LoadHistoryDialog::setTitle(const QString& title)
{
setWindowTitle(title);

View File

@ -34,11 +34,17 @@ class LoadHistoryDialog : public QDialog
Q_OBJECT
public:
enum LoadType {
from,
to
};
explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr);
explicit LoadHistoryDialog(QWidget* parent = nullptr);
~LoadHistoryDialog();
QDateTime getFromDate();
LoadType getLoadType();
void setTitle(const QString& title);
void setInfoLabel(const QString& info);

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>347</width>
<height>264</height>
<width>410</width>
<height>332</height>
</rect>
</property>
<property name="windowTitle">
@ -16,22 +16,60 @@
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="fromLabel">
<property name="text">
<string>Load history from:</string>
</property>
</widget>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="fromLabel">
<property name="text">
<string>Load history</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="loadTypeComboBox">
<item>
<property name="text">
<string>from</string>
</property>
</item>
<item>
<property name="text">
<string>to</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>(about 100 messages are loaded)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<item row="1" column="0">
<widget class="QCalendarWidget" name="fromDate">
<property name="gridVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>