aboutsummaryrefslogtreecommitdiff
path: root/src/aotextarea.cpp
diff options
context:
space:
mode:
authorTrickyLeifa <date.epoch@gmail.com>2024-05-15 00:00:17 +0200
committerTrickyLeifa <date.epoch@gmail.com>2024-05-15 00:04:16 +0200
commitc9f52b7223685d2e7fca925594171f94dd8c6e3b (patch)
tree740bb32a40da98a4d52836432f59a16b31333900 /src/aotextarea.cpp
parent951766666621fa77e257e6b5616fe4ab1eb2a52f (diff)
Ported to CMake, ...
* Ported the project to CMake * Android and Mac support dropped for the time being. * Tests, BASS and Discord-RPC are now options * Restructured and reformated the project. * Merged `include` and `src` * Renamed `resource` to `data` * Renamed various files * External libraries headers are no longer included in `src` * Replaced header guards with #pragma once * Multiple refactors (keywords, headers) * Added Qt6 compatibility * Removed various unused functions and headers * Reworked AOPacket * When content is passed to AOPacket, it should be ensured that the content is already decoded. * Encoding/decoding are now static methods. * Fixed various memory leaks * Removed animation code for AOImage * AOImage is always using static images * Simplified ChatLogPiece
Diffstat (limited to 'src/aotextarea.cpp')
-rw-r--r--src/aotextarea.cpp63
1 files changed, 19 insertions, 44 deletions
diff --git a/src/aotextarea.cpp b/src/aotextarea.cpp
index a4259039..cf651244 100644
--- a/src/aotextarea.cpp
+++ b/src/aotextarea.cpp
@@ -1,42 +1,36 @@
#include "aotextarea.h"
-AOTextArea::AOTextArea(QWidget *p_parent, int p_log_length) : QTextBrowser(p_parent)
-{
- this->document()->setMaximumBlockCount(p_log_length);
-}
+AOTextArea::AOTextArea(QWidget *p_parent)
+ : AOTextArea(5000, p_parent)
+{}
-void AOTextArea::append_linked(QString p_message)
+AOTextArea::AOTextArea(int p_log_length, QWidget *p_parent)
+ : QTextBrowser(p_parent)
{
- QString result = p_message.toHtmlEscaped()
- .replace("\n", "<br>")
- .replace(url_parser_regex, "<a href='\\1'>\\1</a>");
- this->insertHtml(result);
+ this->document()->setMaximumBlockCount(p_log_length);
}
-void AOTextArea::append_chatmessage(QString p_name, QString p_message,
- QString p_name_colour, QString p_color)
+void AOTextArea::append_chatmessage(QString p_name, QString p_message, QString p_name_colour, QString p_color)
{
const QTextCursor old_cursor = this->textCursor();
const int old_scrollbar_value = this->verticalScrollBar()->value();
- const bool is_scrolled_down =
- old_scrollbar_value == this->verticalScrollBar()->maximum();
+ const bool is_scrolled_down = old_scrollbar_value == this->verticalScrollBar()->maximum();
this->moveCursor(QTextCursor::End);
this->append("");
- if (!p_name.isEmpty()) {
- this->insertHtml("<b><font color=" + p_name_colour + ">" + p_name.toHtmlEscaped() +
- "</font></b>:&nbsp;");
+ if (!p_name.isEmpty())
+ {
+ this->insertHtml("<b><font color=" + p_name_colour + ">" + p_name.toHtmlEscaped() + "</font></b>:&nbsp;");
// cheap workarounds ahoy
p_message += " ";
}
- QString result = p_message.toHtmlEscaped()
- .replace("\n", "<br>")
- .replace(url_parser_regex, "<a href='\\1'>\\1</a>");
+ QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>");
- if (!p_color.isEmpty()) {
+ if (!p_color.isEmpty())
+ {
result = "<font color=" + p_color + ">" + result + "</font>";
}
@@ -45,36 +39,17 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message,
this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down);
}
-void AOTextArea::append_error(QString p_message)
-{
- const QTextCursor old_cursor = this->textCursor();
- const int old_scrollbar_value = this->verticalScrollBar()->value();
- const bool is_scrolled_down =
- old_scrollbar_value == this->verticalScrollBar()->maximum();
-
- this->moveCursor(QTextCursor::End);
-
- this->append("");
-
- p_message += " ";
- QString result = p_message.replace("\n", "<br>")
- .replace(url_parser_regex, "<a href='\\1'>\\1</a>");
-
- this->insertHtml("<font color='red'>" + result + "</font>");
-
- this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down);
-}
-
-void AOTextArea::auto_scroll(QTextCursor old_cursor, int old_scrollbar_value,
- bool is_scrolled_down)
+void AOTextArea::auto_scroll(QTextCursor old_cursor, int old_scrollbar_value, bool is_scrolled_down)
{
- if (old_cursor.hasSelection() || !is_scrolled_down) {
+ if (old_cursor.hasSelection() || !is_scrolled_down)
+ {
// The user has selected text or scrolled away from the bottom: maintain
// position.
this->setTextCursor(old_cursor);
this->verticalScrollBar()->setValue(old_scrollbar_value);
}
- else {
+ else
+ {
// The user hasn't selected any text and the scrollbar is at the bottom:
// scroll to the bottom.
this->moveCursor(QTextCursor::End);