diff options
| author | Crystalwarrior <varsash@gmail.com> | 2020-05-22 01:18:24 +0300 |
|---|---|---|
| committer | Crystalwarrior <varsash@gmail.com> | 2020-05-22 01:18:24 +0300 |
| commit | c8e12558cdd3fd0769b81679ad09edf1f29b780f (patch) | |
| tree | 7dae2225e574c3ee55d6b82a1d2f399db4ace5c0 /src/aotextarea.cpp | |
| parent | dfac0652c8eb9bd48ceea7ae755e9c2f7e5cb1a2 (diff) | |
Clang-ify the code with this styling using Visual Studio Code:
{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Stroustrup, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All }
(this is the Visual Studio preset with only "BreakBeforeBraces" changed from Allman to Stroustrup)
Diffstat (limited to 'src/aotextarea.cpp')
| -rw-r--r-- | src/aotextarea.cpp | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/src/aotextarea.cpp b/src/aotextarea.cpp index a34bb1a6..524f3283 100644 --- a/src/aotextarea.cpp +++ b/src/aotextarea.cpp @@ -2,65 +2,62 @@ AOTextArea::AOTextArea(QWidget *p_parent) : QTextBrowser(p_parent) { - } void AOTextArea::append_linked(QString p_message) { - QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>" ); - this->insertHtml(result); + QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>"); + this->insertHtml(result); } void AOTextArea::append_chatmessage(QString p_name, QString p_message, QString p_colour) { - 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 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->moveCursor(QTextCursor::End); - this->append(""); - this->insertHtml("<b><font color=" + p_colour + ">" + p_name.toHtmlEscaped() + "</font></b>: "); + this->append(""); + this->insertHtml("<b><font color=" + p_colour + ">" + p_name.toHtmlEscaped() + "</font></b>: "); - //cheap workarounds ahoy - p_message += " "; - QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>" ); + //cheap workarounds ahoy + p_message += " "; + QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>"); - this->insertHtml(result); + this->insertHtml(result); - this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down); + 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(); + 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->moveCursor(QTextCursor::End); - this->append(""); + this->append(""); - p_message += " "; - QString result = p_message.replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>" ); + 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->insertHtml("<font color='red'>" + result + "</font>"); - this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down); + 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) { - 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 - { - // The user hasn't selected any text and the scrollbar is at the bottom: scroll to the bottom. - this->moveCursor(QTextCursor::End); - this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum()); - } + 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 { + // The user hasn't selected any text and the scrollbar is at the bottom: scroll to the bottom. + this->moveCursor(QTextCursor::End); + this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum()); + } } |
