Fix timestamps when toggling showname

On toggling shownames, regenerate_ic_chatlog() gets called to reprint
the entire chatlog with append_ic_text().  The issue is that
append_ic_text() uses QDateTime::currentDateTime() for the timestamp
when it's called.  Therefore the fix is adding a new timestamp
parameter to the append_ic_text() which we supply from the datetime
provided by each chatlogpiece
This commit is contained in:
Skye Deving 2021-01-04 13:45:18 -06:00
parent 4d02cc8d68
commit 6570bcf066
2 changed files with 13 additions and 7 deletions

View File

@ -225,7 +225,7 @@ public:
// selected // selected
// or the user isn't already scrolled to the top // or the user isn't already scrolled to the top
void append_ic_text(QString p_text, QString p_name = "", QString action = "", void append_ic_text(QString p_text, QString p_name = "", QString action = "",
int color = 0); int color = 0, QDateTime timestamp = {});
// prints who played the song to IC chat and plays said song(if found on local // prints who played the song to IC chat and plays said song(if found on local
// filesystem) takes in a list where the first element is the song name and // filesystem) takes in a list where the first element is the song name and

View File

@ -2619,7 +2619,7 @@ void Courtroom::log_ic_text(QString p_name, QString p_showname,
} }
void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
int color) int color, QDateTime timestamp)
{ {
QTextCharFormat bold; QTextCharFormat bold;
QTextCharFormat normal; QTextCharFormat normal;
@ -2645,10 +2645,15 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
} }
// Timestamp if we're doing that meme // Timestamp if we're doing that meme
if (log_timestamp) if (log_timestamp) {
ui_ic_chatlog->textCursor().insertText( if (timestamp.isValid()) {
"[" + QDateTime::currentDateTime().toString("h:mm:ss AP") + "] ", ui_ic_chatlog->textCursor().insertText(
normal); "[" + timestamp.toString("h:mm:ss AP") + "] ", normal);
} else {
ui_ic_chatlog->textCursor().insertText(
"[" + QDateTime::currentDateTime().toString("h:mm:ss AP") + "] ", normal);
}
}
// Format the name of the actor // Format the name of the actor
ui_ic_chatlog->textCursor().insertText(p_name, bold); ui_ic_chatlog->textCursor().insertText(p_name, bold);
@ -4780,7 +4785,8 @@ void Courtroom::regenerate_ic_chatlog()
append_ic_text(item.get_message(), append_ic_text(item.get_message(),
ui_showname_enable->isChecked() ? item.get_showname() ui_showname_enable->isChecked() ? item.get_showname()
: item.get_name(), : item.get_name(),
item.get_action(), item.get_chat_color()); item.get_action(), item.get_chat_color(),
item.get_datetime().toLocalTime());
} }
} }