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

revert(chatlog): "simple edit code"

This reverts commit b807998fe9.
This commit is contained in:
Anthony Bilinski 2020-04-04 22:54:53 -07:00
parent b0b74cfe92
commit bdbf1f61a8
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
7 changed files with 28 additions and 44 deletions

View File

@ -177,9 +177,8 @@ void ChatLog::updateSceneRect()
void ChatLog::layout(int start, int end, qreal width)
{
if (lines.empty()) {
if (lines.empty())
return;
}
qreal h = 0.0;
@ -322,9 +321,8 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
// Much faster than QGraphicsScene::itemAt()!
ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const
{
if (lines.empty()) {
if (lines.empty())
return nullptr;
}
auto itr =
std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), ChatLine::lessThanBSRectBottom);
@ -467,9 +465,8 @@ void ChatLog::scrollToBottom()
void ChatLog::startResizeWorker()
{
if (lines.empty()) {
if (lines.empty())
return;
}
// (re)start the worker
if (!workerTimer->isActive()) {
@ -648,9 +645,8 @@ void ChatLog::scrollToLine(ChatLine::Ptr line)
void ChatLog::selectAll()
{
if (lines.empty()) {
if (lines.empty())
return;
}
clearSelection();
@ -714,9 +710,8 @@ void ChatLog::forceRelayout()
void ChatLog::checkVisibility(bool causedWheelEvent)
{
if (lines.empty()) {
if (lines.empty())
return;
}
// find first visible line
auto lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(),
@ -815,9 +810,8 @@ void ChatLog::updateTypingNotification()
qreal posY = 0.0;
if (!lines.empty()) {
if (!lines.empty())
posY = lines.last()->sceneBoundingRect().bottom() + lineSpacing;
}
notification->layout(useableWidth(), QPointF(0.0, posY));
}

View File

@ -96,9 +96,10 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co
// NOTE: this has to be done _after_ sending all sent messages since initial
// state of the message has to be marked according to our dispatch state
auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < DEF_NUM_MSG_TO_LOAD
constexpr auto defaultNumMessagesToLoad = 100;
auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < defaultNumMessagesToLoad
? ChatLogIdx(0)
: sessionChatLog.getFirstIdx() - DEF_NUM_MSG_TO_LOAD;
: sessionChatLog.getFirstIdx() - defaultNumMessagesToLoad;
if (canUseHistory()) {
loadHistoryIntoSessionChatLog(firstChatLogIdx);

View File

@ -34,8 +34,6 @@
#include <cassert>
static const auto DEF_NUM_MSG_TO_LOAD = 100;
using ChatLogIdx =
NamedType<size_t, struct ChatLogIdxTag, Orderable, UnderlyingAddable, UnitlessDifferencable, Incrementable>;
Q_DECLARE_METATYPE(ChatLogIdx)

View File

@ -378,7 +378,7 @@ GenericChatForm::GenericChatForm(const Core& _core, const Contact* contact, ICha
connect(contact, &Contact::displayedNameChanged, this, &GenericChatForm::setName);
auto chatLogIdxRange = chatLog.getNextIdx() - chatLog.getFirstIdx();
auto firstChatLogIdx = (chatLogIdxRange < DEF_NUM_MSG_TO_LOAD) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - DEF_NUM_MSG_TO_LOAD;
auto firstChatLogIdx = (chatLogIdxRange < 100) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - 100;
renderMessages(firstChatLogIdx, chatLog.getNextIdx());
}
@ -701,10 +701,10 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
{
auto end = chatLog.getFirstIdx();
if (time.isNull()) {
if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) {
end = ChatLogIdx(messages.rbegin()->first.get() - DEF_NUM_MSG_TO_LOAD);
chatWidget->removeLasts(DEF_NUM_MSG_TO_LOAD);
removeLastsMessages(DEF_NUM_MSG_TO_LOAD);
if (messages.size() + 100 >= maxMessages) {
end = ChatLogIdx(messages.rbegin()->first.get() - 100);
chatWidget->removeLasts(100);
removeLastsMessages(100);
} else {
end = messages.begin()->first;
}
@ -724,10 +724,10 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time)
{
auto begin = chatLog.getFirstIdx();
if (time.isNull()) {
if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) {
begin = ChatLogIdx(messages.rbegin()->first.get() + DEF_NUM_MSG_TO_LOAD);
chatWidget->removeFirsts(DEF_NUM_MSG_TO_LOAD);
removeFirstsMessages(DEF_NUM_MSG_TO_LOAD);
if (messages.size() + 100 >= maxMessages) {
begin = ChatLogIdx(messages.rbegin()->first.get() + 100);
chatWidget->removeFirsts(100);
removeFirstsMessages(100);
} else {
begin = messages.rbegin()->first;
}
@ -736,9 +736,9 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time)
begin = firstItemAfterDate(time.date(), chatLog);
}
int add = DEF_NUM_MSG_TO_LOAD;
if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) {
add = chatLog.getNextIdx().get() - (begin.get() + DEF_NUM_MSG_TO_LOAD);
int add = 100;
if (begin.get() + 100 > chatLog.getNextIdx().get()) {
add = chatLog.getNextIdx().get() - (begin.get() + 100);
}
auto end = ChatLogIdx(begin.get() + add);
renderMessages(begin, end);
@ -756,7 +756,7 @@ void GenericChatForm::removeFirstsMessages(const int num)
void GenericChatForm::removeLastsMessages(const int num)
{
if (static_cast<int>(messages.size()) > num) {
messages.erase(std::next(messages.end(), -num), messages.end());
messages.erase(std::next(messages.end(), -100), messages.end());
} else {
messages.clear();
}

View File

@ -38,15 +38,11 @@ LoadHistoryDialog::LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent)
&LoadHistoryDialog::highlightDates);
}
LoadHistoryDialog::LoadHistoryDialog(Mode mode, QWidget* parent)
LoadHistoryDialog::LoadHistoryDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::LoadHistoryDialog)
{
ui->setupUi(this);
if (mode == Mode::search) {
enableSearchMode();
}
}
LoadHistoryDialog::~LoadHistoryDialog()
@ -79,7 +75,7 @@ LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType()
return LoadType::to;
}
void LoadHistoryDialog::enableSearchMode()
void LoadHistoryDialog::turnSearchMode()
{
setWindowTitle(tr("Select date dialog"));
ui->fromLabel->setText(tr("Select a date"));

View File

@ -38,24 +38,18 @@ public:
to
};
enum Mode {
common,
search
};
explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr);
explicit LoadHistoryDialog(Mode mode, QWidget* parent = nullptr);
explicit LoadHistoryDialog(QWidget* parent = nullptr);
~LoadHistoryDialog();
QDateTime getFromDate();
LoadType getLoadType();
void turnSearchMode();
public slots:
void highlightDates(int year, int month);
private:
void enableSearchMode();
Ui::LoadHistoryDialog* ui;
const IChatLog* chatLog;
};

View File

@ -165,7 +165,8 @@ void SearchSettingsForm::onRegularClicked(const bool checked)
void SearchSettingsForm::onChoiceDate()
{
LoadHistoryDialog dlg(LoadHistoryDialog::search);
LoadHistoryDialog dlg;
dlg.turnSearchMode();
if (dlg.exec()) {
startTime = dlg.getFromDate();
updateStartDateLabel();