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:
parent
b705ac8060
commit
6de1173c17
|
@ -811,12 +811,22 @@ void GenericChatForm::onLoadHistory()
|
||||||
{
|
{
|
||||||
LoadHistoryDialog dlg(&chatLog);
|
LoadHistoryDialog dlg(&chatLog);
|
||||||
if (dlg.exec()) {
|
if (dlg.exec()) {
|
||||||
QDateTime time = dlg.getFromDate();
|
|
||||||
auto idx = firstItemAfterDate(dlg.getFromDate().date(), chatLog);
|
|
||||||
auto end = ChatLogIdx(idx.get() + 100);
|
|
||||||
chatWidget->clear();
|
chatWidget->clear();
|
||||||
messages.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()
|
void GenericChatForm::loadHistoryLower()
|
||||||
{
|
{
|
||||||
auto begin = messages.begin()->first;
|
auto end = messages.begin()->first;
|
||||||
|
auto begin = ChatLogIdx(0);
|
||||||
if (begin.get() > 100) {
|
if (end.get() > 100) {
|
||||||
begin = ChatLogIdx(begin.get() - 100);
|
begin = ChatLogIdx(end.get() - 100);
|
||||||
} else {
|
|
||||||
begin = ChatLogIdx(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderMessages(begin, chatLog.getNextIdx());
|
renderMessages(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatForm::loadHistoryUpper()
|
void GenericChatForm::loadHistoryUpper()
|
||||||
|
|
|
@ -62,6 +62,15 @@ QDateTime LoadHistoryDialog::getFromDate()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType()
|
||||||
|
{
|
||||||
|
if (ui->loadTypeComboBox->currentIndex() == 0) {
|
||||||
|
return LoadType::from;
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoadType::to;
|
||||||
|
}
|
||||||
|
|
||||||
void LoadHistoryDialog::setTitle(const QString& title)
|
void LoadHistoryDialog::setTitle(const QString& title)
|
||||||
{
|
{
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
|
|
|
@ -34,11 +34,17 @@ class LoadHistoryDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum LoadType {
|
||||||
|
from,
|
||||||
|
to
|
||||||
|
};
|
||||||
|
|
||||||
explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr);
|
explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr);
|
||||||
explicit LoadHistoryDialog(QWidget* parent = nullptr);
|
explicit LoadHistoryDialog(QWidget* parent = nullptr);
|
||||||
~LoadHistoryDialog();
|
~LoadHistoryDialog();
|
||||||
|
|
||||||
QDateTime getFromDate();
|
QDateTime getFromDate();
|
||||||
|
LoadType getLoadType();
|
||||||
void setTitle(const QString& title);
|
void setTitle(const QString& title);
|
||||||
void setInfoLabel(const QString& info);
|
void setInfoLabel(const QString& info);
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>347</width>
|
<width>410</width>
|
||||||
<height>264</height>
|
<height>332</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -16,22 +16,60 @@
|
||||||
<property name="modal">
|
<property name="modal">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="fromLabel">
|
<widget class="QLabel" name="fromLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Load history from:</string>
|
<string>Load history</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<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 row="1" column="0">
|
||||||
<widget class="QCalendarWidget" name="fromDate">
|
<widget class="QCalendarWidget" name="fromDate">
|
||||||
<property name="gridVisible">
|
<property name="gridVisible">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="2" column="0">
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user