forked from AttorneyOnline/AO2-Client
-
Notifications
You must be signed in to change notification settings - Fork 2
Pinned message #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EstatoDeviato
wants to merge
5
commits into
Crystalwarrior:master
Choose a base branch
from
EstatoDeviato:pinned-message
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pinned message #20
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0571ac6
Update ms maximum
EstatoDeviato d083e64
Update courtroom.h
EstatoDeviato 3373c5f
Add PM packet (pinned message) and CPM (clear pinned message)
EstatoDeviato 3161cec
add append pinned message function
EstatoDeviato 10db287
add append pinned message function
EstatoDeviato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,6 +153,11 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() | |
| ui_ic_chatlog->setReadOnly(true); | ||
| ui_ic_chatlog->setObjectName("ui_ic_chatlog"); | ||
|
|
||
| ui_ic_chatlog_pinned = new QTextEdit(this); | ||
| ui_ic_chatlog_pinned->setReadOnly(true); | ||
| ui_ic_chatlog_pinned->setObjectName("ui_ic_chatlog_pinned"); | ||
| ui_ic_chatlog_pinned->hide(); | ||
|
|
||
| log_maximum_blocks = Options::getInstance().maxLogSize(); | ||
| log_goes_downwards = Options::getInstance().logDirectionDownwards(); | ||
| log_colors = Options::getInstance().colorLogEnabled(); | ||
|
|
@@ -336,6 +341,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() | |
| ui_switch_area_music = new AOButton(this, ao_app); | ||
| ui_switch_area_music->setObjectName("ui_switch_area_music"); | ||
|
|
||
| ui_switch_logs = new AOButton(this, ao_app); | ||
| ui_switch_logs->setObjectName("ui_switch_logs"); | ||
|
|
||
| ui_pre = new QCheckBox(this); | ||
| ui_pre->setText(tr("Pre")); | ||
| ui_pre->setObjectName("ui_pre"); | ||
|
|
@@ -834,6 +842,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() | |
| connect(ui_settings, &AOButton::clicked, this, &Courtroom::on_settings_clicked); | ||
| connect(ui_switch_area_music, &AOButton::clicked, this, | ||
| &Courtroom::on_switch_area_music_clicked); | ||
| connect(ui_switch_logs, &AOButton::clicked, this, | ||
| &Courtroom::on_switch_logs_clicked); | ||
|
|
||
| connect(ui_pre, &AOButton::clicked, this, &Courtroom::on_pre_clicked); | ||
| connect(ui_flip, &AOButton::clicked, this, &Courtroom::on_flip_clicked); | ||
|
|
@@ -1085,6 +1095,12 @@ void Courtroom::set_widgets() | |
| ui_ic_chatlog->setPlaceholderText(log_goes_downwards ? "▼ " + tr("Log goes down") + " ▼" | ||
| : "▲ " + tr("Log goes up") + " ▲"); | ||
|
|
||
| set_size_and_pos(ui_ic_chatlog_pinned, "ic_chatlog"); | ||
| ui_ic_chatlog_pinned->setFrameShape(QFrame::NoFrame); | ||
| ui_ic_chatlog_pinned->setPlaceholderText(log_goes_downwards | ||
| ? "▼📌 " + tr("Pinned Message") + " 📌▼" | ||
| : "▲📌 " + tr("Pinned Message") + " 📌▲"); | ||
|
|
||
| set_size_and_pos(ui_debug_log, "ms_chatlog"); // Old name, still use it to not break compatibility | ||
| ui_debug_log->setFrameShape(QFrame::NoFrame); | ||
|
|
||
|
|
@@ -1331,6 +1347,11 @@ void Courtroom::set_widgets() | |
| ui_switch_area_music->set_image("switch_area_music"); | ||
| ui_switch_area_music->setToolTip(tr("Switch between Areas and Music lists")); | ||
|
|
||
| set_size_and_pos(ui_switch_logs, "switch_logs"); | ||
| ui_switch_logs->setText(tr("L/P")); | ||
| ui_switch_logs->set_image("switch_logs"); | ||
| ui_switch_logs->setToolTip(tr("Switch between Log message chat and Log pinned chat")); | ||
|
|
||
| set_size_and_pos(ui_pre, "pre"); | ||
| ui_pre->setText(tr("Preanim")); | ||
| ui_pre->setToolTip( | ||
|
|
@@ -1476,6 +1497,7 @@ void Courtroom::set_fonts(QString p_char) | |
| set_font(ui_vp_showname, "", "showname", p_char); | ||
| set_font(ui_vp_message, "", "message", p_char); | ||
| set_font(ui_ic_chatlog, "", "ic_chatlog", p_char); | ||
| set_font(ui_ic_chatlog_pinned, "", "ic_chatlog_pinned", p_char); | ||
| set_font(ui_debug_log, "", "debug_log", p_char); | ||
| set_font(ui_server_chatlog, "", "server_chatlog", p_char); | ||
| set_font(ui_music_list, "", "music_list", p_char); | ||
|
|
@@ -4008,6 +4030,157 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, | |
| } | ||
| } | ||
|
|
||
| void Courtroom::append_pinned_text(QString p_text, QString p_name, QString p_action, int color, bool selfname, QDateTime timestamp) | ||
| { | ||
| QColor chatlog_color = ao_app->get_color("ic_chatlog_color", "courtroom_fonts.ini"); | ||
| QTextCharFormat bold; | ||
| QTextCharFormat normal; | ||
| QTextCharFormat italics; | ||
| QTextCharFormat own_name; | ||
| QTextCharFormat other_name; | ||
| QTextCharFormat timestamp_format; | ||
| QTextCharFormat selftimestamp_format; | ||
| QTextBlockFormat format; | ||
| bold.setFontWeight(QFont::Bold); | ||
| normal.setFontWeight(QFont::Normal); | ||
| italics.setFontItalic(true); | ||
| own_name.setFontWeight(QFont::Bold); | ||
| own_name.setForeground( | ||
| ao_app->get_color("ic_chatlog_selfname_color", "courtroom_fonts.ini")); | ||
| other_name.setFontWeight(QFont::Bold); | ||
| other_name.setForeground( | ||
| ao_app->get_color("ic_chatlog_showname_color", "courtroom_fonts.ini")); | ||
| timestamp_format.setForeground( | ||
| ao_app->get_color("ic_chatlog_timestamp_color", "courtroom_fonts.ini")); | ||
| selftimestamp_format.setForeground(ao_app->get_color( | ||
| "ic_chatlog_selftimestamp_color", "courtroom_fonts.ini")); | ||
| format.setTopMargin(log_margin); | ||
| const QTextCursor old_cursor = ui_ic_chatlog_pinned->textCursor(); | ||
| const int old_scrollbar_value = ui_ic_chatlog_pinned->verticalScrollBar()->value(); | ||
| const bool need_newline = !ui_ic_chatlog_pinned->document()->isEmpty(); | ||
| const int scrollbar_target_value = | ||
| log_goes_downwards ? ui_ic_chatlog_pinned->verticalScrollBar()->maximum() | ||
| : ui_ic_chatlog_pinned->verticalScrollBar()->minimum(); | ||
|
|
||
|
|
||
| ui_ic_chatlog_pinned->moveCursor(log_goes_downwards ? QTextCursor::End | ||
| : QTextCursor::Start); | ||
|
|
||
| // Only prepend with newline if log goes downwards | ||
| if (log_goes_downwards && need_newline) { | ||
| ui_ic_chatlog_pinned->textCursor().insertBlock(format); | ||
| } | ||
|
|
||
| // Timestamp if we're doing that meme | ||
| if (log_timestamp) { | ||
| // Format the timestamp | ||
| QTextCharFormat format = selfname ? selftimestamp_format : timestamp_format; | ||
| if (timestamp.isValid()) { | ||
| ui_ic_chatlog_pinned->textCursor().insertText( | ||
| "[" + timestamp.toString(log_timestamp_format) + "] ", format); | ||
| } | ||
| else { | ||
| qCritical() << "could not insert invalid timestamp" << timestamp; | ||
| } | ||
| } | ||
|
|
||
| // Format the name of the actor | ||
| QTextCharFormat name_format = selfname ? own_name : other_name; | ||
| ui_ic_chatlog_pinned->textCursor().insertText("📌" + p_name + "📌", name_format); | ||
| // Special case for stopping the music | ||
| if (p_action == tr("has stopped the music")) { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action + ".", normal); | ||
| } | ||
| // Make shout text bold | ||
| else if (p_action == tr("shouts") && log_ic_actions) { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action + " ", normal); | ||
| if (log_colors) { | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml( | ||
| "<b>" + | ||
| filter_ic_text(p_text, true, -1, 0) | ||
| .replace("$c0", chatlog_color.name(QColor::HexArgb)) + | ||
| "</b>"); | ||
| } | ||
| else | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_text, italics); | ||
| } | ||
| // If action not blank: | ||
| else if (p_action != "" && log_ic_actions) { | ||
| // Format the action in normal | ||
| ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action, normal); | ||
| if (log_newline) | ||
| // For some reason, we're forced to use <br> instead of the more sensible | ||
| // \n. Why? Because \n is treated as a new Block instead of a soft newline | ||
| // within a paragraph! | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml("<br>"); | ||
| else | ||
| ui_ic_chatlog_pinned->textCursor().insertText(": ", normal); | ||
| // Format the result in italics | ||
| ui_ic_chatlog->textCursor().insertText(p_text + ".", italics); | ||
| } | ||
| else { | ||
| if (log_newline) { | ||
| // For some reason, we're forced to use <br> instead of the more sensible | ||
| // \n. Why? Because \n is treated as a new Block instead of a soft newline | ||
| // within a paragraph! | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml("<br>"); | ||
| } | ||
| else { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(": ", normal); | ||
| } | ||
| // Format the result according to html | ||
| if (log_colors) { | ||
| QString p_text_filtered = filter_ic_text(p_text, true, -1, color); | ||
| p_text_filtered = | ||
| p_text_filtered.replace("$c0", chatlog_color.name(QColor::HexArgb)); | ||
| for (int c = 1; c < max_colors; ++c) { | ||
| QColor color_result = default_color_rgb_list.at(c); | ||
| p_text_filtered = p_text_filtered.replace( | ||
| "$c" + QString::number(c), color_result.name(QColor::HexArgb)); | ||
| } | ||
| ui_ic_chatlog_pinned->textCursor().insertHtml(p_text_filtered); | ||
| } | ||
| else { | ||
| ui_ic_chatlog_pinned->textCursor().insertText(filter_ic_text(p_text, false), | ||
| normal); | ||
| } | ||
| } | ||
|
|
||
| // Only append with newline if log goes upwards | ||
| if (!log_goes_downwards && need_newline) { | ||
| ui_ic_chatlog_pinned->textCursor().insertBlock(format); | ||
| } | ||
|
|
||
| // If we got too many blocks in the current log, delete some. | ||
| while (ui_ic_chatlog_pinned->document()->blockCount() > log_maximum_blocks && | ||
| log_maximum_blocks > 0) { | ||
| QTextCursor temp_curs = ui_ic_chatlog_pinned->textCursor(); | ||
| temp_curs.movePosition(log_goes_downwards ? QTextCursor::Start | ||
| : QTextCursor::End); | ||
| temp_curs.select(QTextCursor::BlockUnderCursor); | ||
| temp_curs.removeSelectedText(); | ||
| if (log_goes_downwards) | ||
| temp_curs.deleteChar(); | ||
| else | ||
| temp_curs.deletePreviousChar(); | ||
| } | ||
|
|
||
| // Finally, scroll the scrollbar to the correct position. | ||
| if (old_cursor.hasSelection() || | ||
| old_scrollbar_value != scrollbar_target_value) { | ||
| // The user has selected text or scrolled away from the bottom: maintain | ||
| // position. | ||
| ui_ic_chatlog_pinned->setTextCursor(old_cursor); | ||
| ui_ic_chatlog_pinned->verticalScrollBar()->setValue(old_scrollbar_value); | ||
| } | ||
| else { | ||
| ui_ic_chatlog_pinned->verticalScrollBar()->setValue( | ||
| log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum() : 0); | ||
| } | ||
| } | ||
|
|
||
| void Courtroom::clear_pinned_message() { ui_ic_chatlog_pinned->clear(); } | ||
|
|
||
|
Comment on lines
+4033
to
+4183
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 COPY PASTE ALERT 🚨please revise, never copy-paste this much code! Adjust the existing function(s) instead and refactor them to allow your use case. |
||
| void Courtroom::pop_ic_ghost() | ||
| { | ||
| QTextCursor ghost = ui_ic_chatlog->textCursor(); | ||
|
|
@@ -6651,6 +6824,18 @@ void Courtroom::on_switch_area_music_clicked() | |
|
|
||
| } | ||
|
|
||
| void Courtroom::on_switch_logs_clicked() | ||
| { | ||
| if (ui_ic_chatlog->isHidden()) { | ||
| ui_ic_chatlog->show(); | ||
| ui_ic_chatlog_pinned->hide(); | ||
| } | ||
| else { | ||
| ui_ic_chatlog->hide(); | ||
| ui_ic_chatlog_pinned->show(); | ||
| } | ||
| } | ||
|
|
||
| void Courtroom::ping_server() | ||
| { | ||
| ping_timer.start(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
ic_chatlog_pinnedto the description so it's known what should be added to themes