diff options
Diffstat (limited to 'facetracknoir/shortcuts.cpp')
-rw-r--r-- | facetracknoir/shortcuts.cpp | 104 |
1 files changed, 82 insertions, 22 deletions
diff --git a/facetracknoir/shortcuts.cpp b/facetracknoir/shortcuts.cpp index 43c1019d..1cd967e0 100644 --- a/facetracknoir/shortcuts.cpp +++ b/facetracknoir/shortcuts.cpp @@ -17,6 +17,7 @@ KeyboardShortcutDialog::KeyboardShortcutDialog( FaceTrackNoIR *ftnoir, QWidget * 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(); @@ -38,8 +39,7 @@ void KeyboardShortcutDialog::doOK() { mainApp->bindKeyboardShortcuts(); } -// override show event -void KeyboardShortcutDialog::showEvent ( QShowEvent * event ) { +void KeyboardShortcutDialog::showEvent ( QShowEvent * ) { loadSettings(); } @@ -76,11 +76,7 @@ void KeyboardShortcutDialog::doCancel() { } } -// -// Load the current Settings from the currently 'active' INI-file. -// void KeyboardShortcutDialog::loadSettings() { - qDebug() << "loadSettings says: Starting "; QSettings settings("opentrack"); // Registry settings (in HK_USER) QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); @@ -90,24 +86,82 @@ void KeyboardShortcutDialog::loadSettings() { iniFile.beginGroup ( "KB_Shortcuts" ); - ui.chkCenterShift->setChecked (iniFile.value ( "Shift_Center", 0 ).toBool()); - ui.chkCenterCtrl->setChecked (iniFile.value ( "Ctrl_Center", 0 ).toBool()); - ui.chkCenterAlt->setChecked (iniFile.value ( "Alt_Center", 0 ).toBool()); + 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" + }; - ui.cbxCenterKey->setCurrentIndex(iniFile.value("Key_index_Center", 0).toInt()); + 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; - } -// -// Save the current Settings to the currently 'active' INI-file. -// 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 + } + }; - qDebug() << "save() says: started"; + const int MODIFIERS = 3; + const int KEY_COUNT = 2; QSettings settings("opentrack"); // Registry settings (in HK_USER) @@ -115,12 +169,17 @@ void KeyboardShortcutDialog::save() { QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) iniFile.beginGroup ( "KB_Shortcuts" ); - iniFile.setValue ( "Key_index_Center", ui.cbxCenterKey->currentIndex() ); - iniFile.setValue ( "Shift_Center", ui.chkCenterShift->isChecked() ); - iniFile.setValue ( "Ctrl_Center", ui.chkCenterCtrl->isChecked() ); - iniFile.setValue ( "Alt_Center", ui.chkCenterAlt->isChecked() ); - iniFile.endGroup (); + 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; } @@ -137,8 +196,8 @@ KeybindingWorkerImpl::~KeybindingWorkerImpl() { din->Release(); } -KeybindingWorkerImpl::KeybindingWorkerImpl(FaceTrackNoIR& w, Key keyCenter) -: din(0), dinkeyboard(0), kCenter(keyCenter), window(w), should_quit(true) +KeybindingWorkerImpl::KeybindingWorkerImpl(FaceTrackNoIR& w, Key keyCenter, Key keyToggle) +: din(0), dinkeyboard(0), kCenter(keyCenter), ktoggle(keyTogle), window(w), should_quit(true) { if (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL) != DI_OK) { qDebug() << "setup DirectInput8 Creation failed!" << GetLastError(); @@ -219,6 +278,7 @@ void KeybindingWorkerImpl::run() { } PROCESS_KEY(kCenter, shortcutRecentered); + PROCESS_KEY(kToggle, shortcutToggled); Sleep(25); } |