From 69555ddc87fe727d59385e1752d3ba66aa5549ee Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 16 Dec 2021 13:04:49 +0100 Subject: api, gui, opentrack: allow embedding proto, filter dialogs --- gui/settings.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++++-------- gui/settings.hpp | 20 ++++++++-- 2 files changed, 112 insertions(+), 18 deletions(-) (limited to 'gui') diff --git a/gui/settings.cpp b/gui/settings.cpp index 907fe8f3..7d74c762 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -47,6 +47,8 @@ void options_dialog::set_disable_translation_state(bool value) } options_dialog::options_dialog(std::unique_ptr& tracker_dialog_, + std::unique_ptr& proto_dialog_, + std::unique_ptr& filter_dialog_, std::function pause_keybindings) : pause_keybindings(std::move(pause_keybindings)) { @@ -177,6 +179,18 @@ options_dialog::options_dialog(std::unique_ptr& tracker_dialog_, tracker_dialog->set_buttons_visible(false); ui.tabWidget->addTab(tracker_dialog, tr("Tracker")); } + if (proto_dialog_ && proto_dialog_->embeddable()) + { + proto_dialog = proto_dialog_.release(); + proto_dialog->set_buttons_visible(false); + ui.tabWidget->addTab(proto_dialog, tr("Output")); + } + if (filter_dialog_ && filter_dialog_->embeddable()) + { + filter_dialog = filter_dialog_.release(); + filter_dialog->set_buttons_visible(false); + ui.tabWidget->addTab(filter_dialog, tr("Filter")); + } } void options_dialog::bind_key(key_opts& kopts, QLabel* label) @@ -236,23 +250,23 @@ void options_dialog::switch_to_tracker_tab() if (tracker_dialog) ui.tabWidget->setCurrentWidget(tracker_dialog); else - eval_once(qDebug() << "options: asked for tab widget with old-style widget dialog!"); + eval_once(qDebug() << "options: asked for tracker tab widget with old-style widget dialog!"); } -void options_dialog::unregister_tracker() +void options_dialog::switch_to_proto_tab() { - if (tracker_dialog) - { - tracker_dialog->unregister_tracker(); - } + if (proto_dialog) + ui.tabWidget->setCurrentWidget(proto_dialog); + else + eval_once(qDebug() << "options: asked for proto tab widget with old-style widget dialog!"); } -void options_dialog::register_tracker(ITracker* t) +void options_dialog::switch_to_filter_tab() { - if (tracker_dialog) - { - tracker_dialog->register_tracker(t); - } + if (filter_dialog) + ui.tabWidget->setCurrentWidget(filter_dialog); + else + eval_once(qDebug() << "options: asked for filter tab widget with old-style widget dialog!"); } void options_dialog::tracker_module_changed() @@ -266,14 +280,75 @@ void options_dialog::tracker_module_changed() } } +void options_dialog::proto_module_changed() +{ + if (proto_dialog) + { + unregister_protocol(); + reload(); + delete proto_dialog; + proto_dialog = nullptr; + } +} + +void options_dialog::filter_module_changed() +{ + if (filter_dialog) + { + unregister_filter(); + reload(); + delete filter_dialog; + filter_dialog = nullptr; + } +} + +void options_dialog::register_tracker(ITracker* t) +{ + if (tracker_dialog) + tracker_dialog->register_tracker(t); +} + +void options_dialog::unregister_tracker() +{ + if (tracker_dialog) + tracker_dialog->unregister_tracker(); +} + +void options_dialog::register_protocol(IProtocol* p) +{ + if (proto_dialog) + proto_dialog->register_protocol(p); +} + +void options_dialog::unregister_protocol() +{ + if (proto_dialog) + proto_dialog->unregister_protocol(); +} + +void options_dialog::register_filter(IFilter* f) +{ + if (filter_dialog) + filter_dialog->register_filter(f); +} + +void options_dialog::unregister_filter() +{ + if (filter_dialog) + filter_dialog->unregister_filter(); +} + +using module_list = std::initializer_list; + void options_dialog::save() { main.b->save(); ui.game_detector->save(); set_disable_translation_state(ui.disable_translation->isChecked()); - if (tracker_dialog) - tracker_dialog->save(); + for (auto* dlg : module_list{ tracker_dialog, proto_dialog, filter_dialog }) + if (dlg) + dlg->save(); } void options_dialog::reload() @@ -281,8 +356,9 @@ void options_dialog::reload() ui.game_detector->revert(); main.b->reload(); - if (tracker_dialog) - tracker_dialog->reload(); + for (auto* dlg : module_list{ tracker_dialog, proto_dialog, filter_dialog }) + if (dlg) + dlg->reload(); } void options_dialog::doOK() @@ -313,4 +389,8 @@ options_dialog::~options_dialog() { if (tracker_dialog) tracker_dialog->unregister_tracker(); + if (proto_dialog) + proto_dialog->unregister_protocol(); + if (filter_dialog) + filter_dialog->unregister_filter(); } diff --git a/gui/settings.hpp b/gui/settings.hpp index 268ccb73..2cb3492c 100644 --- a/gui/settings.hpp +++ b/gui/settings.hpp @@ -17,13 +17,24 @@ class OTR_GUI_EXPORT options_dialog final : public QDialog signals: void closing(); public: - options_dialog(std::unique_ptr& tracker_dialog, std::function pause_keybindings); + options_dialog(std::unique_ptr& tracker_dialog_, + std::unique_ptr& proto_dialog_, + std::unique_ptr& filter_dialog_, + std::function pause_keybindings); ~options_dialog() override; inline bool embeddable() noexcept { return false; } void switch_to_tracker_tab(); + void switch_to_proto_tab(); + void switch_to_filter_tab(); + void tracker_module_changed(); + void proto_module_changed(); + void filter_module_changed(); void register_tracker(ITracker* t); void unregister_tracker(); - void tracker_module_changed(); + void register_protocol(IProtocol* p); + void unregister_protocol(); + void register_filter(IFilter* f); + void unregister_filter(); void save(); void reload(); private: @@ -33,7 +44,10 @@ private: main_settings main; std::function pause_keybindings; Ui::options_dialog ui; - ITrackerDialog* tracker_dialog = nullptr; + + ITrackerDialog* tracker_dialog = nullptr; + IProtocolDialog* proto_dialog = nullptr; + IFilterDialog* filter_dialog = nullptr; private slots: void doOK(); -- cgit v1.2.3