Truncate chat (needs testing)

This commit is contained in:
oldmud0 2017-11-05 11:51:24 -06:00
parent 43448296fc
commit 9c7895922a
2 changed files with 15 additions and 0 deletions

View File

@ -28,6 +28,7 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message)
this->insertHtml(result);
this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down);
this->auto_truncate();
}
void AOTextArea::append_error(QString p_message)
@ -48,6 +49,7 @@ void AOTextArea::append_error(QString p_message)
this->insertHtml("</div>");
this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down);
this->auto_truncate();
}
void AOTextArea::auto_scroll(QTextCursor old_cursor, int old_scrollbar_value, bool is_scrolled_down)
@ -65,3 +67,15 @@ void AOTextArea::auto_scroll(QTextCursor old_cursor, int old_scrollbar_value, bo
this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum());
}
}
void AOTextArea::auto_truncate()
{
QTextCursor temp_cursor = this->textCursor();
if (this->document()->characterCount() > 100000)
{
temp_cursor.movePosition(QTextCursor::Start);
temp_cursor.select(QTextCursor::LineUnderCursor);
temp_cursor.removeSelectedText();
}
}

View File

@ -15,6 +15,7 @@ private:
const QRegExp omnis_dank_url_regex = QRegExp("\\b(https?://\\S+\\.\\S+)\\b");
void auto_scroll(QTextCursor old_cursor, int scrollbar_value, bool is_scrolled_down);
void auto_truncate();
};
#endif // AOTEXTAREA_H