summaryrefslogtreecommitdiffhomepage
path: root/gui/options-dialog.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-01-06 20:07:13 +0100
committerStanislaw Halik <sthalik@misaki.pl>2016-01-06 20:16:18 +0100
commit82f3d7373234cc0db79a22d476cb54b5eda7a0ea (patch)
tree65ee0194ad064cc470f95f7ca8efd533b089ca96 /gui/options-dialog.cpp
parent7e3807d048c5e0a8e0aa64fb49807bf5dfd11fc1 (diff)
parentf02baa0868f219076a641634625f7c032d3a9eef (diff)
Merge branch 'unstable' into trackhat
* unstable: (140 commits) tracker/pt: increase auto threshold bucket size again tracker/pt: limit max amount of extracted blobs gui: don't update main window if we're minimized tracker/pt: only show widget if the frame is visible tracker/pt: don't resize twice in widget freetrack/games: regen contrib/make-csv: perl sort isn't stable, don't ignore case tracker/pt: avoid widget temp QImage allocation spline-widget: oops, pass by reference tracker/pt: don't allocate temporary dynamic size arrays tracker/pt: don't copy points array needlessly tracker/pt: don't allocate temporary frame tracker/pt: cv::Mat::at<T> is slow, use cv::Mat::ptr tracker/pt: avoid widget malloc when able tracker/pt: optimize widget tracker/pt: update video widget at 40 -> 50 ms cmake/mingw-w64: update tracker/pt: reduce mutex contention gui: fix left margin tracker/pt: remove krap tracker/pt: move ctor out of the loop tracker/pt: nix unused tracker/pt: don't fill mask on frame pose-widget: also bilinear interpolation of alpha value ui: adjust margin ui: make more compact glwidget: use transparent octopus background api/mat: fix typos/breakage api/joy: refresh only manually on certain events pt: histogram more granular 6 -> 8 cmake/api: link with strmiids.lib on win32 tracker/pt: reduce auto thresholding histogram bucket size api/keys: prevent idempotent keys api/joy: move from header api/joy: prevent idempotent keypressed passed to receiver compat/options: get rid of std::string usage compat/options: move from header gui/settings: set parent, otherwise not modal gui/settings: don't forget to show a modal dialog before executing gui/main: don't raise a new window, it's enough to set visible api/joy: speed up poll_axis path api/joy: nix static, now that we're not a singleton tracker/joy: adapt to non-singleton joy worker joystick: no longer singleton, use fake window handle api/keys: use a fake window for DirectInput handle gui/keys: allow for pausing global keystrokes for options dialog api/keys: nix tautological #ifdef contrib/aruco: oops, right extension contrib/aruco: use @frost555's marker image api/camera-names: move to compat/ ...
Diffstat (limited to 'gui/options-dialog.cpp')
-rw-r--r--gui/options-dialog.cpp138
1 files changed, 95 insertions, 43 deletions
diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp
index 06346b25..1e734135 100644
--- a/gui/options-dialog.cpp
+++ b/gui/options-dialog.cpp
@@ -11,38 +11,42 @@
#include "keyboard.h"
#include <QPushButton>
#include <QLayout>
+#include <QDialog>
-OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(false)
+static QString kopts_to_string(const key_opts& kopts)
{
- ui.setupUi( this );
+ if (static_cast<QString>(kopts.guid) != "")
+ {
+ const int btn = kopts.button & ~Qt::KeyboardModifierMask;
+ const int mods = kopts.button & Qt::KeyboardModifierMask;
+ QString mm;
+ if (mods & Qt::ControlModifier) mm += "Control+";
+ if (mods & Qt::AltModifier) mm += "Alt+";
+ if (mods & Qt::ShiftModifier) mm += "Shift+";
+ return mm + "Joy button " + QString::number(btn);
+ }
+ if (static_cast<QString>(kopts.keycode) == "")
+ return "None";
+ return kopts.keycode;
+}
+
+OptionsDialog::OptionsDialog(main_settings& main,
+ State& state,
+ std::function<void()> register_global_keys,
+ std::function<void(bool)> pause_keybindings) :
+ main(main),
+ state(state),
+ register_global_keys(register_global_keys),
+ pause_keybindings(pause_keybindings)
+{
+ ui.setupUi(this);
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));
- tie_setting(s.s_main.tray_enabled, ui.trayp);
-
- tie_setting(s.s_main.center_at_startup, ui.center_at_startup);
+ tie_setting(main.tray_enabled, ui.trayp);
- tie_setting(s.s_main.tcomp_p, ui.tcomp_enable);
- tie_setting(s.s_main.tcomp_tz, ui.tcomp_rz);
-
- tie_setting(s.s_main.a_yaw.invert, ui.invert_yaw);
- tie_setting(s.s_main.a_pitch.invert, ui.invert_pitch);
- tie_setting(s.s_main.a_roll.invert, ui.invert_roll);
- tie_setting(s.s_main.a_x.invert, ui.invert_x);
- tie_setting(s.s_main.a_y.invert, ui.invert_y);
- tie_setting(s.s_main.a_z.invert, ui.invert_z);
-
- tie_setting(s.s_main.a_yaw.src, ui.src_yaw);
- tie_setting(s.s_main.a_pitch.src, ui.src_pitch);
- tie_setting(s.s_main.a_roll.src, ui.src_roll);
- tie_setting(s.s_main.a_x.src, ui.src_x);
- tie_setting(s.s_main.a_y.src, ui.src_y);
- tie_setting(s.s_main.a_z.src, ui.src_z);
-
- tie_setting(s.s_main.camera_yaw, ui.camera_yaw);
- tie_setting(s.s_main.camera_pitch, ui.camera_pitch);
- tie_setting(s.s_main.camera_roll, ui.camera_roll);
+ tie_setting(main.center_at_startup, ui.center_at_startup);
tie_setting(pt.camera_mode, ui.camera_mode);
@@ -86,48 +90,96 @@ OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(f
timer.start(100);
- connect(ui.bind_center, &QPushButton::pressed, [&]() -> void { bind_key(s.center.keycode, ui.center_text); });
- connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(s.zero.keycode, ui.zero_text); });
- connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(s.toggle.keycode, ui.toggle_text); });
+ tie_setting(main.tcomp_p, ui.tcomp_enable);
+ tie_setting(main.tcomp_tz, ui.tcomp_rz);
+
+ tie_setting(main.a_yaw.invert, ui.invert_yaw);
+ tie_setting(main.a_pitch.invert, ui.invert_pitch);
+ tie_setting(main.a_roll.invert, ui.invert_roll);
+ tie_setting(main.a_x.invert, ui.invert_x);
+ tie_setting(main.a_y.invert, ui.invert_y);
+ tie_setting(main.a_z.invert, ui.invert_z);
- ui.center_text->setText(s.center.keycode == "" ? "None" : static_cast<QString>(s.center.keycode));
- ui.toggle_text->setText(s.toggle.keycode == "" ? "None" : static_cast<QString>(s.toggle.keycode));
- ui.zero_text->setText(s.zero.keycode == "" ? "None" : static_cast<QString>(s.zero.keycode));
+ tie_setting(main.a_yaw.src, ui.src_yaw);
+ tie_setting(main.a_pitch.src, ui.src_pitch);
+ tie_setting(main.a_roll.src, ui.src_roll);
+ tie_setting(main.a_x.src, ui.src_x);
+ tie_setting(main.a_y.src, ui.src_y);
+ tie_setting(main.a_z.src, ui.src_z);
+
+ tie_setting(main.camera_yaw, ui.camera_yaw);
+ tie_setting(main.camera_pitch, ui.camera_pitch);
+ tie_setting(main.camera_roll, ui.camera_roll);
+
+ tie_setting(main.center_method, ui.center_method);
+
+ connect(ui.bind_center, &QPushButton::pressed, [&]() -> void { bind_key(main.key_center, ui.center_text); });
+ connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(main.key_zero, ui.zero_text); });
+ connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(main.key_toggle, ui.toggle_text); });
+ connect(ui.bind_start, &QPushButton::pressed, [&]() -> void { bind_key(main.key_start_tracking, ui.start_tracking_text); });
+ connect(ui.bind_stop, &QPushButton::pressed, [&]() -> void { bind_key(main.key_stop_tracking, ui.stop_tracking_text); });
+ connect(ui.bind_toggle_tracking, &QPushButton::pressed, [&]() -> void { bind_key(main.key_toggle_tracking, ui.toggle_tracking_text); });
+
+ ui.center_text->setText(kopts_to_string(main.key_center));
+ ui.toggle_text->setText(kopts_to_string(main.key_toggle));
+ ui.zero_text->setText(kopts_to_string(main.key_zero));
+
+ ui.start_tracking_text->setText(kopts_to_string(main.key_start_tracking));
+ ui.stop_tracking_text->setText(kopts_to_string(main.key_stop_tracking));
+ ui.toggle_tracking_text->setText(kopts_to_string(main.key_toggle_tracking));
}
-void OptionsDialog::bind_key(value<QString>& ret, QLabel* label)
+void OptionsDialog::bind_key(key_opts& kopts, QLabel* label)
{
- ret = "";
- QDialog d;
+ kopts.button = -1;
+ kopts.guid = "";
+ kopts.keycode = "";
+ QDialog d(this);
auto l = new QHBoxLayout;
l->setMargin(0);
- auto k = new KeyboardListener;
- l->addWidget(k);
+ KeyboardListener k;
+ l->addWidget(&k);
d.setLayout(l);
d.setFixedSize(QSize(500, 300));
d.setWindowFlags(Qt::Dialog);
- connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = s.toString(QKeySequence::PortableText); d.close(); });
+ d.setWindowModality(Qt::ApplicationModal);
+ connect(&k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void {
+ kopts.keycode = s.toString(QKeySequence::PortableText);
+ kopts.guid = "";
+ kopts.button = -1;
+ d.close();
+ });
+ connect(&k, &KeyboardListener::joystick_button_pressed, [&](QString guid, int idx, bool held) -> void {
+ if (!held)
+ {
+ kopts.guid = guid;
+ kopts.keycode = "";
+ kopts.button = idx;
+ d.close();
+ }
+ });
+ pause_keybindings(true);
+ d.show();
d.exec();
- label->setText(ret == "" ? "None" : static_cast<QString>(ret));
- delete k;
+ pause_keybindings(false);
+ register_global_keys();
+ label->setText(kopts_to_string(kopts));
delete l;
}
void OptionsDialog::doOK() {
- s.b->save();
pt.b->save();
- s.s_main.b->save();
acc.b->save();
+ main.b->save();
ui.game_detector->save();
this->close();
emit reload();
}
void OptionsDialog::doCancel() {
- s.b->reload();
pt.b->reload();
- s.s_main.b->reload();
acc.b->reload();
+ main.b->reload();
ui.game_detector->revert();
close();
}