summaryrefslogtreecommitdiffhomepage
path: root/gui/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/ui.cpp')
-rw-r--r--gui/ui.cpp103
1 files changed, 41 insertions, 62 deletions
diff --git a/gui/ui.cpp b/gui/ui.cpp
index 5ea5dbfa..86c9fa9c 100644
--- a/gui/ui.cpp
+++ b/gui/ui.cpp
@@ -9,6 +9,8 @@
#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 "new_file_dialog.h"
#include <QFileDialog>
#include <QDesktopServices>
@@ -23,7 +25,8 @@ MainWindow::MainWindow() :
pose_update_timer(this),
kbd_quit(QKeySequence("Ctrl+Q"), this),
no_feed_pixmap(":/images/no-feed.png"),
- is_refreshing_profiles(false)
+ is_refreshing_profiles(false),
+ update_query(this)
{
ui.setupUi(this);
@@ -34,41 +37,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 +93,16 @@ MainWindow::MainWindow() :
QMessageBox::Ok, QMessageBox::NoButton);
ui.btnStartTracker->setFocus();
+
+ update_query.maybe_show_dialog();
+}
+
+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)
@@ -247,8 +240,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);
}
@@ -264,7 +255,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};
@@ -285,12 +276,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());
@@ -312,17 +297,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();
@@ -379,7 +356,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()
@@ -392,12 +369,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;
}
@@ -407,34 +384,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)
{
@@ -455,7 +417,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()));
}
@@ -463,12 +425,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;