-
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
base: master
Are you sure you want to change the base?
Pinned message #20
Conversation
|
Plz add a picture of how it looks like in client |
Crystalwarrior
left a comment
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.
volvo plz revise
| 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); |
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_pinned to the description so it's known what should be added to themes
| 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(); } | ||
|
|
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.
🚨 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.
PM Packet = send_command("PM", text, char_name, action) Set a pinned message in pinned message chatlog
CPM Packet = send_command("CPM") clear all the pinned messages