summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2021-12-14 21:41:46 +0100
committerStanislaw Halik <sthalik@misaki.pl>2021-12-14 21:43:03 +0100
commitd30123f938c3bb9b8e556eedabccc265818dc06a (patch)
treeda25c33b8a146592538925f936979bbbb8633b90 /gui
parentd3b86b83f3a9d64cc0c7b9562a2ad8ae37dd16f5 (diff)
gui, opentrack: initial support for embeddable module dialogs
Diffstat (limited to 'gui')
-rw-r--r--gui/lang/nl_NL.ts4
-rw-r--r--gui/lang/ru_RU.ts4
-rw-r--r--gui/lang/stub.ts4
-rw-r--r--gui/lang/zh_CN.ts4
-rw-r--r--gui/settings.cpp104
-rw-r--r--gui/settings.hpp20
6 files changed, 108 insertions, 32 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 &quot;clear calibration&quot; 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 &quot;clear calibration&quot; 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 &quot;clear calibration&quot; 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 &quot;clear calibration&quot; 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);
};