diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2021-12-14 21:41:46 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2021-12-14 21:43:03 +0100 |
commit | d30123f938c3bb9b8e556eedabccc265818dc06a (patch) | |
tree | da25c33b8a146592538925f936979bbbb8633b90 | |
parent | d3b86b83f3a9d64cc0c7b9562a2ad8ae37dd16f5 (diff) |
gui, opentrack: initial support for embeddable module dialogs
-rw-r--r-- | gui/lang/nl_NL.ts | 4 | ||||
-rw-r--r-- | gui/lang/ru_RU.ts | 4 | ||||
-rw-r--r-- | gui/lang/stub.ts | 4 | ||||
-rw-r--r-- | gui/lang/zh_CN.ts | 4 | ||||
-rw-r--r-- | gui/settings.cpp | 104 | ||||
-rw-r--r-- | gui/settings.hpp | 20 | ||||
-rw-r--r-- | opentrack/main-window.cpp | 79 | ||||
-rw-r--r-- | opentrack/main-window.hpp | 9 |
8 files changed, 171 insertions, 57 deletions
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 <source>Freeze the position returned by the tracker while this mode is active.</source> <translation type="unfinished"></translation> </message> + <message> + <source>Tracker</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>process_detector</name> 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 <source>Disable user interface localization</source> <translation>Использовать английский интерфейс</translation> </message> + <message> + <source>Tracker</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>process_detector</name> 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 <source>Disable user interface localization</source> <translation type="unfinished"></translation> </message> + <message> + <source>Tracker</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>process_detector</name> 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 <source>Freeze the position returned by the tracker while this mode is active.</source> <translation type="unfinished"></translation> </message> + <message> + <source>Tracker</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>process_detector</name> 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<void(bool)> pause_keybindings) : +options_dialog::options_dialog(std::unique_ptr<ITrackerDialog>& tracker_dialog_, + std::function<void(bool)> 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<void(bool)> 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 <QDialog> #include <QWidget> -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<void(bool)> pause_keybindings); + options_dialog(std::unique_ptr<ITrackerDialog>& tracker_dialog, std::function<void(bool)> 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<void(bool)> 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); }; diff --git a/opentrack/main-window.cpp b/opentrack/main-window.cpp index 89100cbd..84c1cc0c 100644 --- a/opentrack/main-window.cpp +++ b/opentrack/main-window.cpp @@ -86,7 +86,7 @@ void main_window::init_dylibs() ui.iconcomboFilter->addItem(x->icon, x->name, x->module_name); connect(ui.iconcomboTrackerSource, &QComboBox::currentTextChanged, - this, [&](const QString&) { pTrackerDialog = nullptr; }); + this, [this](const QString&) { pTrackerDialog = nullptr; if (options_widget) options_widget->tracker_module_changed(); }); connect(ui.iconcomboProtocol, &QComboBox::currentTextChanged, this, [this](const QString&) { pProtocolDialog = nullptr; }); @@ -409,7 +409,18 @@ void main_window::start_tracker_() } if (pTrackerDialog) - pTrackerDialog->register_tracker(work->libs.pTracker.get()); + { + auto* tracker = &*work->libs.pTracker; + pTrackerDialog->register_tracker(tracker); + } + + if (options_widget) + { + // XXX TODO other module types + auto* tracker = &*work->libs.pTracker; + if (tracker) + options_widget->register_tracker(tracker); + } if (pFilterDialog) pFilterDialog->register_filter(work->libs.pFilter.get()); @@ -438,6 +449,12 @@ void main_window::stop_tracker_() pose_update_timer.stop(); ui.pose_display->present(0,0,0, 0,0,0); + if (options_widget) + { + // XXX TODO other module types + options_widget->unregister_tracker(); + } + if (pTrackerDialog) pTrackerDialog->unregister_tracker(); @@ -543,7 +560,7 @@ static void show_window(QWidget& d, bool fresh) } template<typename t, typename F> -static bool mk_window_common(std::unique_ptr<t>& d, F&& fun) +static bool mk_window_common(std::unique_ptr<t>& d, bool show, F&& fun) { bool fresh = false; @@ -551,13 +568,16 @@ static bool mk_window_common(std::unique_ptr<t>& d, F&& fun) d = fun(), fresh = !!d; if (d) - show_window(*d, fresh); + { + if (show && !d->embeddable()) + show_window(*d, fresh); + } return fresh; } template<typename t, typename... Args> -static bool mk_window(std::unique_ptr<t>& place, Args&&... params) +static bool mk_window(std::unique_ptr<t>& place, bool show, Args&&... params) { return mk_window_common(place, show, [&] { return std::make_unique<t>(std::forward<Args>(params)...); @@ -565,11 +585,11 @@ static bool mk_window(std::unique_ptr<t>& place, Args&&... params) } template<typename t> -static bool mk_dialog(std::unique_ptr<t>& place, const std::shared_ptr<dylib>& lib) +static bool mk_dialog(std::unique_ptr<t>& place, bool show, const std::shared_ptr<dylib>& lib) { using u = std::unique_ptr<t>; - return mk_window_common(place, [&] { + return mk_window_common(place, show, [&] { if (lib && lib->Dialog) return u{ (t*)lib->Dialog() }; else @@ -577,44 +597,59 @@ static bool mk_dialog(std::unique_ptr<t>& place, const std::shared_ptr<dylib>& l }); } -void main_window::show_tracker_settings() +void main_window::show_tracker_settings_(bool show) { - if (mk_dialog(pTrackerDialog, current_tracker()) && work && work->libs.pTracker) + if (mk_dialog(pTrackerDialog, show, current_tracker()) && work && work->libs.pTracker) + { pTrackerDialog->register_tracker(work->libs.pTracker.get()); - if (pTrackerDialog) - QObject::connect(pTrackerDialog.get(), &ITrackerDialog::closing, - this, [this] { pTrackerDialog = nullptr; }); + QObject::connect(&*pTrackerDialog, &ITrackerDialog::closing, + this, [this] { pTrackerDialog = nullptr; qDebug() << "deleted dialog"; }); + } + else if (show && pTrackerDialog && pTrackerDialog->embeddable()) + { + show_options_dialog(); + options_widget->switch_to_tracker_tab(); + } } -void main_window::show_proto_settings() +void main_window::show_proto_settings_(bool show) { - if (mk_dialog(pProtocolDialog, current_protocol()) && work && work->libs.pProtocol) + if (mk_dialog(pProtocolDialog, show, current_protocol()) && work && work->libs.pProtocol) + { pProtocolDialog->register_protocol(work->libs.pProtocol.get()); - if (pProtocolDialog) - QObject::connect(pProtocolDialog.get(), &IProtocolDialog::closing, + QObject::connect(&*pProtocolDialog, &IProtocolDialog::closing, this, [this] { pProtocolDialog = nullptr; }); + } } -void main_window::show_filter_settings() +void main_window::show_filter_settings_(bool show) { - if (mk_dialog(pFilterDialog, current_filter()) && work && work->libs.pFilter) + if (mk_dialog(pFilterDialog, show, current_filter()) && work && work->libs.pFilter) + { pFilterDialog->register_filter(work->libs.pFilter.get()); - if (pFilterDialog) - QObject::connect(pFilterDialog.get(), &IFilterDialog::closing, + QObject::connect(&*pFilterDialog, &IFilterDialog::closing, this, [this] { pFilterDialog = nullptr; }); + } } void main_window::show_options_dialog() { - if (mk_window(options_widget, [&](bool flag) { set_keys_enabled(!flag); })) + if (options_widget) + return; + + show_tracker_settings_(false); + + if (mk_window(options_widget, true, pTrackerDialog, + [this](bool flag) { set_keys_enabled(!flag); })) { // move shortcuts to a separate bundle and add a migration -sh 20180218 + connect(&*options_widget, &options_dialog::closing, [this] { options_widget = nullptr; }); } } void main_window::show_mapping_window() { - mk_window(mapping_widget, pose); + mk_window(mapping_widget, true, pose); } void main_window::exit(int status) diff --git a/opentrack/main-window.hpp b/opentrack/main-window.hpp index 9ffb7019..cec76b7a 100644 --- a/opentrack/main-window.hpp +++ b/opentrack/main-window.hpp @@ -103,9 +103,12 @@ class main_window final : public QMainWindow, private State void closeEvent(QCloseEvent *event) override; bool event(QEvent *event) override; - void show_tracker_settings(); - void show_proto_settings(); - void show_filter_settings(); + void show_tracker_settings_(bool show); + void show_proto_settings_(bool show); + void show_filter_settings_(bool show); + void show_tracker_settings() { show_tracker_settings_(true); } + void show_proto_settings() { show_proto_settings_(true); } + void show_filter_settings() { show_filter_settings_(true); } void show_options_dialog(); void show_mapping_window(); |