From d30123f938c3bb9b8e556eedabccc265818dc06a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 14 Dec 2021 21:41:46 +0100 Subject: gui, opentrack: initial support for embeddable module dialogs --- gui/lang/nl_NL.ts | 4 +++ gui/lang/ru_RU.ts | 4 +++ gui/lang/stub.ts | 4 +++ gui/lang/zh_CN.ts | 4 +++ gui/settings.cpp | 104 ++++++++++++++++++++++++++++++++++++++++-------------- gui/settings.hpp | 20 ++++++++--- 6 files changed, 108 insertions(+), 32 deletions(-) (limited to 'gui') diff --git a/gui/lang/nl_NL.ts b/gui/lang/nl_NL.ts index f21806b3..49ecec73 100644 --- a/gui/lang/nl_NL.ts +++ b/gui/lang/nl_NL.ts @@ -388,6 +388,10 @@ Press "clear calibration" to remove any calibration data pertaining to Freeze the position returned by the tracker while this mode is active. + + Tracker + + process_detector diff --git a/gui/lang/ru_RU.ts b/gui/lang/ru_RU.ts index 27160ec5..95567649 100644 --- a/gui/lang/ru_RU.ts +++ b/gui/lang/ru_RU.ts @@ -391,6 +391,10 @@ Press "clear calibration" to remove any calibration data pertaining to Disable user interface localization Использовать английский интерфейс + + Tracker + + process_detector diff --git a/gui/lang/stub.ts b/gui/lang/stub.ts index 3fdc2d8f..7b7a97b0 100644 --- a/gui/lang/stub.ts +++ b/gui/lang/stub.ts @@ -388,6 +388,10 @@ Press "clear calibration" to remove any calibration data pertaining to Disable user interface localization + + Tracker + + process_detector diff --git a/gui/lang/zh_CN.ts b/gui/lang/zh_CN.ts index 6efcf439..b7df572e 100644 --- a/gui/lang/zh_CN.ts +++ b/gui/lang/zh_CN.ts @@ -389,6 +389,10 @@ Press "clear calibration" to remove any calibration data pertaining to Freeze the position returned by the tracker while this mode is active. + + Tracker + + process_detector diff --git a/gui/settings.cpp b/gui/settings.cpp index dcb9f6a0..1dc0e570 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -46,13 +46,14 @@ void options_dialog::set_disable_translation_state(bool value) }); } -options_dialog::options_dialog(std::function pause_keybindings) : +options_dialog::options_dialog(std::unique_ptr& tracker_dialog_, + std::function pause_keybindings) : pause_keybindings(std::move(pause_keybindings)) { ui.setupUi(this); - connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); - connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &options_dialog::doOK); + connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &options_dialog::close); tie_setting(main.tray_enabled, ui.trayp); tie_setting(main.tray_start, ui.tray_start); @@ -169,11 +170,13 @@ options_dialog::options_dialog(std::function pause_keybindings) : connect(val.button, &QPushButton::clicked, this, [=] { bind_key(val.opt, val.label); }); } } -} -void options_dialog::closeEvent(QCloseEvent *) -{ - done(result()); + if (tracker_dialog_ && tracker_dialog_->embeddable()) + { + tracker_dialog = tracker_dialog_.release(); + tracker_dialog->set_buttons_visible(false); + ui.tabWidget->addTab(tracker_dialog, tr("Tracker")); + } } void options_dialog::bind_key(key_opts& kopts, QLabel* label) @@ -228,41 +231,88 @@ void options_dialog::bind_key(key_opts& kopts, QLabel* label) label->setText(kopts_to_string(kopts)); } -void options_dialog::doOK() +void options_dialog::switch_to_tracker_tab() { - if (isHidden()) // close() can return true twice in a row it seems - return; - hide(); - if (!close()) // dialog was closed already - return; + if (tracker_dialog) + ui.tabWidget->setCurrentWidget(tracker_dialog); + else + eval_once(qDebug() << "options: asked for tab widget with old-style widget dialog!"); +} + +void options_dialog::unregister_tracker() +{ + if (tracker_dialog) + { + qDebug() << "options: unregister tracker"; + tracker_dialog->unregister_tracker(); + } +} + +void options_dialog::register_tracker(ITracker* t) +{ + if (tracker_dialog) + { + qDebug() << "options: register tracker"; + tracker_dialog->register_tracker(t); + } +} + +void options_dialog::tracker_module_changed() +{ + if (tracker_dialog) + { + unregister_tracker(); + reload(); + delete tracker_dialog; + tracker_dialog = nullptr; + } +} +void options_dialog::save() +{ main.b->save(); ui.game_detector->save(); set_disable_translation_state(ui.disable_translation->isChecked()); - emit closing(); + + if (tracker_dialog) + tracker_dialog->save(); } -void options_dialog::doCancel() +void options_dialog::reload() { ui.game_detector->revert(); - if (isHidden()) // close() can return true twice in a row it seems - return; - hide(); - if (!close()) // dialog was closed already - return; - main.b->reload(); - emit closing(); + if (tracker_dialog) + tracker_dialog->reload(); +} + +void options_dialog::doOK() +{ + if (isVisible()) + { + save(); + close(); + } } -void options_dialog::done(int res) +void options_dialog::doCancel() { if (isVisible()) { - if (res == QDialog::Accepted) - doOK(); - else - doCancel(); + reload(); + close(); } } + +void options_dialog::closeEvent(QCloseEvent *) +{ + reload(); + emit closing(); +} + +options_dialog::~options_dialog() +{ + if (tracker_dialog) + tracker_dialog->unregister_tracker(); +} diff --git a/gui/settings.hpp b/gui/settings.hpp index 8ef5aa2d..268ccb73 100644 --- a/gui/settings.hpp +++ b/gui/settings.hpp @@ -11,23 +11,33 @@ #include #include -class OTR_GUI_EXPORT options_dialog : public QDialog +class OTR_GUI_EXPORT options_dialog final : public QDialog { Q_OBJECT signals: void closing(); public: - explicit options_dialog(std::function pause_keybindings); + options_dialog(std::unique_ptr& tracker_dialog, std::function pause_keybindings); + ~options_dialog() override; + inline bool embeddable() noexcept { return false; } + void switch_to_tracker_tab(); + void register_tracker(ITracker* t); + void unregister_tracker(); + void tracker_module_changed(); + void save(); + void reload(); private: + void closeEvent(QCloseEvent*) override; + static QString kopts_to_string(const key_opts& opts); + main_settings main; std::function pause_keybindings; Ui::options_dialog ui; - void closeEvent(QCloseEvent*) override; - static QString kopts_to_string(const key_opts& opts); + ITrackerDialog* tracker_dialog = nullptr; + private slots: void doOK(); void doCancel(); - void done(int res) override; void bind_key(key_opts &kopts, QLabel* label); void set_disable_translation_state(bool value); }; -- cgit v1.2.3