diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-08 05:55:32 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-08 05:55:59 +0200 |
commit | 527eef2a2f0e68b286e1b782ba148ecdfafbb89c (patch) | |
tree | 2be0f0b96df712f7b12534291db3c36564be62ca /facetracknoir | |
parent | 3a54a111567370ecf903704d702d12736b693a8e (diff) | |
parent | ab47eac174db02710a7fa6c194e00c31cef755a4 (diff) |
Merge branch 'unstable' into trackhat-ui
Diffstat (limited to 'facetracknoir')
-rw-r--r-- | facetracknoir/main.cpp | 26 | ||||
-rw-r--r-- | facetracknoir/ui.cpp | 72 |
2 files changed, 37 insertions, 61 deletions
diff --git a/facetracknoir/main.cpp b/facetracknoir/main.cpp index 6d29e3b5..326b40ec 100644 --- a/facetracknoir/main.cpp +++ b/facetracknoir/main.cpp @@ -60,34 +60,14 @@ int main(int argc, char** argv) QApplication::setAttribute(Qt::AA_X11InitThreads, true); QApplication app(argc, argv); - QCommandLineParser p; - p.setApplicationDescription("opentrack - Head tracking software for MS Windows, Linux, and Apple OSX"); - p.addHelpOption(); - QCommandLineOption autostartOption(QStringList() << "a" << "autostart", "Load <profile> and start tracking", "profile"); - p.addOption(autostartOption); - p.process(app); - - QString profile = p.value(autostartOption); - - bool use_profile = profile.endsWith(".ini") && QFileInfo(profile).exists() && QFileInfo(profile).isFile(); - if (!profile.isEmpty() && !use_profile) - QMessageBox::warning(nullptr, "Can't load profile", "Profile " + profile + " specified but can't be opened!", - QMessageBox::Ok, QMessageBox::NoButton); - - if (use_profile) - MainWindow::set_profile(profile); - auto w = std::make_shared<MainWindow>(); - - if (use_profile) - w->startTracker(); - + w->show(); app.exec(); - // on MSVC crashes in atexit + // on MSVC crashes in atexit #ifdef _MSC_VER - TerminateProcess(GetCurrentProcess(), 0); + TerminateProcess(GetCurrentProcess(), 0); #endif return 0; } diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index 8cf14050..405c516a 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -310,64 +310,60 @@ void MainWindow::showHeadPose() } template<typename t> -mem<t> mk_dialog(mem<dylib> lib) +bool mk_dialog(mem<dylib> lib, mem<t>* orig) { + if (*orig && (*orig)->isVisible()) + { + (*orig)->show(); + (*orig)->raise(); + return false; + } + if (lib && lib->Dialog) { auto dialog = mem<t>(reinterpret_cast<t*>(lib->Dialog())); dialog->setWindowFlags(Qt::Dialog); dialog->setFixedSize(dialog->size()); - return dialog; + + *orig = dialog; + dialog->show(); + dialog->raise(); + + return true; } - return nullptr; + return false; } - void MainWindow::showProtocolSettings() { - if (pProtocolDialog && pProtocolDialog->isVisible()) + if (mk_dialog(current_protocol(), &pProtocolDialog) && libs.pProtocol) + pProtocolDialog->register_protocol(libs.pProtocol.get()); +} +template<typename t, typename... Args> +bool mk_window(mem<t>* place, Args... params) +{ + if (*place && (*place)->isVisible()) { - pProtocolDialog->show(); - pProtocolDialog->raise(); - } else + (*place)->show(); + (*place)->raise(); + return false; + } + else { - auto dialog = mk_dialog<IProtocolDialog>(current_protocol()); - if (!dialog) return; - pProtocolDialog = dialog; - if (libs.pProtocol != nullptr) - dialog->register_protocol(libs.pProtocol.get()); - dialog->show(); - dialog->raise(); + *place = std::make_shared<t>(params...); + (*place)->setWindowFlags(Qt::Dialog); + (*place)->show(); + (*place)->raise(); + return true; } } void MainWindow::showKeyboardShortcuts() { - if (shortcuts_widget && shortcuts_widget->isVisible()) - { - shortcuts_widget->show(); - shortcuts_widget->raise(); - } - else - { - shortcuts_widget = std::make_shared<OptionsDialog>(static_cast<State&>(*this)); - shortcuts_widget->setWindowFlags(Qt::Dialog); + if (mk_window<OptionsDialog, State&>(&shortcuts_widget, *this)) connect(shortcuts_widget.get(), SIGNAL(reload()), this, SLOT(bindKeyboardShortcuts())); - shortcuts_widget->show(); - shortcuts_widget->raise(); - } } void MainWindow::showCurveConfiguration() { - if (mapping_widget && mapping_widget->isVisible()) - { - mapping_widget->show(); - mapping_widget->raise(); - } - else - { - mapping_widget = std::make_shared<MapWidget>(pose, s); - mapping_widget->setWindowFlags(Qt::Dialog); - mapping_widget->show(); - } + mk_window<MapWidget, Mappings&, main_settings&>(&mapping_widget, pose, s); } void MainWindow::exit() { |