diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2014-01-03 11:22:06 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2014-01-03 11:22:06 +0100 |
commit | a3df0c8a8d19655040c7d21812414d7a335def61 (patch) | |
tree | 6739401d8e59800731b2faf26e49b8df63664573 /facetracknoir | |
parent | 7307adbc3b8ec2213bc90a91deb1beb9198e7ff2 (diff) | |
parent | 519434cd1abb8991635487c6d84bc0d85367fc42 (diff) |
Merge branch 'feature/settings-template'
Conflicts:
README.md
Diffstat (limited to 'facetracknoir')
-rw-r--r-- | facetracknoir/curve-config.cpp | 161 | ||||
-rw-r--r-- | facetracknoir/facetracknoir.cpp | 390 | ||||
-rw-r--r-- | facetracknoir/facetracknoir.h | 38 | ||||
-rw-r--r-- | facetracknoir/ftnoir_curves.ui | 4 | ||||
-rw-r--r-- | facetracknoir/ftnoir_keyboardshortcuts.ui | 53 | ||||
-rw-r--r-- | facetracknoir/images/settingsopen16.png | bin | 686 -> 0 bytes | |||
-rw-r--r-- | facetracknoir/main-facetracknoir.qrc | 1 | ||||
-rw-r--r-- | facetracknoir/main-settings.hpp | 56 | ||||
-rw-r--r-- | facetracknoir/main.cpp | 7 | ||||
-rw-r--r-- | facetracknoir/options.h | 317 | ||||
-rw-r--r-- | facetracknoir/shortcuts.cpp | 148 | ||||
-rw-r--r-- | facetracknoir/shortcuts.h | 9 | ||||
-rw-r--r-- | facetracknoir/tracker.cpp | 25 | ||||
-rw-r--r-- | facetracknoir/tracker.h | 51 |
14 files changed, 591 insertions, 669 deletions
diff --git a/facetracknoir/curve-config.cpp b/facetracknoir/curve-config.cpp index 2e731892..4b07a165 100644 --- a/facetracknoir/curve-config.cpp +++ b/facetracknoir/curve-config.cpp @@ -14,7 +14,23 @@ CurveConfigurationDialog::CurveConfigurationDialog(FaceTrackNoIR *ftnoir, QWidge // Connect Qt signals to member-functions connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(curveChanged(int))); + + tie_setting(mainApp->s.a_x.altp, ui.tx_altp); + tie_setting(mainApp->s.a_y.altp, ui.ty_altp); + tie_setting(mainApp->s.a_z.altp, ui.tz_altp); + tie_setting(mainApp->s.a_yaw.altp, ui.rx_altp); + tie_setting(mainApp->s.a_pitch.altp, ui.ry_altp); + tie_setting(mainApp->s.a_roll.altp, ui.rz_altp); + + tie_setting(mainApp->s.tcomp_p, ui.tcomp_enable); + tie_setting(mainApp->s.tcomp_tz, ui.tcomp_rz); + + tie_setting(mainApp->s.a_x.zero, ui.pos_tx); + tie_setting(mainApp->s.a_y.zero, ui.pos_ty); + tie_setting(mainApp->s.a_z.zero, ui.pos_tz); + tie_setting(mainApp->s.a_yaw.zero, ui.pos_rx); + tie_setting(mainApp->s.a_pitch.zero, ui.pos_ry); + tie_setting(mainApp->s.a_roll.zero, ui.pos_rz); // Load the settings from the current .INI-file loadSettings(); @@ -47,7 +63,7 @@ void CurveConfigurationDialog::doCancel() { // // Ask if changed Settings should be saved // - if (settingsDirty) { + if (settingsDirty || mainApp->s.b->modifiedp()) { int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); qDebug() << "doCancel says: answer =" << ret; @@ -58,6 +74,7 @@ void CurveConfigurationDialog::doCancel() { this->close(); break; case QMessageBox::Discard: + mainApp->s.b->revert(); this->close(); break; case QMessageBox::Cancel: @@ -77,67 +94,6 @@ void CurveConfigurationDialog::doCancel() { // Load the current Settings from the currently 'active' INI-file. // void CurveConfigurationDialog::loadSettings() { - qDebug() << "CurveConfigurationDialog::loadSettings says: Starting "; - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - qDebug() << "CurveConfigurationDialog::loadSettings says: iniFile = " << currentFile; - - static const char* names[] = { - "tx_alt", - "ty_alt", - "tz_alt", - "rx_alt", - "ry_alt", - "rz_alt" - }; - - iniFile.beginGroup("Tracking"); - - ui.tcomp_rz->setChecked(iniFile.value("tcomp-rz", false).toBool()); - ui.checkBox->setChecked(iniFile.value("compensate", true).toBool()); - - for (int i = 0; i < 6; i++) - mainApp->axis(i).altp = iniFile.value(names[i], false).toBool(); - - QCheckBox* widgets[] = { - ui.tx_altp, - ui.ty_altp, - ui.tz_altp, - ui.rx_altp, - ui.ry_altp, - ui.rz_altp - }; - - for (int i = 0; i < 6; i++) - widgets[i]->setChecked(mainApp->axis(i).altp); - - QDoubleSpinBox* widgets2[] = { - ui.pos_tx, - ui.pos_ty, - ui.pos_tz, - ui.pos_tx, - ui.pos_ry, - ui.pos_rz - }; - - const char* names2[] = { - "zero_tx", - "zero_ty", - "zero_tz", - "zero_rx", - "zero_ry", - "zero_rz" - }; - - - for (int i = 0; i < 6; i++) - widgets2[i]->setValue(iniFile.value(names2[i], 0).toDouble()); - - iniFile.endGroup(); - QFunctionConfigurator* configs[6] = { ui.txconfig, ui.tyconfig, @@ -156,23 +112,10 @@ void CurveConfigurationDialog::loadSettings() { ui.rzconfig_alt }; - QCheckBox* checkboxes[6] = { - ui.rx_altp, - ui.ry_altp, - ui.rz_altp, - ui.tx_altp, - ui.ty_altp, - ui.tz_altp - }; - - QDoubleSpinBox* widgets3[] = { - ui.pos_tx, - ui.pos_ty, - ui.pos_tz, - ui.pos_tx, - ui.pos_ry, - ui.pos_rz - }; + QSettings settings("opentrack"); + QString currentFile = settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ) + .toString(); for (int i = 0; i < 6; i++) { @@ -182,8 +125,6 @@ void CurveConfigurationDialog::loadSettings() { alt_configs[i]->loadSettings(currentFile); connect(configs[i], SIGNAL(CurveChanged(bool)), this, SLOT(curveChanged(bool)), Qt::UniqueConnection); connect(alt_configs[i], SIGNAL(CurveChanged(bool)), this, SLOT(curveChanged(bool)), Qt::UniqueConnection); - connect(checkboxes[i], SIGNAL(stateChanged(int)), this, SLOT(curveChanged(int)), Qt::UniqueConnection); - mainApp->axis(i).zero = widgets3[i]->value(); } settingsDirty = false; @@ -196,9 +137,11 @@ void CurveConfigurationDialog::save() { qDebug() << "save() says: started"; - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings settings("opentrack"); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ) + .toString(); ui.rxconfig->saveSettings(currentFile); ui.ryconfig->saveSettings(currentFile); @@ -214,53 +157,5 @@ void CurveConfigurationDialog::save() { ui.ryconfig_alt->saveSettings(currentFile); ui.rzconfig_alt->saveSettings(currentFile); - bool tcomp_rz = false, compensate = true; - - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup("Tracking"); - - iniFile.setValue("tcomp-rz", tcomp_rz = ui.tcomp_rz->checkState() != Qt::Unchecked); - iniFile.setValue("compensate", compensate = (bool) !!ui.checkBox->isChecked()); - - if (mainApp->tracker) - { - mainApp->tracker->compensate = compensate; - mainApp->tracker->tcomp_rz = tcomp_rz; - } - - iniFile.setValue("rx_alt", ui.rx_altp->checkState() != Qt::Unchecked); - iniFile.setValue("ry_alt", ui.ry_altp->checkState() != Qt::Unchecked); - iniFile.setValue("rz_alt", ui.rz_altp->checkState() != Qt::Unchecked); - iniFile.setValue("tx_alt", ui.tx_altp->checkState() != Qt::Unchecked); - iniFile.setValue("ty_alt", ui.ty_altp->checkState() != Qt::Unchecked); - iniFile.setValue("tz_alt", ui.tz_altp->checkState() != Qt::Unchecked); - - QDoubleSpinBox* widgets2[] = { - ui.pos_tx, - ui.pos_ty, - ui.pos_tz, - ui.pos_tx, - ui.pos_ry, - ui.pos_rz - }; - - const char* names2[] = { - "zero_tx", - "zero_ty", - "zero_tz", - "zero_rx", - "zero_ry", - "zero_rz" - }; - - for (int i = 0; i < 6; i++) - { - iniFile.setValue(names2[i], widgets2[i]->value()); - mainApp->axis(i).zero = widgets2[i]->value(); - } - - iniFile.endGroup(); - settingsDirty = false; } diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index 75ac737d..85207b53 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -95,6 +95,9 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : keyCenter(this), keyToggle(this), #endif + b(bundle("opentrack-ui")), + s(b), + pose(std::vector<axis_opts*>{&s.a_x, &s.a_y, &s.a_z, &s.a_yaw, &s.a_pitch, &s.a_roll}), timUpdateHeadPose(this), pTrackerDialog(NULL), pSecondTrackerDialog(NULL), @@ -111,6 +114,16 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : tracker = 0; + CurveConfigurationDialog* ccd; + + if (!_curve_config) + { + ccd = new CurveConfigurationDialog( this, this ); + _curve_config = ccd; + } else { + ccd = dynamic_cast<CurveConfigurationDialog*>(_curve_config); + } + QDir::setCurrent(QCoreApplication::applicationDirPath()); connect(ui.btnLoad, SIGNAL(clicked()), this, SLOT(open())); @@ -124,18 +137,6 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : connect(ui.btnShowServerControls, SIGNAL(clicked()), this, SLOT(showServerControls())); connect(ui.btnShowFilterControls, SIGNAL(clicked()), this, SLOT(showFilterControls())); - connect(ui.chkInvertYaw, SIGNAL(stateChanged(int)), this, SLOT(setInvertYaw(int))); - connect(ui.chkInvertRoll, SIGNAL(stateChanged(int)), this, SLOT(setInvertRoll(int))); - connect(ui.chkInvertPitch, SIGNAL(stateChanged(int)), this, SLOT(setInvertPitch(int))); - connect(ui.chkInvertX, SIGNAL(stateChanged(int)), this, SLOT(setInvertX(int))); - connect(ui.chkInvertY, SIGNAL(stateChanged(int)), this, SLOT(setInvertY(int))); - connect(ui.chkInvertZ, SIGNAL(stateChanged(int)), this, SLOT(setInvertZ(int))); - - connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(startTracker())); - connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stopTracker())); - - GetCameraNameDX(); - ui.cbxSecondTrackerSource->addItem(QIcon(), "None"); dlopen_filters.push_back((DynamicLibrary*) NULL); ui.iconcomboFilter->addItem(QIcon(), "None"); @@ -144,11 +145,25 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : fill_combobox("opentrack-tracker-*.", dlopen_trackers, ui.iconcomboTrackerSource, ui.cbxSecondTrackerSource); fill_combobox("opentrack-filter-*.", dlopen_filters, ui.iconcomboFilter, NULL); + tie_setting(s.a_yaw.invert, ui.chkInvertYaw); + tie_setting(s.a_pitch.invert, ui.chkInvertPitch); + tie_setting(s.a_roll.invert, ui.chkInvertRoll); + tie_setting(s.a_x.invert, ui.chkInvertX); + tie_setting(s.a_y.invert, ui.chkInvertY); + tie_setting(s.a_z.invert, ui.chkInvertZ); + tie_setting(s.tracker_dll, ui.iconcomboTrackerSource); + tie_setting(s.tracker2_dll, ui.cbxSecondTrackerSource); + tie_setting(s.protocol_dll, ui.iconcomboProtocol); + tie_setting(s.filter_dll, ui.iconcomboFilter); + + connect(ui.btnStartTracker, SIGNAL(clicked()), this, SLOT(startTracker())); + connect(ui.btnStopTracker, SIGNAL(clicked()), this, SLOT(stopTracker())); + + GetCameraNameDX(); + connect(ui.iconcomboProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(profileSelected(int))); connect(&timUpdateHeadPose, SIGNAL(timeout()), this, SLOT(showHeadPose())); - loadSettings(); - #ifndef _WIN32 connect(&keyCenter, SIGNAL(activated()), this, SLOT(shortcutRecentered())); connect(&keyToggle, SIGNAL(activated()), this, SLOT(shortcutToggled())); @@ -156,6 +171,8 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent) : connect(&kbd_quit, SIGNAL(activated()), this, SLOT(exit())); kbd_quit.setEnabled(true); + + fill_profile_cbx(); } FaceTrackNoIR::~FaceTrackNoIR() { @@ -245,50 +262,20 @@ void FaceTrackNoIR::open() { QSettings settings("opentrack"); settings.setValue ("SettingsFile", QFileInfo(fileName).absoluteFilePath()); } + fill_profile_cbx(); loadSettings(); } } void FaceTrackNoIR::save() { - QSettings settings("opentrack"); - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); - - iniFile.beginGroup ( "Tracking" ); - - iniFile.setValue ( "invertYaw", ui.chkInvertYaw->isChecked() ); - iniFile.setValue ( "invertPitch", ui.chkInvertPitch->isChecked() ); - iniFile.setValue ( "invertRoll", ui.chkInvertRoll->isChecked() ); - iniFile.setValue ( "invertX", ui.chkInvertX->isChecked() ); - iniFile.setValue ( "invertY", ui.chkInvertY->isChecked() ); - iniFile.setValue ( "invertZ", ui.chkInvertZ->isChecked() ); - iniFile.endGroup (); - - iniFile.beginGroup ( "GameProtocol" ); - { - DynamicLibrary* proto = dlopen_protocols.value( ui.iconcomboProtocol->currentIndex(), (DynamicLibrary*) NULL); - iniFile.setValue ( "DLL", proto == NULL ? "" : proto->filename); - } - iniFile.endGroup (); + b->save(); - iniFile.beginGroup ( "TrackerSource" ); - { - DynamicLibrary* tracker = dlopen_trackers.value( ui.iconcomboTrackerSource->currentIndex(), (DynamicLibrary*) NULL); - iniFile.setValue ( "DLL", tracker == NULL ? "" : tracker->filename); - } - { - DynamicLibrary* tracker = dlopen_trackers.value( ui.cbxSecondTrackerSource->currentIndex() - 1, (DynamicLibrary*) NULL); - iniFile.setValue ( "2ndDLL", tracker == NULL ? "" : tracker->filename); - } - iniFile.endGroup (); + QSettings settings("opentrack"); - iniFile.beginGroup ( "Filter" ); - { - DynamicLibrary* filter = dlopen_filters.value( ui.iconcomboFilter->currentIndex(), (DynamicLibrary*) NULL); - iniFile.setValue ( "DLL", filter == NULL ? "" : filter->filename); - } - iniFile.endGroup (); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini") + .toString(); #if defined(__unix) || defined(__linux) QByteArray bytes = QFile::encodeName(currentFile); @@ -308,8 +295,7 @@ void FaceTrackNoIR::saveAs() QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"), oldFile, -// QCoreApplication::applicationDirPath() + "/settings", - tr("Settings file (*.ini);;All Files (*)")); + tr("Settings file (*.ini);;All Files (*)")); if (!fileName.isEmpty()) { QFileInfo newFileInfo ( fileName ); @@ -325,117 +311,40 @@ void FaceTrackNoIR::saveAs() } settings.setValue ("SettingsFile", fileName); - save(); + save(); + } - loadSettings(); - } + fill_profile_cbx(); } void FaceTrackNoIR::loadSettings() { - if (looping) - return; - looping = true; - qDebug() << "loadSettings says: Starting "; - QSettings settings("opentrack"); - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - qDebug() << "Config file now" << currentFile; - QSettings iniFile( currentFile, QSettings::IniFormat ); - - QFileInfo pathInfo ( currentFile ); - setWindowTitle(QString( OPENTRACK_VERSION " :: ") + pathInfo.fileName()); - - QDir settingsDir( pathInfo.dir() ); - QStringList filters; - filters << "*.ini"; - iniFileList.clear(); - iniFileList = settingsDir.entryList( filters, QDir::Files, QDir::Name ); - - ui.iconcomboProfile->clear(); - for ( int i = 0; i < iniFileList.size(); i++) { - ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); - if (iniFileList.at(i) == pathInfo.fileName()) { - ui.iconcomboProfile->setItemIcon(i, QIcon(":/images/settingsopen16.png")); - ui.iconcomboProfile->setCurrentIndex( i ); - } - } - - qDebug() << "loadSettings says: iniFile = " << currentFile; - - iniFile.beginGroup ( "Tracking" ); - ui.chkInvertYaw->setChecked (iniFile.value ( "invertYaw", 0 ).toBool()); - ui.chkInvertPitch->setChecked (iniFile.value ( "invertPitch", 0 ).toBool()); - ui.chkInvertRoll->setChecked (iniFile.value ( "invertRoll", 0 ).toBool()); - ui.chkInvertX->setChecked (iniFile.value ( "invertX", 0 ).toBool()); - ui.chkInvertY->setChecked (iniFile.value ( "invertY", 0 ).toBool()); - ui.chkInvertZ->setChecked (iniFile.value ( "invertZ", 0 ).toBool()); - iniFile.endGroup (); - - iniFile.beginGroup ( "GameProtocol" ); - QString selectedProtocolName = iniFile.value ( "DLL", "" ).toString(); - iniFile.endGroup (); - - for ( int i = 0; i < dlopen_protocols.size(); i++) { - if (dlopen_protocols.at(i)->filename.compare( selectedProtocolName, Qt::CaseInsensitive ) == 0) { - ui.iconcomboProtocol->setCurrentIndex( i ); - break; - } - } - - iniFile.beginGroup ( "TrackerSource" ); - QString selectedTrackerName = iniFile.value ( "DLL", "" ).toString(); - qDebug() << "loadSettings says: selectedTrackerName = " << selectedTrackerName; - QString secondTrackerName = iniFile.value ( "2ndDLL", "None" ).toString(); - qDebug() << "loadSettings says: secondTrackerName = " << secondTrackerName; - iniFile.endGroup (); - - for ( int i = 0; i < dlopen_trackers.size(); i++) { - DynamicLibrary* foo = dlopen_trackers.at(i); - if (foo && foo->filename.compare( selectedTrackerName, Qt::CaseInsensitive ) == 0) { - ui.iconcomboTrackerSource->setCurrentIndex( i ); - } - if (foo && foo->filename.compare( secondTrackerName, Qt::CaseInsensitive ) == 0) { - ui.cbxSecondTrackerSource->setCurrentIndex( i + 1 ); - } - } - - iniFile.beginGroup ( "Filter" ); - QString selectedFilterName = iniFile.value ( "DLL", "" ).toString(); - qDebug() << "createIconGroupBox says: selectedFilterName = " << selectedFilterName; - iniFile.endGroup (); - - for ( int i = 0; i < dlopen_filters.size(); i++) { - DynamicLibrary* foo = dlopen_filters.at(i); - if (foo && foo->filename.compare( selectedFilterName, Qt::CaseInsensitive ) == 0) { - ui.iconcomboFilter->setCurrentIndex( i ); - break; - } - } - - CurveConfigurationDialog* ccd; - - if (!_curve_config) - { - ccd = new CurveConfigurationDialog( this, this ); - _curve_config = ccd; - } else { - ccd = dynamic_cast<CurveConfigurationDialog*>(_curve_config); - } - - ccd->loadSettings(); + b->reload(); + (dynamic_cast<CurveConfigurationDialog*>(_curve_config))->loadSettings(); +} - looping = false; +void FaceTrackNoIR::updateButtonState(bool running) +{ + bool e = !running; + ui.iconcomboProfile->setEnabled ( e ); + ui.btnLoad->setEnabled ( e ); + ui.btnSaveAs->setEnabled ( e ); + ui.btnStartTracker->setEnabled ( e ); + ui.btnStopTracker->setEnabled ( running ); + ui.iconcomboProtocol->setEnabled ( e ); + ui.btnShowServerControls->setEnabled ( e ); + ui.iconcomboFilter->setEnabled ( e ); + ui.iconcomboTrackerSource->setEnabled(e); + ui.cbxSecondTrackerSource->setEnabled(e); + + ui.btnStartTracker->setEnabled(e); + ui.btnStopTracker->setEnabled(running); } -void FaceTrackNoIR::startTracker( ) { +void FaceTrackNoIR::startTracker( ) { + b->save(); + loadSettings(); bindKeyboardShortcuts(); - ui.iconcomboProfile->setEnabled ( false ); - ui.btnLoad->setEnabled ( false ); - ui.btnSave->setEnabled ( false ); - ui.btnSaveAs->setEnabled ( false ); - ui.btnShowFilterControls->setEnabled ( true ); - if (Libraries) delete Libraries; Libraries = new SelectedLibraries(this); @@ -457,54 +366,19 @@ void FaceTrackNoIR::startTracker( ) { delete tracker; } - QSettings settings("opentrack"); - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); - - for (int i = 0; i < 6; i++) { - axis(i).curve.loadSettings(iniFile); - axis(i).curveAlt.loadSettings(iniFile); - } + QSettings settings("opentrack"); + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings iniFile( currentFile, QSettings::IniFormat ); - static const char* names[] = { - "tx_alt", - "ty_alt", - "tz_alt", - "rx_alt", - "ry_alt", - "rz_alt", - }; - - static const char* invert_names[] = { - "invertX", - "invertY", - "invertZ", - "invertYaw", - "invertPitch", - "invertRoll" - }; - - iniFile.beginGroup("Tracking"); - - for (int i = 0; i < 6; i++) { - axis(i).altp = iniFile.value(names[i], false).toBool(); - axis(i).invert = iniFile.value(invert_names[i], false).toBool() ? 1 : -1; + for (int i = 0; i < 6; i++) + { + axis(i).curve.loadSettings(iniFile); + axis(i).curveAlt.loadSettings(iniFile); + } } - tracker = new Tracker ( this ); - - tracker->compensate = iniFile.value("compensate", true).toBool(); - tracker->tcomp_rz = iniFile.value("tcomp-rz", false).toBool(); - - iniFile.endGroup(); - - tracker->setInvertAxis(Yaw, ui.chkInvertYaw->isChecked() ); - tracker->setInvertAxis(Pitch, ui.chkInvertPitch->isChecked() ); - tracker->setInvertAxis(Roll, ui.chkInvertRoll->isChecked() ); - tracker->setInvertAxis(TX, ui.chkInvertX->isChecked() ); - tracker->setInvertAxis(TY, ui.chkInvertY->isChecked() ); - tracker->setInvertAxis(TZ, ui.chkInvertZ->isChecked() ); + tracker = new Tracker ( this, s ); if (pTrackerDialog && Libraries->pTracker) { pTrackerDialog->registerTracker( Libraries->pTracker ); @@ -517,21 +391,12 @@ void FaceTrackNoIR::startTracker( ) { ui.video_frame->show(); - ui.btnStartTracker->setEnabled ( false ); - ui.btnStopTracker->setEnabled ( true ); - - ui.iconcomboTrackerSource->setEnabled ( false ); - ui.cbxSecondTrackerSource->setEnabled ( false ); - ui.iconcomboProtocol->setEnabled ( false ); - ui.btnShowServerControls->setEnabled ( false ); - ui.iconcomboFilter->setEnabled ( false ); - - GetCameraNameDX(); - timUpdateHeadPose.start(50); + + updateButtonState(true); } -void FaceTrackNoIR::stopTracker( ) { +void FaceTrackNoIR::stopTracker( ) { ui.game_name->setText("Not connected"); #if defined(_WIN32) if (keybindingWorker) @@ -555,39 +420,16 @@ void FaceTrackNoIR::stopTracker( ) { pFilterDialog->unregisterFilter(); if ( tracker ) { - qDebug() << "Done with tracking"; tracker->should_quit = true; tracker->wait(); - - qDebug() << "stopTracker says: Deleting tracker!"; delete tracker; - qDebug() << "stopTracker says: Tracker deleted!"; tracker = 0; if (Libraries) { delete Libraries; Libraries = NULL; } } - ui.btnStartTracker->setEnabled ( true ); - ui.btnStopTracker->setEnabled ( false ); - ui.iconcomboProtocol->setEnabled ( true ); - ui.iconcomboTrackerSource->setEnabled ( true ); - ui.cbxSecondTrackerSource->setEnabled ( true ); - ui.iconcomboFilter->setEnabled ( true ); - - ui.btnShowServerControls->setEnabled ( true ); - ui.video_frame->hide(); - - ui.iconcomboProfile->setEnabled ( true ); - ui.btnLoad->setEnabled ( true ); - ui.btnSave->setEnabled ( true ); - ui.btnSaveAs->setEnabled ( true ); - ui.btnShowFilterControls->setEnabled ( true ); -} - -void FaceTrackNoIR::setInvertAxis(Axis axis, int invert ) { - if (tracker) - tracker->setInvertAxis (axis, (invert != 0)?true:false ); + updateButtonState(false); } void FaceTrackNoIR::showHeadPose() { @@ -625,7 +467,6 @@ void FaceTrackNoIR::showHeadPose() { } } -/** toggles Engine Controls Dialog **/ void FaceTrackNoIR::showTrackerSettings() { if (pTrackerDialog) { delete pTrackerDialog; @@ -641,7 +482,7 @@ void FaceTrackNoIR::showTrackerSettings() { foo->setFixedSize(foo->size()); if (Libraries && Libraries->pTracker) pTrackerDialog->registerTracker(Libraries->pTracker); - pTrackerDialog->Initialize(this); + dynamic_cast<QWidget*>(pTrackerDialog)->show(); } } } @@ -661,7 +502,7 @@ void FaceTrackNoIR::showSecondTrackerSettings() { foo->setFixedSize(foo->size()); if (Libraries && Libraries->pSecondTracker) pSecondTrackerDialog->registerTracker(Libraries->pSecondTracker); - pSecondTrackerDialog->Initialize(this); + dynamic_cast<QWidget*>(pSecondTrackerDialog)->show(); } } } @@ -679,7 +520,7 @@ void FaceTrackNoIR::showServerControls() { if (pProtocolDialog) { auto foo = dynamic_cast<QWidget*>(pProtocolDialog); foo->setFixedSize(foo->size()); - pProtocolDialog->Initialize(this); + dynamic_cast<QWidget*>(pProtocolDialog)->show(); } } } @@ -697,9 +538,9 @@ void FaceTrackNoIR::showFilterControls() { if (pFilterDialog) { auto foo = dynamic_cast<QWidget*>(pFilterDialog); foo->setFixedSize(foo->size()); - pFilterDialog->Initialize(this); if (Libraries && Libraries->pFilter) pFilterDialog->registerFilter(Libraries->pFilter); + dynamic_cast<QWidget*>(pFilterDialog)->show(); } } } @@ -730,34 +571,55 @@ void FaceTrackNoIR::exit() { QCoreApplication::exit(0); } -void FaceTrackNoIR::profileSelected(int index) +void FaceTrackNoIR::fill_profile_cbx() { if (looping) return; + looping = true; + QSettings settings("opentrack"); + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + qDebug() << "Config file now" << currentFile; + QFileInfo pathInfo ( currentFile ); + setWindowTitle(QString( OPENTRACK_VERSION " :: ") + pathInfo.fileName()); + QDir settingsDir( pathInfo.dir() ); + QStringList filters; + filters << "*.ini"; + auto iniFileList = settingsDir.entryList( filters, QDir::Files, QDir::Name ); + ui.iconcomboProfile->clear(); + for ( int i = 0; i < iniFileList.size(); i++) { + ui.iconcomboProfile->addItem(QIcon(":/images/settings16.png"), iniFileList.at(i)); + if (iniFileList.at(i) == pathInfo.fileName()) { + ui.iconcomboProfile->setCurrentIndex( i ); + } + } + looping = false; +} + +void FaceTrackNoIR::profileSelected(int index) +{ QSettings settings("opentrack"); QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); QFileInfo pathInfo ( currentFile ); - - settings.setValue ("SettingsFile", pathInfo.absolutePath() + "/" + iniFileList.value(index, "")); + settings.setValue ("SettingsFile", pathInfo.absolutePath() + "/" + ui.iconcomboProfile->itemText(index)); loadSettings(); } #if !defined(_WIN32) -void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, const QString label, QSettings& iniFile) +void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, key_opts& k) { - const int idx = iniFile.value("Key_index_" + label, 0).toInt(); key.setShortcut(QKeySequence::fromString("")); key.setDisabled(); - QString seq(global_key_sequences.value(idx, "")); + const int idx = k.key_index; if (idx > 0) { + QString seq(global_key_sequences.value(idx, "")); if (!seq.isEmpty()) { - if (iniFile.value(QString("Shift_%1").arg(label), false).toBool()) + if (k.shift) seq = "Shift+" + seq; - if (iniFile.value(QString("Alt_%1").arg(label), false).toBool()) + if (k.alt) seq = "Alt+" + seq; - if (iniFile.value(QString("Ctrl_%1").arg(label), false).toBool()) + if (k.ctrl) seq = "Ctrl+" + seq; key.setShortcut(QKeySequence::fromString(seq, QKeySequence::PortableText)); key.setEnabled(); @@ -767,39 +629,31 @@ void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, const QString } } #else -static void bind_keyboard_shortcut(Key& key, const QString label, QSettings& iniFile) +static void bind_keyboard_shortcut(Key& key, key_opts& k) { - const int idx = iniFile.value("Key_index_" + label, 0).toInt(); + int idx = k.key_index; if (idx > 0) { key.keycode = 0; key.shift = key.alt = key.ctrl = 0; if (idx < global_windows_key_sequences.size()) key.keycode = global_windows_key_sequences[idx]; - key.shift = iniFile.value(QString("Shift_%1").arg(label), false).toBool(); - key.alt = iniFile.value(QString("Alt_%1").arg(label), false).toBool(); - key.ctrl = iniFile.value(QString("Ctrl_%1").arg(label), false).toBool(); + key.shift = k.shift; + key.alt = k.alt; + key.ctrl = k.ctrl; } } #endif void FaceTrackNoIR::bindKeyboardShortcuts() { - QSettings settings("opentrack"); - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); - iniFile.beginGroup ( "KB_Shortcuts" ); - #if !defined(_WIN32) - bind_keyboard_shortcut(keyCenter, "Center", iniFile); - bind_keyboard_shortcut(keyToggle, "Toggle", iniFile); + bind_keyboard_shortcut(keyCenter, s.center_key); + bind_keyboard_shortcut(keyToggle, s.toggle_key); #else - bind_keyboard_shortcut(keyCenter, "Center", iniFile); - bind_keyboard_shortcut(keyToggle, "Toggle", iniFile); + bind_keyboard_shortcut(keyCenter, s.center_key); + bind_keyboard_shortcut(keyToggle, s.toggle_key); #endif - iniFile.endGroup (); - if (tracker) /* running already */ { #if defined(_WIN32) @@ -822,9 +676,7 @@ void FaceTrackNoIR::shortcutRecentered() qDebug() << "Center"; if (tracker) - { tracker->do_center = true; - } } void FaceTrackNoIR::shortcutToggled() @@ -832,7 +684,5 @@ void FaceTrackNoIR::shortcutToggled() QApplication::beep(); qDebug() << "Toggle"; if (tracker) - { tracker->enabled = !tracker->enabled; - } } diff --git a/facetracknoir/facetracknoir.h b/facetracknoir/facetracknoir.h index 72ccebd8..53b83754 100644 --- a/facetracknoir/facetracknoir.h +++ b/facetracknoir/facetracknoir.h @@ -39,6 +39,7 @@ #include <QString> #include <QByteArray> #include <QShortcut> +#include <vector> #if !defined(_WIN32) # include "qxt-mini/QxtGlobalShortcut" #else @@ -50,6 +51,11 @@ #include "ui_facetracknoir.h" +#include "facetracknoir/options.h" +using namespace options; + +#include "facetracknoir/main-settings.hpp" + #include "global-settings.h" #include "tracker.h" #include "facetracknoir/shortcuts.h" @@ -100,6 +106,8 @@ public: QxtGlobalShortcut keyCenter; QxtGlobalShortcut keyToggle; #endif + pbundle b; + main_settings s; public slots: void shortcutRecentered(); void shortcutToggled(); @@ -108,7 +116,6 @@ private: HeadPoseData pose; Ui::OpentrackUI ui; QTimer timUpdateHeadPose; // Timer to display headpose - QStringList iniFileList; // List of INI-files, that are present in the Settings folder ITrackerDialog* pTrackerDialog; // Pointer to Tracker dialog instance (in DLL) ITrackerDialog* pSecondTrackerDialog; // Pointer to the second Tracker dialog instance (in DLL) @@ -122,6 +129,7 @@ private: void GetCameraNameDX(); void loadSettings(); + void updateButtonState(bool); QList<DynamicLibrary*> dlopen_filters; QList<DynamicLibrary*> dlopen_trackers; @@ -129,18 +137,18 @@ private: QShortcut kbd_quit; #ifndef _WIN32 - void bind_keyboard_shortcut(QxtGlobalShortcut& key, const QString label, QSettings& iniFile); + void bind_keyboard_shortcut(QxtGlobalShortcut&, key_opts& k); #endif - volatile bool looping; + bool looping; + + void fill_profile_cbx(); private slots: - //file menu void open(); void save(); void saveAs(); void exit(); - // void setIcon(int index); void profileSelected(int index); void showTrackerSettings(); @@ -151,30 +159,10 @@ private slots: void showKeyboardShortcuts(); void showCurveConfiguration(); - void setInvertAxis( Axis axis, int invert ); - void setInvertYaw(int invert) { - setInvertAxis(Yaw, invert); - } - void setInvertPitch(int invert) { - setInvertAxis(Pitch, invert); - } - void setInvertRoll(int invert) { - setInvertAxis(Roll, invert); - } - void setInvertX(int invert) { - setInvertAxis(TX, invert); - } - void setInvertY(int invert) { - setInvertAxis(TY, invert); - } - void setInvertZ(int invert) { - setInvertAxis(TZ, invert); - } void showHeadPose(); void startTracker(); void stopTracker(); - }; #endif // FaceTrackNoIR_H diff --git a/facetracknoir/ftnoir_curves.ui b/facetracknoir/ftnoir_curves.ui index 5355dd20..9b5c8d07 100644 --- a/facetracknoir/ftnoir_curves.ui +++ b/facetracknoir/ftnoir_curves.ui @@ -761,7 +761,7 @@ </property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="QCheckBox" name="checkBox">
+ <widget class="QCheckBox" name="tcomp_enable">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -816,7 +816,7 @@ <tabstop>tx_altp</tabstop>
<tabstop>ty_altp</tabstop>
<tabstop>tz_altp</tabstop>
- <tabstop>checkBox</tabstop>
+ <tabstop>tcomp_enable</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>pos_tx</tabstop>
<tabstop>buttonBox</tabstop>
diff --git a/facetracknoir/ftnoir_keyboardshortcuts.ui b/facetracknoir/ftnoir_keyboardshortcuts.ui index 565c0e77..1477d56d 100644 --- a/facetracknoir/ftnoir_keyboardshortcuts.ui +++ b/facetracknoir/ftnoir_keyboardshortcuts.ui @@ -6,8 +6,8 @@ <rect>
<x>0</x>
<y>0</y>
- <width>335</width>
- <height>120</height>
+ <width>360</width>
+ <height>124</height>
</rect>
</property>
<property name="sizePolicy">
@@ -191,53 +191,10 @@ </property>
</widget>
</item>
- <item row="3" column="0" colspan="2">
- <widget class="QPushButton" name="btnCancel">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>100</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>100</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Cancel</string>
- </property>
- </widget>
- </item>
<item row="3" column="3" colspan="2">
- <widget class="QPushButton" name="btnOK">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>100</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>100</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>OK</string>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
diff --git a/facetracknoir/images/settingsopen16.png b/facetracknoir/images/settingsopen16.png Binary files differdeleted file mode 100644 index 5bf65f0d..00000000 --- a/facetracknoir/images/settingsopen16.png +++ /dev/null diff --git a/facetracknoir/main-facetracknoir.qrc b/facetracknoir/main-facetracknoir.qrc index eb5ad991..6cb2e300 100644 --- a/facetracknoir/main-facetracknoir.qrc +++ b/facetracknoir/main-facetracknoir.qrc @@ -2,7 +2,6 @@ <qresource prefix="/"> <file>uielements/tools.png</file> <file>images/settings16.png</file> - <file>images/settingsopen16.png</file> <file>uielements/curves.png</file> <file>images/facetracknoir.png</file> </qresource> diff --git a/facetracknoir/main-settings.hpp b/facetracknoir/main-settings.hpp new file mode 100644 index 00000000..c9b5ff66 --- /dev/null +++ b/facetracknoir/main-settings.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include <QString> +#include "facetracknoir/options.h" +using namespace options; + +struct key_opts { + value<int> key_index; + value<bool> ctrl, alt, shift; + key_opts(pbundle b, const QString& name) : + key_index(b, QString("key-index-%1").arg(name), 0), + ctrl(b, QString("key-ctrl-%1").arg(name), 0), + alt(b, QString("key-alt-%1").arg(name), 0), + shift(b, QString("key-shift-%1").arg(name), 0) + {} +}; + +struct axis_opts { + value<double> zero; + value<bool> invert, altp; + axis_opts(pbundle b, QString pfx) : + zero(b, n(pfx, "zero-pos"), 0), + invert(b, n(pfx, "invert-axis"), false), + altp(b, n(pfx, "alt-axis-sign"), false) + {} +private: + static inline QString n(QString pfx, QString name) { + return QString("%1-%2").arg(pfx, name); + } +}; + +struct main_settings { + pbundle b; + key_opts center_key; + key_opts toggle_key; + value<QString> tracker_dll, tracker2_dll, filter_dll, protocol_dll; + axis_opts a_x, a_y, a_z, a_yaw, a_pitch, a_roll; + value<bool> tcomp_p, tcomp_tz; + main_settings(pbundle b) : + b(b), + center_key(b, "center"), + toggle_key(b, "toggle"), + tracker_dll(b, "tracker-dll", ""), + tracker2_dll(b, "tracker2-dll", ""), + filter_dll(b, "filter-dll", ""), + protocol_dll(b, "protocol-dll", ""), + a_x(b, "x"), + a_y(b, "y"), + a_z(b, "z"), + a_yaw(b, "yaw"), + a_pitch(b, "pitch"), + a_roll(b, "roll"), + tcomp_p(b, "compensate-translation", true), + tcomp_tz(b, "compensate-translation-disable-z-axis", false) + {} +}; diff --git a/facetracknoir/main.cpp b/facetracknoir/main.cpp index 5ba3fcd5..3143a093 100644 --- a/facetracknoir/main.cpp +++ b/facetracknoir/main.cpp @@ -30,6 +30,7 @@ #include <QList> #include <QDir> #include <QStringList> +#include <memory> #if defined(_WIN32) && defined(_MSC_VER) # include <windows.h> @@ -61,11 +62,9 @@ int main(int argc, char** argv) #endif QApplication::setAttribute(Qt::AA_X11InitThreads, true); QApplication app(argc, argv); - FaceTrackNoIR w; - QDesktopWidget desktop; + auto w = std::make_shared<FaceTrackNoIR>(); - w.move(desktop.screenGeometry().width()/2-w.width()/2, 100); - w.show(); + w->show(); app.exec(); return 0; diff --git a/facetracknoir/options.h b/facetracknoir/options.h new file mode 100644 index 00000000..bc53a456 --- /dev/null +++ b/facetracknoir/options.h @@ -0,0 +1,317 @@ +/* Copyright (c) 2013 Stanislaw Halik + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#pragma once + +#include <QObject> +#include <QSettings> +#include <QMap> +#include <QString> +#include <QVariant> +#include <QMutex> +#include <QMutexLocker> +#include <memory> +#include <cassert> +#include <QWidget> +#include <QComboBox> +#include <QCheckBox> +#include <QDoubleSpinBox> +#include <QSpinBox> +#include <QSlider> +#include <QLineEdit> +#include <QLabel> +#include <QCoreApplication> + +#ifdef __GNUC__ +# define ov override +#else +# define ov +#endif + +#include <QDebug> + +namespace options { + template<typename T> + inline T qcruft_to_t (const QVariant& t); + + template<> + inline int qcruft_to_t<int>(const QVariant& t) + { + return t.toInt(); + } + + template<> + inline QString qcruft_to_t<QString>(const QVariant& t) + { + return t.toString(); + } + + template<> + inline bool qcruft_to_t<bool>(const QVariant& t) + { + return t.toBool(); + } + + template<> + inline double qcruft_to_t<double>(const QVariant& t) + { + return t.toDouble(); + } + + template<> + inline QVariant qcruft_to_t<QVariant>(const QVariant& t) + { + return t; + } + + // snapshot of qsettings group at given time + class group { + private: + QMap<QString, QVariant> map; + QString name; + public: + group(const QString& name) : name(name) + { + QSettings settings(group::org); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings iniFile(currentFile, QSettings::IniFormat); + iniFile.beginGroup(name); + for (auto& k : iniFile.childKeys()) + map[k] = iniFile.value(k); + iniFile.endGroup(); + } + static constexpr const char* org = "opentrack"; + void save() { + QSettings settings(group::org); + QString currentFile = + settings.value("SettingsFile", + QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); + QSettings s(currentFile, QSettings::IniFormat); + s.beginGroup(name); + for (auto& k : map.keys()) + s.setValue(k, map[k]); + s.endGroup(); + } + template<typename T> + T get(const QString& k) { + return qcruft_to_t<T>(map.value(k)); + } + + void put(const QString& s, const QVariant& d) + { + map[s] = d; + } + bool contains(const QString& s) + { + return map.contains(s); + } + }; + + class impl_bundle : public QObject { + Q_OBJECT + private: + QMutex mtx; + const QString group_name; + group saved; + group transient; + impl_bundle(const impl_bundle&) = delete; + impl_bundle& operator=(const impl_bundle&) = delete; + bool modified; + public: + impl_bundle(const QString& group_name) : + mtx(QMutex::Recursive), + group_name(group_name), + saved(group_name), + transient(saved), + modified(false) + { + } + void reload() { + QMutexLocker l(&mtx); + saved = group(group_name); + transient = saved; + emit reloaded(); + } + + std::shared_ptr<impl_bundle> make(const QString& name) { + return std::make_shared<impl_bundle>(name); + } + void store(const QString& name, const QVariant& datum) + { + QMutexLocker l(&mtx); + if (!transient.contains(name) || datum != transient.get<QVariant>(name)) + { + modified = true; + transient.put(name, datum); + emit bundleChanged(); + } + } + bool contains(const QString& name) + { + QMutexLocker l(&mtx); + return transient.contains(name); + } + template<typename T> + T get(const QString& name) { + QMutexLocker l(&mtx); + return transient.get<T>(name); + } + void save() + { + QMutexLocker l(&mtx); + modified = false; + saved = transient; + transient.save(); + } + void revert() + { + QMutexLocker l(&mtx); + modified = false; + transient = saved; + emit bundleChanged(); + } + + bool modifiedp() { + QMutexLocker l(&mtx); + return modified; + } + signals: + void bundleChanged(); + void reloaded(); + }; + + typedef std::shared_ptr<impl_bundle> pbundle; + + class base_value : public QObject { + Q_OBJECT + public: + base_value(pbundle b, const QString& name) : b(b), self_name(name) { + connect(b.get(), SIGNAL(reloaded()), this, SLOT(reread_value())); + } + protected: + virtual QVariant operator=(const QVariant& datum) = 0; + pbundle b; + QString self_name; + public slots: + void reread_value() + { + this->operator=(b->get<QVariant>(self_name)); + } + public slots: +#define DEFINE_SLOT(t) void setValue(t datum) { this->operator=(qVariantFromValue(datum)); } + DEFINE_SLOT(double) + DEFINE_SLOT(int) + DEFINE_SLOT(QString) + DEFINE_SLOT(bool) + signals: +#define DEFINE_SIGNAL(t) void valueChanged(t); + DEFINE_SIGNAL(double) + DEFINE_SIGNAL(int) + DEFINE_SIGNAL(QString) + DEFINE_SIGNAL(bool) + }; + + template<typename T> + class value : public base_value { + private: + T def; + protected: + QVariant operator=(const QVariant& datum) { + auto foo = qcruft_to_t<T>(datum); + b->store(self_name, qVariantFromValue<T>(foo)); + emit valueChanged(foo); + return datum; + } + public: + static constexpr const Qt::ConnectionType CONNTYPE = Qt::QueuedConnection; + value(pbundle b, const QString& name, T def) : + base_value(b, name), def(def) + { + if (!b->contains(name) || b->get<QVariant>(name).type() == QVariant::Invalid) + { + this->operator=(qVariantFromValue<T>(def)); + } + } + operator T() { return b->get<T>(self_name); } + QVariant operator=(const T& datum) + { + return this->operator =(qVariantFromValue<T>(datum)); + } + }; + + template<typename T, typename Q> + inline void tie_setting(value<T>&, Q*); + + template<> + inline void tie_setting(value<int>& v, QComboBox* cb) + { + base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int)), v.CONNTYPE); + cb->setCurrentIndex(v); + } + + template<> + inline void tie_setting(value<QString>& v, QComboBox* cb) + { + base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString)), v.CONNTYPE); + cb->setCurrentText(v); + } + + template<> + inline void tie_setting(value<bool>& v, QCheckBox* cb) + { + base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool)), v.CONNTYPE); + cb->setChecked(v); + } + + template<> + inline void tie_setting(value<double>& v, QDoubleSpinBox* dsb) + { + base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double)), v.CONNTYPE); + dsb->setValue(v); + } + + template<> + inline void tie_setting(value<int>& v, QSpinBox* sb) + { + base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)), v.CONNTYPE); + sb->setValue(v); + } + + template<> + inline void tie_setting(value<int>& v, QSlider* sl) + { + base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int)), v.CONNTYPE); + sl->setValue(v); + } + + template<> + inline void tie_setting(value<QString>& v, QLineEdit* le) + { + base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString)), v.CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString)), v.CONNTYPE); + le->setText(v); + } + + template<> + inline void tie_setting(value<QString>& v, QLabel* lb) + { + base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.CONNTYPE); + lb->setText(v); + } + + inline pbundle bundle(const QString& group) { + return std::make_shared<impl_bundle>(group); + } +} diff --git a/facetracknoir/shortcuts.cpp b/facetracknoir/shortcuts.cpp index 6a972aa3..2f117ea4 100644 --- a/facetracknoir/shortcuts.cpp +++ b/facetracknoir/shortcuts.cpp @@ -12,63 +12,55 @@ KeyboardShortcutDialog::KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget * mainApp = ftnoir; // Preserve a pointer to FTNoIR // Connect Qt signals to member-functions - connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); - connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); for ( int i = 0; i < global_key_sequences.size(); i++) { ui.cbxCenterKey->addItem(global_key_sequences.at(i)); ui.cbxToggleKey->addItem(global_key_sequences.at(i)); } - loadSettings(); -} + tie_setting(mainApp->s.center_key.key_index, ui.cbxCenterKey); + tie_setting(mainApp->s.center_key.alt, ui.chkCenterAlt); + tie_setting(mainApp->s.center_key.shift, ui.chkCenterShift); + tie_setting(mainApp->s.center_key.ctrl, ui.chkCenterCtrl); -// -// Destructor for server-dialog -// -KeyboardShortcutDialog::~KeyboardShortcutDialog() { - qDebug() << "~KeyboardShortcutDialog() says: started"; + tie_setting(mainApp->s.toggle_key.key_index, ui.cbxToggleKey); + tie_setting(mainApp->s.toggle_key.alt, ui.chkToggleAlt); + tie_setting(mainApp->s.toggle_key.shift, ui.chkToggleShift); + tie_setting(mainApp->s.toggle_key.ctrl, ui.chkToggleCtrl); } // // OK clicked on server-dialog // void KeyboardShortcutDialog::doOK() { - save(); + mainApp->b->save(); this->close(); if (mainApp->tracker) mainApp->bindKeyboardShortcuts(); } -void KeyboardShortcutDialog::showEvent ( QShowEvent * ) { - loadSettings(); -} - -// -// Cancel clicked on server-dialog -// void KeyboardShortcutDialog::doCancel() { // // Ask if changed Settings should be saved // - if (settingsDirty) { - int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); + if (mainApp->b->modifiedp()) { + int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); qDebug() << "doCancel says: answer =" << ret; switch (ret) { case QMessageBox::Save: - save(); + mainApp->b->save(); this->close(); break; case QMessageBox::Discard: - this->close(); + mainApp->b->revert(); + close(); break; case QMessageBox::Cancel: - // Cancel was clicked - break; default: - // should never be reached break; } } @@ -77,114 +69,6 @@ void KeyboardShortcutDialog::doCancel() { } } -void KeyboardShortcutDialog::loadSettings() { - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - qDebug() << "loadSettings says: iniFile = " << currentFile; - - iniFile.beginGroup ( "KB_Shortcuts" ); - - const char* names[] = { - "Center", "Toggle" - }; - - QComboBox* comboboxen[] = { - ui.cbxCenterKey, - ui.cbxToggleKey - }; - - QCheckBox* boxen[2][3] = { - { - ui.chkCenterShift, - ui.chkCenterCtrl, - ui.chkCenterAlt - }, - { - ui.chkToggleShift, - ui.chkToggleCtrl, - ui.chkToggleAlt - } - }; - - const char* modnames[] = { - "Shift", "Ctrl", "Alt" - }; - - const char* keynames[] = { - "Center", "Toggle" - }; - - const int KEY_COUNT = 2; - const int MODIFIERS = 3; - - for (int i = 0; i < KEY_COUNT; i++) - { - for (int m = 0; m < MODIFIERS; m++) - { - boxen[i][m]->setChecked (iniFile.value ( QString("%1_%2").arg(modnames[m], keynames[i]), 0).toBool()); - } - comboboxen[i]->setCurrentIndex(iniFile.value(QString("Key_index_%1").arg(names[i]), 0).toInt()); - } - - iniFile.endGroup (); - - settingsDirty = false; -} - -void KeyboardShortcutDialog::save() { - const char* keynames[] = { - "Center", "Toggle" - }; - - QComboBox* comboboxen[] = { - ui.cbxCenterKey, - ui.cbxToggleKey - }; - - const char* modnames[] = { - "Shift", "Ctrl", "Alt" - }; - - QCheckBox* boxen[2][3] = { - { - ui.chkCenterShift, - ui.chkCenterCtrl, - ui.chkCenterAlt - }, - { - ui.chkToggleShift, - ui.chkToggleCtrl, - ui.chkToggleAlt - } - }; - - const int MODIFIERS = 3; - const int KEY_COUNT = 2; - - QSettings settings("opentrack"); // Registry settings (in HK_USER) - - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup ( "KB_Shortcuts" ); - - for (int i = 0; i < KEY_COUNT; i++) - { - for (int m = 0; m < MODIFIERS; m++) - { - iniFile.setValue(QString("%1_%2").arg(modnames[m], keynames[i]), boxen[i][m]->isChecked()); - } - iniFile.setValue(QString("Key_index_%1").arg(keynames[i]), comboboxen[i]->currentIndex()); - } - - iniFile.endGroup(); - - settingsDirty = false; -} - #if defined(_WIN32) #include <windows.h> diff --git a/facetracknoir/shortcuts.h b/facetracknoir/shortcuts.h index a98211a8..f8c34be7 100644 --- a/facetracknoir/shortcuts.h +++ b/facetracknoir/shortcuts.h @@ -15,16 +15,9 @@ class KeyboardShortcutDialog: public QWidget Q_OBJECT public: - explicit KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget *parent ); - virtual ~KeyboardShortcutDialog(); - void showEvent (QShowEvent *); - + KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget *parent ); private: Ui::UICKeyboardShortcutDialog ui; - void loadSettings(); - void save(); - - bool settingsDirty; FaceTrackNoIR *mainApp; private slots: diff --git a/facetracknoir/tracker.cpp b/facetracknoir/tracker.cpp index 590d44bf..ae4398ff 100644 --- a/facetracknoir/tracker.cpp +++ b/facetracknoir/tracker.cpp @@ -22,14 +22,13 @@ # include <windows.h>
#endif
-Tracker::Tracker( FaceTrackNoIR *parent ) :
+Tracker::Tracker(FaceTrackNoIR *parent , main_settings& s) :
+ mainApp(parent),
+ s(s),
should_quit(false),
do_center(false),
- enabled(true),
- compensate(true),
- tcomp_rz(false)
+ enabled(true)
{
- mainApp = parent;
}
Tracker::~Tracker()
@@ -37,18 +36,18 @@ Tracker::~Tracker() }
static void get_curve(double pos, double& out, THeadPoseDOF& axis) {
- bool altp = (pos < 0) && axis.altp;
+ bool altp = (pos < 0) && axis.opts.altp;
if (altp) {
- out = axis.invert * axis.curveAlt.getValue(pos);
+ out = (axis.opts.invert ? -1 : 1) * axis.curveAlt.getValue(pos);
axis.curve.setTrackingActive( false );
axis.curveAlt.setTrackingActive( true );
}
else {
- out = axis.invert * axis.curve.getValue(pos);
+ out = (axis.opts.invert ? -1 : 1) * axis.curve.getValue(pos);
axis.curve.setTrackingActive( true );
axis.curveAlt.setTrackingActive( false );
}
- out += axis.zero;
+ out += axis.opts.zero;
}
static void t_compensate(double* input, double* output, bool rz)
@@ -131,7 +130,7 @@ void Tracker::run() { do_center = false;
if (Libraries->pFilter)
- Libraries->pFilter->Initialize();
+ Libraries->pFilter->reset();
}
T6DOF target_camera, target_camera2, new_camera;
@@ -154,8 +153,8 @@ void Tracker::run() { get_curve(new_camera.axes[i], output_camera.axes[i], mainApp->axis(i));
}
- if (compensate)
- t_compensate(output_camera.axes, output_camera.axes, tcomp_rz);
+ if (mainApp->s.tcomp_p)
+ t_compensate(output_camera.axes, output_camera.axes, mainApp->s.tcomp_tz);
if (Libraries->pProtocol) {
Libraries->pProtocol->sendHeadposeToGame( output_camera.axes ); // degrees & centimeters
@@ -188,5 +187,3 @@ void Tracker::getOutputHeadPose( double *data ) { for (int i = 0; i < 6; i++)
data[i] = output_camera.axes[i];
}
-
-void Tracker::setInvertAxis(Axis axis, bool invert) { mainApp->axis(axis).invert = invert? -1.0 : 1.0; }
diff --git a/facetracknoir/tracker.h b/facetracknoir/tracker.h index 987b5a24..404a8f24 100644 --- a/facetracknoir/tracker.h +++ b/facetracknoir/tracker.h @@ -12,53 +12,43 @@ #include <QMutex> #include "global-settings.h" #include <ftnoir_tracker_base/ftnoir_tracker_types.h> +#include <vector> #include <qfunctionconfigurator/functionconfig.h> #include "tracker_types.h" +#include "facetracknoir/main-settings.hpp" +#include "facetracknoir/options.h" +using namespace options; class FaceTrackNoIR; // pre-define parent-class to avoid circular includes class THeadPoseDOF { private: - THeadPoseDOF(const THeadPoseDOF &) {} - THeadPoseDOF& operator=(const THeadPoseDOF&) { return *this; } + THeadPoseDOF(const THeadPoseDOF &) = delete; + THeadPoseDOF& operator=(const THeadPoseDOF&) = delete; public: - THeadPoseDOF() : - headPos(0), - invert(0), - altp(false), - zero(0) - { - } - THeadPoseDOF(QString primary, QString secondary, int maxInput1, int maxOutput1, int maxInput2, - int maxOutput2) : + int maxOutput2, + axis_opts* opts) : headPos(0), - invert(1), curve(primary, maxInput1, maxOutput1), curveAlt(secondary, maxInput2, maxOutput2), - zero(0) + opts(*opts) { QSettings settings("opentrack"); QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); QSettings iniFile( currentFile, QSettings::IniFormat ); curve.loadSettings(iniFile); curveAlt.loadSettings(iniFile); - - iniFile.beginGroup("Tracking"); - altp = iniFile.value(secondary).toBool(); - iniFile.endGroup(); } volatile double headPos; - volatile float invert; FunctionConfig curve; FunctionConfig curveAlt; - volatile bool altp; - volatile double zero; + axis_opts& opts; }; class Tracker : public QThread { @@ -67,24 +57,21 @@ class Tracker : public QThread { private: FaceTrackNoIR *mainApp; QMutex mtx; + main_settings& s; protected: void run(); public: - Tracker( FaceTrackNoIR *parent ); + Tracker( FaceTrackNoIR *parent, main_settings& s); ~Tracker(); - void setInvertAxis(Axis axis, bool invert); - void getHeadPose(double *data); void getOutputHeadPose(double *data); volatile bool should_quit; volatile bool do_center; volatile bool enabled; - volatile bool compensate; - volatile bool tcomp_rz; T6DOF output_camera; }; @@ -92,14 +79,14 @@ public: class HeadPoseData { public: THeadPoseDOF* axes[6]; - HeadPoseData() + HeadPoseData(std::vector<axis_opts*> opts) { - axes[TX] = new THeadPoseDOF("tx","tx_alt", 25, 100, 25, 100); - axes[TY] = new THeadPoseDOF("ty","ty_alt", 25, 100, 25, 100); - axes[TZ] = new THeadPoseDOF("tz","tz_alt", 25, 100, 25, 100); - axes[Yaw] = new THeadPoseDOF("rx", "rx_alt", 180, 180, 180, 180); - axes[Pitch] = new THeadPoseDOF("ry", "ry_alt", 90, 90, 90, 90); - axes[Roll] = new THeadPoseDOF("rz", "rz_alt", 180, 180, 180, 180); + axes[TX] = new THeadPoseDOF("tx","tx_alt", 25, 100, 25, 100, opts[TX]); + axes[TY] = new THeadPoseDOF("ty","ty_alt", 25, 100, 25, 100, opts[TY]); + axes[TZ] = new THeadPoseDOF("tz","tz_alt", 25, 100, 25, 100, opts[TZ]); + axes[Yaw] = new THeadPoseDOF("rx", "rx_alt", 180, 180, 180, 180, opts[Yaw]); + axes[Pitch] = new THeadPoseDOF("ry", "ry_alt", 90, 90, 90, 90, opts[Pitch]); + axes[Roll] = new THeadPoseDOF("rz", "rz_alt", 180, 180, 180, 180, opts[Roll]); } ~HeadPoseData() { |