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
This commit is contained in:
parent
b2a4a41fd7
commit
c163aab671
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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__))
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user