From 6570bcf0662d675cc3f0ed89820fc95efe4cace3 Mon Sep 17 00:00:00 2001 From: Skye Deving <76892045+skyedeving@users.noreply.github.com> Date: Mon, 4 Jan 2021 13:45:18 -0600 Subject: 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 --- src/courtroom.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 95189112..9fda3954 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -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, - int color) + int color, QDateTime timestamp) { QTextCharFormat bold; 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 - if (log_timestamp) - ui_ic_chatlog->textCursor().insertText( - "[" + QDateTime::currentDateTime().toString("h:mm:ss AP") + "] ", - normal); + if (log_timestamp) { + if (timestamp.isValid()) { + ui_ic_chatlog->textCursor().insertText( + "[" + 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 ui_ic_chatlog->textCursor().insertText(p_name, bold); @@ -4780,7 +4785,8 @@ void Courtroom::regenerate_ic_chatlog() append_ic_text(item.get_message(), ui_showname_enable->isChecked() ? item.get_showname() : item.get_name(), - item.get_action(), item.get_chat_color()); + item.get_action(), item.get_chat_color(), + item.get_datetime().toLocalTime()); } } -- cgit From 8aaba6633ec8b3303e0e7f24d42b96f3d5a4a90e Mon Sep 17 00:00:00 2001 From: Skye Deving <76892045+skyedeving@users.noreply.github.com> Date: Mon, 4 Jan 2021 19:21:11 -0600 Subject: Change default parameter to be QDateTime::currentDateTime() Print debug message if provided timestamp is invalid --- src/courtroom.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 9fda3954..5f9d206e 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2650,8 +2650,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, ui_ic_chatlog->textCursor().insertText( "[" + timestamp.toString("h:mm:ss AP") + "] ", normal); } else { - ui_ic_chatlog->textCursor().insertText( - "[" + QDateTime::currentDateTime().toString("h:mm:ss AP") + "] ", normal); + qDebug() << "could not insert invalid timestamp"; } } -- cgit