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

revert(chatlog): "edit load history in search"

This reverts commit 8c4b1e00a1.
This commit is contained in:
Anthony Bilinski 2020-04-05 01:19:05 -07:00
parent 5efb0ba020
commit 8e03aa4b17
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
11 changed files with 51 additions and 72 deletions

View File

@ -66,11 +66,9 @@ void Text::selectText(const QString& txt, const std::pair<int, int>& point)
return;
}
selectCursor = doc->find(txt, point.first);
selectPoint = point;
auto cursor = doc->find(txt, point.first);
regenerate();
update();
selectText(cursor, point);
}
void Text::selectText(const QRegularExpression &exp, const std::pair<int, int>& point)
@ -81,20 +79,14 @@ void Text::selectText(const QRegularExpression &exp, const std::pair<int, int>&
return;
}
selectCursor = doc->find(exp, point.first);
selectPoint = point;
auto cursor = doc->find(exp, point.first);
regenerate();
update();
selectText(cursor, point);
}
void Text::deselectText()
{
dirty = true;
selectCursor = QTextCursor();
selectPoint = {0, 0};
regenerate();
update();
}
@ -363,10 +355,6 @@ void Text::regenerate()
dirty = false;
}
if (!selectCursor.isNull()) {
selectText(selectCursor, selectPoint);
}
// if we are not visible -> free mem
if (!keepInMemory)
freeResources();
@ -474,6 +462,9 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
QTextCharFormat format;
format.setBackground(QBrush(Style::getColor(Style::SearchHighlighted)));
cursor.mergeCharFormat(format);
regenerate();
update();
}
}

View File

@ -24,7 +24,6 @@
#include "src/widget/style.h"
#include <QFont>
#include <QTextCursor>
class QTextDocument;
@ -111,9 +110,6 @@ private:
TextType textType;
QColor color;
QColor customColor;
QTextCursor selectCursor;
std::pair<int, int> selectPoint{0, 0};
};
#endif // TEXT_H

View File

@ -865,14 +865,14 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi
break;
}
QDateTime time = from;
QDateTime date = from;
if (!time.isValid()) {
time = QDateTime::currentDateTime();
if (!date.isValid()) {
date = QDateTime::currentDateTime();
}
if (parameter.period == PeriodSearch::AfterDate || parameter.period == PeriodSearch::BeforeDate) {
time = parameter.time;
date = QDateTime(parameter.date);
}
QString period;
@ -882,15 +882,15 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi
break;
case PeriodSearch::AfterDate:
period = QStringLiteral("AND timestamp > '%1' ORDER BY timestamp ASC LIMIT 1;")
.arg(time.toMSecsSinceEpoch());
.arg(date.toMSecsSinceEpoch());
break;
case PeriodSearch::BeforeDate:
period = QStringLiteral("AND timestamp < '%1' ORDER BY timestamp DESC LIMIT 1;")
.arg(time.toMSecsSinceEpoch());
.arg(date.toMSecsSinceEpoch());
break;
default:
period = QStringLiteral("AND timestamp < '%1' ORDER BY timestamp DESC LIMIT 1;")
.arg(time.toMSecsSinceEpoch());
.arg(date.toMSecsSinceEpoch());
break;
}

View File

