summaryrefslogtreecommitdiffhomepage
path: root/gui/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/ui.cpp')
-rw-r--r--gui/ui.cpp112
1 files changed, 42 insertions, 70 deletions
diff --git a/gui/ui.cpp b/gui/ui.cpp
index 31bce40b..09739b92 100644
--- a/gui/ui.cpp
+++ b/gui/ui.cpp
@@ -8,6 +8,8 @@
#include "ui.h"
#include "opentrack/tracker.h"
+#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>
@@ -23,7 +25,8 @@ MainWindow::MainWindow() :
pose_update_timer(this),
kbd_quit(QKeySequence("Ctrl+Q"), this),
is_refreshing_profiles(false),
- keys_paused(false)
+ keys_paused(false),
+ update_query(this)
{
ui.setupUi(this);
@@ -33,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)));
@@ -125,6 +108,16 @@ MainWindow::MainWindow() :
connect(this, &MainWindow::emit_minimized, this, &MainWindow::mark_minimized, Qt::QueuedConnection);
ui.btnStartTracker->setFocus();
+
+ update_query.maybe_show_dialog();
+}
+
+void MainWindow::closeEvent(QCloseEvent *e)
+{
+ if (maybe_not_close_tracking())
+ e->ignore();
+ else
+ e->accept();
}
void MainWindow::register_shortcuts()
@@ -278,8 +271,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);
}
@@ -298,7 +289,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};
@@ -319,12 +310,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());
@@ -349,17 +334,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();
@@ -382,11 +359,10 @@ void MainWindow::display_pose(const double *mapped, const double *raw)
if (mapping_widget)
mapping_widget->update();
- double mapped_[6], raw_[6];
+ double raw_[6];
for (int i = 0; i < 6; i++)
{
- mapped_[i] = (int) mapped[i];
raw_[i] = (int) raw[i];
}
@@ -397,13 +373,6 @@ void MainWindow::display_pose(const double *mapped, const double *raw)
ui.raw_pitch->display(raw_[Pitch]);
ui.raw_roll->display(raw_[Roll]);
- ui.pose_x->display(mapped_[TX]);
- ui.pose_y->display(mapped_[TY]);
- ui.pose_z->display(mapped_[TZ]);
- ui.pose_yaw->display(mapped_[Yaw]);
- ui.pose_pitch->display(mapped_[Pitch]);
- ui.pose_roll->display(mapped_[Roll]);
-
QString game_title;
if (libs.pProtocol)
game_title = libs.pProtocol->game_name();
@@ -416,7 +385,7 @@ void MainWindow::set_title(const QString& game_title_)
if (game_title_ != "")
game_title = " :: " + game_title_;
QString current = group::ini_filename();
- setWindowTitle(opentrack_version + QStringLiteral(" :: ") + current + game_title);
+ setWindowTitle(opentrack_version + QStringLiteral(" opentrack") + QStringLiteral(" :: ") + current + game_title);
}
void MainWindow::showHeadPose()
@@ -432,12 +401,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;
}
@@ -447,33 +416,18 @@ bool mk_dialog(mem<dylib> lib, mem<t>& orig)
dialog->setWindowFlags(Qt::Dialog);
dialog->setFixedSize(dialog->size());
- orig = dialog;
+ *orig = dialog;
dialog->show();
- QObject::connect(dialog.get(), &plugin_api::detail::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)
{
@@ -495,6 +449,7 @@ bool mk_window(mem<t>* place, Args&&... params)
void MainWindow::show_options_dialog() {
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()));
@@ -504,12 +459,29 @@ void MainWindow::showCurveConfiguration() {
mk_window(&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;