summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir/facetracknoir.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-10-16 20:59:40 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-10-16 20:59:40 +0200
commit33ed4d75801d547572e4d3c55a4f459d28dcf646 (patch)
treec845392790b2eca5556432dfd75db6ddb4390078 /facetracknoir/facetracknoir.cpp
parent8e988b5a8509cf811ababd8e49ce85aa4afe4da0 (diff)
parent015547df5de7dcfaa60bfa6f8ac30b1f9c91385a (diff)
New feature: tracker disablement on keystroke
Requested-by: Patrick Ruoff (c14) Reviewed-by: mm0zct (first commit) Untested on Win32! Not even compile-time-tested... Merge remote-tracking branch 'origin/feature/toggle-tracking-enabled-20131016'
Diffstat (limited to 'facetracknoir/facetracknoir.cpp')
-rw-r--r--facetracknoir/facetracknoir.cpp128
1 files changed, 78 insertions, 50 deletions
diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp
index eb24b320..af630bea 100644
--- a/facetracknoir/facetracknoir.cpp
+++ b/facetracknoir/facetracknoir.cpp
@@ -91,11 +91,12 @@ static void fill_combobox(const QString& filter, QList<DynamicLibrary*>& list, Q
//
FaceTrackNoIR::FaceTrackNoIR(QWidget *parent, Qt::WindowFlags flags) :
QMainWindow(parent, flags),
- #if defined(_WIN32)
- keybindingWorker(NULL),
- #else
- keyCenter(0),
- #endif
+#if defined(_WIN32)
+ keybindingWorker(NULL),
+#else
+ keyCenter(this),
+ keyToggle(this),
+#endif
timUpdateHeadPose(this),
pTrackerDialog(NULL),
pSecondTrackerDialog(NULL),
@@ -181,6 +182,9 @@ FaceTrackNoIR::FaceTrackNoIR(QWidget *parent, Qt::WindowFlags flags) :
ui.lcdNumOutputRotX->setVisible(false);
ui.lcdNumOutputRotY->setVisible(false);
ui.lcdNumOutputRotZ->setVisible(false);
+
+ connect(&keyCenter, SIGNAL(activated()), this, SLOT(shortcutRecentered()));
+ connect(&keyToggle, SIGNAL(activated()), this, SLOT(shortcutToggled()));
}
/** destructor stops the engine and quits the faceapi **/
@@ -544,7 +548,7 @@ void FaceTrackNoIR::startTracker( ) {
}
#if defined(_WIN32)
- keybindingWorker = new KeybindingWorker(*this, keyCenter);
+ keybindingWorker = new KeybindingWorker(*this, &keyCenter, &keyToggle);
keybindingWorker->start();
#endif
@@ -912,73 +916,97 @@ void FaceTrackNoIR::profileSelected(int index)
loadSettings();
}
-void FaceTrackNoIR::bindKeyboardShortcuts()
-{
- 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" );
- int idxCenter = iniFile.value("Key_index_Center", 0).toInt();
-
#if !defined(_WIN32)
- if (keyCenter) {
- delete keyCenter;
- keyCenter = NULL;
- }
-
- if (idxCenter > 0)
+void FaceTrackNoIR::bind_keyboard_shortcut(QxtGlobalShortcut& key, const QString label, QSettings& iniFile)
+{
+ const int idx = iniFile.value("Key_index_" + label, 0).toInt();
+ key.setShortcut(QKeySequence::fromString(""));
+ key.setDisabled();
+ QString seq(global_key_sequences.value(idx, ""));
+ if (idx > 0)
{
- QString seq(global_key_sequences.value(idxCenter, ""));
if (!seq.isEmpty())
{
- if (iniFile.value("Shift_Center", false).toBool())
+ if (iniFile.value(QString("Shift_%1").arg(label), false).toBool())
seq = "Shift+" + seq;
- if (iniFile.value("Alt_Center", false).toBool())
+ if (iniFile.value(QString("Alt_%1").arg(label), false).toBool())
seq = "Alt+" + seq;
- if (iniFile.value("Ctrl_Center", false).toBool())
+ if (iniFile.value(QString("Ctrl_%1").arg(label), false).toBool())
seq = "Ctrl+" + seq;
- keyCenter = new QxtGlobalShortcut(QKeySequence(seq), this);
- connect(keyCenter, SIGNAL(activated()), this, SLOT(shortcutRecentered()));
+ key.setShortcut(QKeySequence::fromString(seq, QKeySequence::NativeText));
+ key.setEnabled();
}
}
+}
#else
- keyCenter.keycode = 0;
- keyCenter.shift = keyCenter.alt = keyCenter.ctrl = 0;
- if (idxCenter > 0 && idxCenter < global_windows_key_sequences.size())
- keyCenter.keycode = global_windows_key_sequences[idxCenter];
- keyCenter.shift = iniFile.value("Shift_Center", false).toBool();
- keyCenter.alt = iniFile.value("Alt_Center", false).toBool();
- keyCenter.ctrl = iniFile.value("Ctrl_Center", false).toBool();
+static void bind_keyboard_shotcut(Key& key, const QString label, QSettings& iniFile)
+{
+ const int idx = iniFile.value("Key_index_" + label, 0).toInt();
+ 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_").arg(label), false).toBool();
+ key.alt = iniFile.value(QString("Alt_").arg(label), false).toBool();
+ key.ctrl = iniFile.value(QString("Ctrl_").arg(label), false).toBool();
+ }
+}
#endif
- iniFile.endGroup ();
+
+void FaceTrackNoIR::bindKeyboardShortcuts()
+{
+ 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" );
+#if !defined(_WIN32)
+ bind_keyboard_shortcut(keyCenter, "Center", iniFile);
+ bind_keyboard_shortcut(keyToggle, "Toggle", iniFile);
+#else
+ bind_keyboard_shortcut(&keyCenter, "Center", iniFile));
+ bind_keyboard_shortcut(&keyToggle, "Toggle", iniFile));
+#endif
+ iniFile.endGroup ();
+
if (tracker) /* running already */
{
#if defined(_WIN32)
- if (keybindingWorker)
- {
- keybindingWorker->should_quit = true;
- keybindingWorker->wait();
- delete keybindingWorker;
- keybindingWorker = NULL;
- }
- keybindingWorker = new KeybindingWorker(*this, keyCenter);
- keybindingWorker->start();
+ if (keybindingWorker)
+ {
+ keybindingWorker->should_quit = true;
+ keybindingWorker->wait();
+ delete keybindingWorker;
+ keybindingWorker = NULL;
+ }
+ const int idx_center = iniFile.value("Key_index_Center", 0).toInt();
+ const int idx_toggle = iniFile.value("Key_index_Toggle", 0).toInt();
+ keybindingWorker = new KeybindingWorker(*this, keyCenter, keyToggle);
+ keybindingWorker->start();
#endif
}
}
void FaceTrackNoIR::shortcutRecentered()
{
+ QApplication::beep();
+
+ qDebug() << "Center";
if (tracker)
{
-#if defined(_WIN32)
- MessageBeep(MB_OK);
-#else
- QApplication::beep();
-#endif
- qDebug() << "Center";
tracker->do_center = true;
}
}
+
+void FaceTrackNoIR::shortcutToggled()
+{
+ QApplication::beep();
+ qDebug() << "Toggle";
+ if (tracker)
+ {
+ tracker->enabled = !tracker->enabled;
+ }
+}