aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosemary Witchaven <32779090+in1tiate@users.noreply.github.com>2021-09-22 18:59:59 -0500
committerGitHub <noreply@github.com>2021-09-22 18:59:59 -0500
commitc163aab671b9590910039a7031ed4f02ff989ed8 (patch)
treed2e116e33e6b8ba136665d9f5bb7baffad5c297a
parentb2a4a41fd707633a03ecdef8a484c0f16f13779e (diff)
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
-rw-r--r--include/aoapplication.h3
-rw-r--r--include/aooptionsdialog.h4
-rw-r--r--include/courtroom.h3
-rw-r--r--src/aooptionsdialog.cpp32
-rw-r--r--src/courtroom.cpp7
-rw-r--r--src/text_file_functions.cpp6
6 files changed, 52 insertions, 3 deletions
diff --git a/include/aoapplication.h b/include/aoapplication.h
index 718029ae..0c5359ad 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 4568b1ed..77d19a43 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 09ec486a..4bc86242 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 5f3dbf02..aa1d6342 100644
--- a/src/aooptionsdialog.cpp
+++ b/src/aooptionsdialog.cpp
@@ -216,9 +216,34 @@ 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:"));
ui_log_ic_actions_lbl->setToolTip(
@@ -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 9d0ead76..12b97e5a 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 d9b341be..aedf3b8a 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<QString>();
+ return result;
+}
+
bool AOApplication::get_log_ic_actions()
{
QString result =