@ -37,6 +37,7 @@
#include "src/widget/contentlayout.h"
#include "src/widget/emoticonswidget.h"
#include "src/widget/form/chatform.h"
#include "src/widget/form/loadhistorydialog.h"
#include "src/widget/maskablepixmapwidget.h"
#include "src/widget/searchform.h"
#include "src/widget/style.h"
@ -640,23 +641,6 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const
return QDateTime();
}
void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog::LoadType type)
{
chatWidget->clear();
messages.clear();
auto begin = firstItemAfterDate(time.date(), chatLog);
auto end = ChatLogIdx(begin.get() + 1);
renderMessages(begin, end);
if (type == LoadHistoryDialog::from) {
loadHistoryUpper();
} else {
loadHistoryLower();
}
}
void GenericChatForm::disableSearchText()
{
@ -821,10 +805,22 @@ void GenericChatForm::onLoadHistory()
{
LoadHistoryDialog dlg(&chatLog);
if (dlg.exec()) {
chatWidget->clear();
messages.clear();
QDateTime time = dlg.getFromDate();
auto type = dlg.getLoadType();
loadHistory(time, type);
auto begin = firstItemAfterDate(dlg.getFromDate().date(), chatLog);
auto end = ChatLogIdx(begin.get() + 1);
renderMessages(begin, end);
if (type == LoadHistoryDialog::from) {
loadHistoryUpper();
} else {
loadHistoryLower();
}
}
}
@ -871,12 +867,6 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch
{
disableSearchText();
if (!parameter.time.isNull()) {
LoadHistoryDialog::LoadType type = (parameter.period == PeriodSearch::BeforeDate)
? LoadHistoryDialog::to : LoadHistoryDialog::from;
loadHistory(parameter.time, type);
}
bool bForwardSearch = false;
switch (parameter.period) {
case PeriodSearch::WithTheFirst: {
@ -894,13 +884,13 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch
}
case PeriodSearch::AfterDate: {
bForwardSearch = true;
searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
searchPos.logIdx = firstItemAfterDate(parameter.date, chatLog);
searchPos.numMatches = 0;
break;
}
case PeriodSearch::BeforeDate: {
bForwardSearch = false;
searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
searchPos.logIdx = firstItemAfterDate(parameter.date, chatLog);
searchPos.numMatches = 0;
break;
}
@ -1011,7 +1001,7 @@ void GenericChatForm::loadHistoryLower()
void GenericChatForm::loadHistoryUpper()
{
auto begin = messages.rbegin()->first;
auto begin = messages.end()->first;
int add = 100;
if (begin.get() + 100 > chatLog.getNextIdx().get()) {

View File

@ -23,7 +23,6 @@
#include "src/chatlog/chatmessage.h"
#include "src/core/toxpk.h"
#include "src/model/ichatlog.h"
#include "src/widget/form/loadhistorydialog.h"
#include "src/widget/searchtypes.h"
#include <QMenu>
@ -134,7 +133,6 @@ private:
void retranslateUi();
void addSystemDateMessage(const QDate& date);
QDateTime getTime(const ChatLine::Ptr& chatLine) const;
void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type);
protected:
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,

View File

@ -71,12 +71,14 @@ LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType()
return LoadType::to;
}
void LoadHistoryDialog::turnSearchMode()
void LoadHistoryDialog::setTitle(const QString& title)
{
setWindowTitle(tr("Select Date Dialog"));
ui->fromLabel->setText(tr("Select a date"));
ui->loadTypeComboBox->setVisible(false);
ui->infoLabel->setVisible(false);
setWindowTitle(title);
}
void LoadHistoryDialog::setInfoLabel(const QString& info)
{
ui->fromLabel->setText(info);
}
void LoadHistoryDialog::highlightDates(int year, int month)

View File

@ -45,7 +45,8 @@ public:
QDateTime getFromDate();
LoadType getLoadType();
void turnSearchMode();
void setTitle(const QString& title);
void setInfoLabel(const QString& info);
public slots:
void highlightDates(int year, int month);

View File

@ -41,7 +41,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="infoLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>(about 100 messages are loaded)</string>
</property>

View File

@ -86,7 +86,7 @@ ParameterSearch SearchSettingsForm::getParameterSearch()
break;
}
ps.time = startTime;
ps.date = startDate;
ps.isUpdate = isUpdate;
isUpdate = false;
@ -101,7 +101,7 @@ void SearchSettingsForm::reloadTheme()
void SearchSettingsForm::updateStartDateLabel()
{
ui->startDateLabel->setText(startTime.toString(Settings::getInstance().getDateFormat()));
ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat()));
}
void SearchSettingsForm::setUpdate(const bool isUpdate)
@ -119,8 +119,8 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
ui->choiceDateButton->setProperty("state", QStringLiteral("green"));
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
if (startTime.isNull()) {
startTime = QDateTime::currentDateTime();
if (startDate.isNull()) {
startDate = QDate::currentDate();
updateStartDateLabel();
}
@ -162,9 +162,10 @@ void SearchSettingsForm::onRegularClicked(const bool checked)
void SearchSettingsForm::onChoiceDate()
{
LoadHistoryDialog dlg;
dlg.turnSearchMode();
dlg.setTitle(tr("Select Date Dialog"));
dlg.setInfoLabel(tr("Select a date"));
if (dlg.exec()) {
startTime = dlg.getFromDate();
startDate = dlg.getFromDate().date();
updateStartDateLabel();
}

View File

@ -40,7 +40,7 @@ public:
private:
Ui::SearchSettingsForm *ui;
QDateTime startTime;
QDate startDate;
bool isUpdate{false};
void updateStartDateLabel();

View File

@ -48,13 +48,13 @@ enum class SearchDirection {
struct ParameterSearch {
FilterSearch filter{FilterSearch::None};
PeriodSearch period{PeriodSearch::None};
QDateTime time;
QDate date;
bool isUpdate{false};
bool operator ==(const ParameterSearch& other) {
return filter == other.filter &&
period == other.period &&
time == other.time;
date == other.date;
}
bool operator !=(const ParameterSearch& other) {