From c163aab671b9590910039a7031ed4f02ff989ed8 Mon Sep 17 00:00:00 2001 From: Rosemary Witchaven <32779090+in1tiate@users.noreply.github.com> Date: Wed, 22 Sep 2021 18:59:59 -0500 Subject: [PATCH] Allow user to configure log timestamp format (#590) * user configurable timestamp format * fix label making the entire settings window move jankily * add a dropdown for sane timestamp formats * streamline adding options to log timestamp format --- include/aoapplication.h | 3 +++ include/aooptionsdialog.h | 4 ++++ include/courtroom.h | 3 +++ src/aooptionsdialog.cpp | 32 +++++++++++++++++++++++++++++++- src/courtroom.cpp | 7 +++++-- src/text_file_functions.cpp | 6 ++++++ 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/include/aoapplication.h b/include/aoapplication.h index 718029a..0c5359a 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -285,6 +285,9 @@ public: // Returns whether the log should have a timestamp. bool get_log_timestamp(); + // Returns the format string for the log timestamp + QString get_log_timestamp_format(); + // Returns whether to log IC actions. bool get_log_ic_actions(); diff --git a/include/aooptionsdialog.h b/include/aooptionsdialog.h index 4568b1e..77d19a4 100644 --- a/include/aooptionsdialog.h +++ b/include/aooptionsdialog.h @@ -62,6 +62,8 @@ private: QSpinBox *ui_log_margin_spinbox; QLabel *ui_log_timestamp_lbl; QCheckBox *ui_log_timestamp_cb; + QLabel *ui_log_timestamp_format_lbl; + QComboBox *ui_log_timestamp_format_combobox; QLabel *ui_stay_time_lbl; QSpinBox *ui_stay_time_spinbox; QLabel *ui_desync_logs_lbl; @@ -197,6 +199,8 @@ public slots: void save_pressed(); void discard_pressed(); void button_clicked(QAbstractButton *button); + void on_timestamp_format_edited(); + void timestamp_cb_changed(int state); void on_reload_theme_clicked(); void theme_changed(int i); }; diff --git a/include/courtroom.h b/include/courtroom.h index 09ec486..4bc8624 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -416,6 +416,9 @@ private: // True, if the log should have a timestamp. bool log_timestamp = false; + // format string for aforementioned log timestamp + QString log_timestamp_format; + // How long in miliseconds should the objection wait before appearing. int objection_threshold = 1500; diff --git a/src/aooptionsdialog.cpp b/src/aooptionsdialog.cpp index 5f3dbf0..aa1d634 100644 --- a/src/aooptionsdialog.cpp +++ b/src/aooptionsdialog.cpp @@ -216,8 +216,33 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) ui_log_timestamp_cb = new QCheckBox(ui_form_layout_widget); + connect(ui_log_timestamp_cb, SIGNAL(stateChanged(int)), this, SLOT(timestamp_cb_changed(int))); + ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_log_timestamp_cb); + row += 1; + ui_log_timestamp_format_lbl = new QLabel(ui_form_layout_widget); + ui_log_timestamp_format_lbl->setText(tr("Log timestamp format:\n") + QDateTime::currentDateTime().toString(ao_app->get_log_timestamp_format())); + ui_gameplay_form->setWidget(row, QFormLayout::LabelRole, ui_log_timestamp_format_lbl); + + ui_log_timestamp_format_combobox = new QComboBox(ui_form_layout_widget); + ui_log_timestamp_format_combobox->setEditable(true); + + QString l_current_format = ao_app->get_log_timestamp_format(); + + ui_log_timestamp_format_combobox->setCurrentText(l_current_format); + ui_log_timestamp_format_combobox->addItem("h:mm:ss AP"); // 2:13:09 PM + ui_log_timestamp_format_combobox->addItem("hh:mm:ss"); // 14:13:09 + ui_log_timestamp_format_combobox->addItem("h:mm AP"); // 2:13 PM + ui_log_timestamp_format_combobox->addItem("hh:mm"); // 14:13 + + ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_log_timestamp_format_combobox); + + connect(ui_log_timestamp_format_combobox, SIGNAL(currentTextChanged(QString)), this, SLOT(on_timestamp_format_edited())); + + if(!ao_app->get_log_timestamp()) + ui_log_timestamp_format_combobox->setDisabled(true); + row += 1; ui_log_ic_actions_lbl = new QLabel(ui_form_layout_widget); ui_log_ic_actions_lbl->setText(tr("Log IC actions:")); @@ -230,7 +255,6 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_log_ic_actions_cb); - row += 1; ui_stay_time_lbl = new QLabel(ui_form_layout_widget); ui_stay_time_lbl->setText(tr("Text Stay Time:")); @@ -1072,6 +1096,7 @@ void AOOptionsDialog::update_values() { ui_downwards_cb->setChecked(ao_app->get_log_goes_downwards()); ui_log_newline_cb->setChecked(ao_app->get_log_newline()); ui_log_timestamp_cb->setChecked(ao_app->get_log_timestamp()); + ui_log_timestamp_format_combobox->setCurrentText(ao_app->get_log_timestamp_format()); ui_log_ic_actions_cb->setChecked(ao_app->get_log_ic_actions()); ui_desync_logs_cb->setChecked(ao_app->is_desyncrhonized_logs_enabled()); ui_instant_objection_cb->setChecked(ao_app->is_instant_objection_enabled()); @@ -1133,6 +1158,7 @@ void AOOptionsDialog::save_pressed() configini->setValue("log_newline", ui_log_newline_cb->isChecked()); configini->setValue("log_margin", ui_log_margin_spinbox->value()); configini->setValue("log_timestamp", ui_log_timestamp_cb->isChecked()); + configini->setValue("log_timestamp_format", ui_log_timestamp_format_combobox->currentText()); configini->setValue("log_ic_actions", ui_log_ic_actions_cb->isChecked()); configini->setValue("desync_logs", ui_desync_logs_cb->isChecked()); configini->setValue("stay_time", ui_stay_time_spinbox->value()); @@ -1260,6 +1286,10 @@ void AOOptionsDialog::theme_changed(int i) { } +void AOOptionsDialog::on_timestamp_format_edited() { ui_log_timestamp_format_lbl->setText(tr("Log timestamp format:\n") + QDateTime::currentDateTime().toString(ui_log_timestamp_format_combobox->currentText())); } + +void AOOptionsDialog::timestamp_cb_changed(int state) { ui_log_timestamp_format_combobox->setDisabled(state == 0); } + #if (defined(_WIN32) || defined(_WIN64)) bool AOOptionsDialog::needs_default_audiodev() { return true; } #elif (defined(LINUX) || defined(__linux__)) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 9d0ead7..12b97e5 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -109,6 +109,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() log_newline = ao_app->get_log_newline(); log_margin = ao_app->get_log_margin(); log_timestamp = ao_app->get_log_timestamp(); + log_timestamp_format = ao_app->get_log_timestamp_format(); ui_ms_chatlog = new AOTextArea(this); ui_ms_chatlog->setReadOnly(true); @@ -708,12 +709,14 @@ void Courtroom::set_widgets() log_colors != ao_app->is_colorlog_enabled() || log_newline != ao_app->get_log_newline() || log_margin != ao_app->get_log_margin() || - log_timestamp != ao_app->get_log_timestamp(); + log_timestamp != ao_app->get_log_timestamp() || + log_timestamp_format != ao_app->get_log_timestamp_format(); log_goes_downwards = ao_app->get_log_goes_downwards(); log_colors = ao_app->is_colorlog_enabled(); log_newline = ao_app->get_log_newline(); log_margin = ao_app->get_log_margin(); log_timestamp = ao_app->get_log_timestamp(); + log_timestamp_format = ao_app->get_log_timestamp_format(); if (regenerate) regenerate_ic_chatlog(); @@ -3127,7 +3130,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, if (log_timestamp) { if (timestamp.isValid()) { ui_ic_chatlog->textCursor().insertText( - "[" + timestamp.toString("h:mm:ss AP") + "] ", normal); + "[" + timestamp.toString(log_timestamp_format) + "] ", normal); } else { qDebug() << "could not insert invalid timestamp"; } diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index d9b341b..aedf3b8 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -89,6 +89,12 @@ bool AOApplication::get_log_timestamp() return result.startsWith("true"); } +QString AOApplication::get_log_timestamp_format() +{ + QString result = configini->value("log_timestamp_format", "h:mm:ss AP").value(); + return result; +} + bool AOApplication::get_log_ic_actions() { QString result =