diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-01-06 20:07:13 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-01-06 20:16:18 +0100 |
commit | 82f3d7373234cc0db79a22d476cb54b5eda7a0ea (patch) | |
tree | 65ee0194ad064cc470f95f7ca8efd533b089ca96 /gui/ui.cpp | |
parent | 7e3807d048c5e0a8e0aa64fb49807bf5dfd11fc1 (diff) | |
parent | f02baa0868f219076a641634625f7c032d3a9eef (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/ui.cpp')
-rw-r--r-- | gui/ui.cpp | 108 |
1 files changed, 71 insertions, 37 deletions
@@ -8,9 +8,9 @@ #include "ui.h" #include "opentrack/tracker.h" -#include "opentrack/options.hpp" #include "tracker-pt/ftnoir_tracker_pt.h" #include "filter-accela/ftnoir_filter_accela.h" +#include "opentrack-compat/options.hpp" #include "new_file_dialog.h" #include <QFileDialog> #include <QDesktopServices> @@ -24,8 +24,8 @@ MainWindow::MainWindow() : pose_update_timer(this), kbd_quit(QKeySequence("Ctrl+Q"), this), - no_feed_pixmap(":/images/no-feed.png"), is_refreshing_profiles(false), + keys_paused(false), update_query(this) { ui.setupUi(this); @@ -33,7 +33,6 @@ MainWindow::MainWindow() : setFixedSize(size()); updateButtonState(false, false); - ui.video_frame_label->setPixmap(no_feed_pixmap); connect(ui.btnEditCurves, SIGNAL(clicked()), this, SLOT(showCurveConfiguration())); connect(ui.btnShortcuts, SIGNAL(clicked()), this, SLOT(show_options_dialog())); @@ -91,7 +90,23 @@ MainWindow::MainWindow() : "Configuration not saved.", "Can't create configuration directory! Expect major malfunction.", QMessageBox::Ok, QMessageBox::NoButton); - + + connect(this, &MainWindow::emit_start_tracker, + this, [&]() -> void { if (keys_paused) return; qDebug() << "start tracker"; startTracker(); }, + Qt::QueuedConnection); + + connect(this, &MainWindow::emit_stop_tracker, + this, [&]() -> void { if (keys_paused) return; qDebug() << "stop tracker"; stopTracker(); }, + Qt::QueuedConnection); + + connect(this, &MainWindow::emit_toggle_tracker, + this, [&]() -> void { if (keys_paused) return; qDebug() << "toggle tracker"; if (work) stopTracker(); else startTracker(); }, + Qt::QueuedConnection); + + register_shortcuts(); + + connect(this, &MainWindow::emit_minimized, this, &MainWindow::mark_minimized, Qt::QueuedConnection); + ui.btnStartTracker->setFocus(); update_query.maybe_show_dialog(); @@ -105,6 +120,22 @@ void MainWindow::closeEvent(QCloseEvent *e) e->accept(); } +void MainWindow::register_shortcuts() +{ + using t_shortcut = std::tuple<key_opts&, Shortcuts::fun>; + + std::vector<t_shortcut> keys { + t_shortcut(s.key_start_tracking, [&]() -> void { emit_start_tracker(); }), + t_shortcut(s.key_stop_tracking, [&]() -> void { emit_stop_tracker(); }), + t_shortcut(s.key_toggle_tracking, [&]() -> void { emit_toggle_tracker(); }), + }; + + global_shortcuts.reload(keys); + + if (work) + work->reload_shortcuts(); +} + bool MainWindow::get_new_config_name_from_dialog(QString& ret) { new_file_dialog dlg; @@ -252,6 +283,9 @@ void MainWindow::reload_options() } void MainWindow::startTracker() { + if (work) + return; + // tracker dtor needs run first work = nullptr; @@ -272,7 +306,7 @@ void MainWindow::startTracker() { return; } - work = std::make_shared<Work>(s, pose, libs, this, winId()); + work = std::make_shared<Work>(s, pose, libs, winId()); reload_options(); @@ -291,7 +325,10 @@ void MainWindow::startTracker() { ui.btnStopTracker->setFocus(); } -void MainWindow::stopTracker( ) { +void MainWindow::stopTracker() { + if (!work) + return; + //ui.game_name->setText("Not connected"); pose_update_timer.stop(); @@ -361,6 +398,9 @@ void MainWindow::set_title(const QString& game_title_) void MainWindow::showHeadPose() { + if (!ui.video_frame->isEnabled()) + return; + double mapped[6], raw[6]; work->tracker->get_raw_and_mapped_poses(mapped, raw); @@ -386,7 +426,6 @@ bool mk_dialog(mem<dylib> lib, mem<t>* orig) *orig = dialog; dialog->show(); - dialog->raise(); return true; } @@ -398,7 +437,7 @@ void MainWindow::showProtocolSettings() { pProtocolDialog->register_protocol(libs.pProtocol.get()); } template<typename t, typename... Args> -bool mk_window(mem<t>* place, Args... params) +bool mk_window(mem<t>* place, Args&&... params) { if (*place && (*place)->isVisible()) { @@ -408,21 +447,24 @@ bool mk_window(mem<t>* place, Args... params) } else { - *place = std::make_shared<t>(params...); + *place = std::make_shared<t>(std::forward<Args>(params)...); (*place)->setWindowFlags(Qt::Dialog); (*place)->show(); - (*place)->raise(); return true; } } void MainWindow::show_options_dialog() { - if (mk_window<OptionsDialog, State&>(&options_widget, static_cast<State&>(*this))) + if (mk_window(&options_widget, + s, + *this, + [&]() -> void { register_shortcuts(); }, + [&](bool flag) -> void { keys_paused = flag; })) connect(options_widget.get(), SIGNAL(reload()), this, SLOT(reload_options())); } void MainWindow::showCurveConfiguration() { - mk_window<MapWidget, Mappings&, main_settings&>(&mapping_widget, pose, s); + mk_window(&mapping_widget, pose, s); } bool MainWindow::maybe_not_close_tracking() @@ -468,27 +510,6 @@ void MainWindow::profileSelected(QString name) } } -void MainWindow::shortcutRecentered() -{ - qDebug() << "Center"; - if (work) - work->tracker->center(); -} - -void MainWindow::shortcutToggled() -{ - qDebug() << "Toggle"; - if (work) - work->tracker->toggle_enabled(); -} - -void MainWindow::shortcutZeroed() -{ - qDebug() << "Zero"; - if (work) - work->tracker->zero(); -} - void MainWindow::ensure_tray() { if (tray) @@ -512,15 +533,28 @@ void MainWindow::restore_from_tray(QSystemTrayIcon::ActivationReason) void MainWindow::changeEvent(QEvent* e) { - if (s.tray_enabled && e->type() == QEvent::WindowStateChange && (windowState() & Qt::WindowMinimized)) + if (e->type() == QEvent::WindowStateChange) { - if (!tray) - ensure_tray(); - hide(); + const bool is_minimized = windowState() & Qt::WindowMinimized; + + if (s.tray_enabled && is_minimized) + { + if (!tray) + ensure_tray(); + hide(); + } + + emit_minimized(is_minimized); } + QMainWindow::changeEvent(e); } +void MainWindow::mark_minimized(bool is_minimized) +{ + ui.video_frame->setEnabled(!is_minimized); +} + void MainWindow::maybe_start_profile_from_executable() { if (!work) |