diff options
Diffstat (limited to 'facetracknoir/ui.cpp')
-rw-r--r-- | facetracknoir/ui.cpp | 98 |
1 files changed, 37 insertions, 61 deletions
diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index d90fc762..50250d7c 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -9,6 +9,8 @@ #include "ui.h" #include "opentrack/tracker.h" #include "opentrack/options.hpp" +#include "ftnoir_tracker_pt/ftnoir_tracker_pt.h" +#include "ftnoir_filter_accela/ftnoir_filter_accela.h" #include "facetracknoir/new_file_dialog.h" #include <QFileDialog> #include <QDesktopServices> @@ -34,41 +36,21 @@ MainWindow::MainWindow() : connect(ui.btnEditCurves, SIGNAL(clicked()), this, SLOT(showCurveConfiguration())); connect(ui.btnShortcuts, SIGNAL(clicked()), this, SLOT(show_options_dialog())); - connect(ui.btnShowEngineControls, SIGNAL(clicked()), this, SLOT(showTrackerSettings())); connect(ui.btnShowServerControls, SIGNAL(clicked()), this, SLOT(showProtocolSettings())); - connect(ui.btnShowFilterControls, SIGNAL(clicked()), this, SLOT(showFilterSettings())); - - modules.filters().push_front(std::make_shared<dylib>("", dylib::Filter)); - - for (auto x : modules.trackers()) - ui.iconcomboTrackerSource->addItem(x->icon, x->name); for (auto x : modules.protocols()) ui.iconcomboProtocol->addItem(x->icon, x->name); - for (auto x : modules.filters()) - ui.iconcomboFilter->addItem(x->icon, x->name); - refresh_config_list(); connect(&config_list_timer, SIGNAL(timeout()), this, SLOT(refresh_config_list())); config_list_timer.start(1000 * 3); - tie_setting(s.tracker_dll, ui.iconcomboTrackerSource); tie_setting(s.protocol_dll, ui.iconcomboProtocol); - tie_setting(s.filter_dll, ui.iconcomboFilter); - - connect(ui.iconcomboTrackerSource, - &QComboBox::currentTextChanged, - [&](QString) -> void { if (pTrackerDialog) pTrackerDialog = nullptr; save(); }); connect(ui.iconcomboProtocol, &QComboBox::currentTextChanged, [&](QString) -> void { if (pProtocolDialog) pProtocolDialog = nullptr; save(); }); - connect(ui.iconcomboFilter, - &QComboBox::currentTextChanged, - [&](QString) -> void { if (pFilterDialog) pFilterDialog = nullptr; save(); }); - connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(startTracker())); connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stopTracker())); connect(ui.iconcomboProfile, SIGNAL(currentTextChanged(QString)), this, SLOT(profileSelected(QString))); @@ -110,6 +92,14 @@ MainWindow::MainWindow() : QMessageBox::Ok, QMessageBox::NoButton); } +void MainWindow::closeEvent(QCloseEvent *e) +{ + if (maybe_not_close_tracking()) + e->ignore(); + else + e->accept(); +} + bool MainWindow::get_new_config_name_from_dialog(QString& ret) { new_file_dialog dlg; @@ -245,8 +235,6 @@ void MainWindow::updateButtonState(bool running, bool inertialp) ui.btnStartTracker->setEnabled ( not_running ); ui.btnStopTracker->setEnabled ( running ); ui.iconcomboProtocol->setEnabled ( not_running ); - ui.iconcomboFilter->setEnabled ( not_running ); - ui.iconcomboTrackerSource->setEnabled(not_running); ui.video_frame_label->setVisible(not_running || inertialp); ui.profile_button->setEnabled(not_running); } @@ -262,7 +250,7 @@ void MainWindow::startTracker() { // tracker dtor needs run first work = nullptr; - libs = SelectedLibraries(ui.video_frame, current_tracker(), current_protocol(), current_filter()); + libs = SelectedLibraries(ui.video_frame, std::make_shared<Tracker_PT>(), current_protocol(), std::make_shared<FTNoIR_Filter>()); { double p[6] = {0,0,0, 0,0,0}; @@ -283,12 +271,6 @@ void MainWindow::startTracker() { reload_options(); - if (pTrackerDialog) - pTrackerDialog->register_tracker(libs.pTracker.get()); - - if (pFilterDialog) - pFilterDialog->register_filter(libs.pFilter.get()); - if (pProtocolDialog) pProtocolDialog->register_protocol(libs.pProtocol.get()); @@ -308,17 +290,9 @@ void MainWindow::stopTracker( ) { pose_update_timer.stop(); ui.pose_display->rotateBy(0, 0, 0, 0, 0, 0); - if (pTrackerDialog) - pTrackerDialog->unregister_tracker(); - if (pProtocolDialog) pProtocolDialog->unregister_protocol(); - if (pFilterDialog) - pFilterDialog->unregister_filter(); - - maybe_save(); - work = nullptr; libs = SelectedLibraries(); @@ -373,7 +347,7 @@ void MainWindow::set_title(const QString& game_title_) if (game_title_ != "") game_title = " :: " + game_title_; QString current = group::ini_filename(); - setWindowTitle(const_cast<const char*>(opentrack_version) + QStringLiteral(" :: ") + current + game_title); + setWindowTitle(const_cast<const char*>(opentrack_version) + QStringLiteral(" opentrack") + QStringLiteral(" :: ") + current + game_title); } void MainWindow::showHeadPose() @@ -386,12 +360,12 @@ void MainWindow::showHeadPose() } template<typename t> -bool mk_dialog(mem<dylib> lib, mem<t>& orig) +bool mk_dialog(mem<dylib> lib, mem<t>* orig) { - if (orig && orig->isVisible()) + if (*orig && (*orig)->isVisible()) { - orig->show(); - orig->raise(); + (*orig)->show(); + (*orig)->raise(); return false; } @@ -401,34 +375,19 @@ bool mk_dialog(mem<dylib> lib, mem<t>& orig) dialog->setWindowFlags(Qt::Dialog); dialog->setFixedSize(dialog->size()); - orig = dialog; + *orig = dialog; dialog->show(); dialog->raise(); - QObject::connect(dialog.get(), &BaseDialog::closing, [&]() -> void { orig = nullptr; }); - return true; } return false; } - -void MainWindow::showTrackerSettings() -{ - if (mk_dialog(current_tracker(), pTrackerDialog) && libs.pTracker) - pTrackerDialog->register_tracker(libs.pTracker.get()); -} - void MainWindow::showProtocolSettings() { - if (mk_dialog(current_protocol(), pProtocolDialog) && libs.pProtocol) + if (mk_dialog(current_protocol(), &pProtocolDialog) && libs.pProtocol) pProtocolDialog->register_protocol(libs.pProtocol.get()); } - -void MainWindow::showFilterSettings() { - if (mk_dialog(current_filter(), pFilterDialog) && libs.pFilter) - pFilterDialog->register_filter(libs.pFilter.get()); -} - template<typename t, typename... Args> bool mk_window(mem<t>* place, Args... params) { @@ -449,7 +408,7 @@ bool mk_window(mem<t>* place, Args... params) } void MainWindow::show_options_dialog() { - if (mk_window(&options_widget)) + if (mk_window<OptionsDialog, State&>(&options_widget, static_cast<State&>(*this))) connect(options_widget.get(), SIGNAL(reload()), this, SLOT(reload_options())); } @@ -457,12 +416,29 @@ void MainWindow::showCurveConfiguration() { mk_window<MapWidget, Mappings&, main_settings&>(&mapping_widget, pose, s); } +bool MainWindow::maybe_not_close_tracking() +{ + if (work != nullptr) + { + auto btn = QMessageBox::warning(this, "Tracking active", + "Are you sure you want to exit? This will terminate tracking.", + QMessageBox::Yes, QMessageBox::No); + if (btn == QMessageBox::No) + return true; + } + return false; +} + void MainWindow::exit() { - QCoreApplication::exit(0); + + if (!maybe_not_close_tracking()) + QCoreApplication::exit(0); } void MainWindow::profileSelected(QString name) { + maybe_save(); + if (name == "" || is_refreshing_profiles) return; |