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

feat: edit load history in search

This commit is contained in:
TriKriSta 2019-05-25 22:16:47 +03:00
parent 6de1173c17
commit 8c4b1e00a1
11 changed files with 72 additions and 53 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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