From 0e4dedcac5071cf29baf6130e0b54e3d3ae719bd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 7 Jul 2015 06:43:25 +0200 Subject: ui: simplify dialog creation --- facetracknoir/ui.cpp | 105 +++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 66 deletions(-) diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index 10445182..416a619c 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -340,100 +340,73 @@ void MainWindow::showHeadPose() } template -mem mk_dialog(mem lib) +bool mk_dialog(mem lib, mem* orig) { + if (*orig && (*orig)->isVisible()) + { + (*orig)->show(); + (*orig)->raise(); + return false; + } + if (lib && lib->Dialog) { auto dialog = mem(reinterpret_cast(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::showTrackerSettings() { - if (pTrackerDialog && pTrackerDialog->isVisible()) - { - pTrackerDialog->show(); - pTrackerDialog->raise(); - } - else - { - auto dialog = mk_dialog(current_tracker()); - if (!dialog) return; - pTrackerDialog = dialog; - if (libs.pTracker != nullptr) - dialog->register_tracker(libs.pTracker.get()); - dialog->show(); - dialog->raise(); - } + if (mk_dialog(current_tracker(), &pTrackerDialog) && libs.pTracker) + pTrackerDialog->register_tracker(libs.pTracker.get()); } void MainWindow::showProtocolSettings() { - if (pProtocolDialog && pProtocolDialog->isVisible()) - { - pProtocolDialog->show(); - pProtocolDialog->raise(); - } else - { - auto dialog = mk_dialog(current_protocol()); - if (!dialog) return; - pProtocolDialog = dialog; - if (libs.pProtocol != nullptr) - dialog->register_protocol(libs.pProtocol.get()); - dialog->show(); - dialog->raise(); - } + if (mk_dialog(current_tracker(), &pProtocolDialog) && libs.pProtocol) + pProtocolDialog->register_protocol(libs.pProtocol.get()); } void MainWindow::showFilterSettings() { - if (pFilterDialog && pFilterDialog->isVisible()) - { - pFilterDialog->show(); - pFilterDialog->raise(); - } else - { - auto dialog = mk_dialog(current_filter()); - if (!dialog) return; - pFilterDialog = dialog; - if (libs.pFilter != nullptr) - dialog->register_filter(libs.pFilter.get()); - dialog->show(); - dialog->raise(); - } + if (mk_dialog(current_tracker(), &pFilterDialog) && libs.pFilter) + pFilterDialog->register_filter(libs.pFilter.get()); } -void MainWindow::showKeyboardShortcuts() { - if (shortcuts_widget && shortcuts_widget->isVisible()) +template +bool mk_window(mem* place, Args... params) +{ + if (*place && (*place)->isVisible()) { - shortcuts_widget->show(); - shortcuts_widget->raise(); + (*place)->show(); + (*place)->raise(); + return false; } else { - shortcuts_widget = std::make_shared(); - shortcuts_widget->setWindowFlags(Qt::Dialog); - connect(shortcuts_widget.get(), SIGNAL(reload()), this, SLOT(bindKeyboardShortcuts())); - shortcuts_widget->show(); - shortcuts_widget->raise(); + *place = std::make_shared(params...); + (*place)->setWindowFlags(Qt::Dialog); + (*place)->show(); + (*place)->raise(); + return true; } } +void MainWindow::showKeyboardShortcuts() { + if (mk_window(&shortcuts_widget)) + connect(shortcuts_widget.get(), SIGNAL(reload()), this, SLOT(bindKeyboardShortcuts())); +} + void MainWindow::showCurveConfiguration() { - if (mapping_widget && mapping_widget->isVisible()) - { - mapping_widget->show(); - mapping_widget->raise(); - } - else - { - mapping_widget = std::make_shared(pose, s); - mapping_widget->setWindowFlags(Qt::Dialog); - mapping_widget->show(); - } + mk_window(&mapping_widget, pose, s); } void MainWindow::exit() { -- cgit v1.2.3