Remember and ignore hotkey combination before capturing

When capturing a new hotkey combination, we want to get only the delta of the keys and buttons being pressed during the capturing. 

ref T585
This commit is contained in:
Roland Rossgotterer
2019-04-11 10:08:58 +02:00
committed by Mat Sutcliffe
parent c51a1b8c7b
commit 563a69e3f5
5 changed files with 62 additions and 9 deletions

View File

@@ -93,6 +93,7 @@ namespace BlackCore
{
m_captureActive = true;
m_capturedCombination = {};
m_combinationBeforeCapture = m_lastCombination;
}
void CInputManager::callFunctionsBy(const QString &action, bool isKeyDown, bool shouldEmit)
@@ -156,15 +157,20 @@ namespace BlackCore
{
if (m_captureActive)
{
if (currentCombination.size() < m_capturedCombination.size())
CHotkeyCombination deltaCombination = currentCombination.getDeltaComparedTo(m_combinationBeforeCapture);
// Don't continue if there is no relevant combination yet
if (m_capturedCombination.isEmpty() && deltaCombination.isEmpty()) { return; }
if (deltaCombination.size() < m_capturedCombination.size())
{
emit combinationSelectionFinished(m_capturedCombination);
m_captureActive = false;
}
else
{
emit combinationSelectionChanged(currentCombination);
m_capturedCombination = currentCombination;
emit combinationSelectionChanged(deltaCombination);
m_capturedCombination = deltaCombination;
}
return;
}

View File

@@ -147,6 +147,7 @@ namespace BlackCore
bool m_captureActive = false;
BlackMisc::Input::CHotkeyCombination m_lastCombination;
BlackMisc::Input::CHotkeyCombination m_capturedCombination;
BlackMisc::Input::CHotkeyCombination m_combinationBeforeCapture;
BlackMisc::CSetting<Application::TActionHotkeys> m_actionHotkeys { this, &CInputManager::reloadHotkeySettings };
};

View File

@@ -185,7 +185,17 @@ namespace BlackGui
void CSettingsHotkeyComponent::hotkeySlot(bool keyDown)
{
if (keyDown) { QMessageBox::information(this, "Test", "Hotkey test"); }
if (keyDown)
{
QMessageBox* msgBox = new QMessageBox(this);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setWindowTitle("Test");
msgBox->setText("Hotkey test");
msgBox->setIcon(QMessageBox::Information);
msgBox->setModal(false);
msgBox->open();
}
}
bool CConfigHotkeyWizardPage::validatePage()

View File

@@ -25,20 +25,30 @@ namespace BlackMisc
CHotkeyCombination::CHotkeyCombination(const CKeyboardKeyList &keys) : m_keyboardKeys(keys)
{ }
void CHotkeyCombination::addKeyboardKey(CKeyboardKey key)
void CHotkeyCombination::addKeyboardKey(const CKeyboardKey &key)
{
if (m_keyboardKeys.contains(key)) { return; }
m_keyboardKeys.push_back(key);
m_keyboardKeys.sortBy(&CKeyboardKey::getKey);
}
void CHotkeyCombination::addJoystickButton(CJoystickButton button)
void CHotkeyCombination::addJoystickButton(const CJoystickButton &button)
{
if (m_joystickButtons.contains(button)) { return; }
m_joystickButtons.push_back(button);
m_joystickButtons.sortBy(&CJoystickButton::getButtonIndex);
}
bool CHotkeyCombination::containsKeyboardKey(const CKeyboardKey &key) const
{
return m_keyboardKeys.contains(key);
}
bool CHotkeyCombination::containsJoystickButton(const CJoystickButton &button) const
{
return m_joystickButtons.contains(button);
}
void CHotkeyCombination::replaceKey(CKeyboardKey oldKey, CKeyboardKey newKey)
{
if (oldKey.hasKey())
@@ -70,7 +80,24 @@ namespace BlackMisc
bool CHotkeyCombination::isSubsetOf(const CHotkeyCombination &other) const
{
return std::all_of(m_keyboardKeys.begin(), m_keyboardKeys.end(), [&other](const CKeyboardKey & k) { return other.m_keyboardKeys.contains(k); }) &&
std::all_of(m_joystickButtons.begin(), m_joystickButtons.end(), [&other](const CJoystickButton & b) { return other.m_joystickButtons.contains(b); });
std::all_of(m_joystickButtons.begin(), m_joystickButtons.end(), [&other](const CJoystickButton & b) { return other.m_joystickButtons.contains(b); });
}
CHotkeyCombination CHotkeyCombination::getDeltaComparedTo(const CHotkeyCombination &other) const
{
CHotkeyCombination combination(*this);
const CKeyboardKeyList otherKeys = other.getKeyboardKeys();
for (const CKeyboardKey &key : otherKeys)
{
if (containsKeyboardKey(key)) { combination.removeKeyboardKey(key); }
}
const CJoystickButtonList otherButtons = other.getJoystickButtons();
for (const CJoystickButton &button : otherButtons)
{
if (containsJoystickButton(button)) { combination.removeJoystickButton(button); }
}
return combination;
}
QString CHotkeyCombination::convertToQString(bool i18n) const

View File

@@ -55,10 +55,16 @@ namespace BlackMisc
CJoystickButtonList getJoystickButtons() const { return m_joystickButtons; }
//! Add keyboard key
void addKeyboardKey(CKeyboardKey key);
void addKeyboardKey(const CKeyboardKey &key);
//! Add joystick button
void addJoystickButton(CJoystickButton button);
void addJoystickButton(const CJoystickButton &button);
//! Does combination contain key?
bool containsKeyboardKey(const CKeyboardKey &key) const;
//! Does combination contain button?
bool containsJoystickButton(const CJoystickButton &button) const;
//! Replace oldKey with newKey
void replaceKey(CKeyboardKey oldKey, CKeyboardKey newKey);
@@ -82,6 +88,9 @@ namespace BlackMisc
//! E.g. CTRL would be a subset of CTRL+D
bool isSubsetOf(const CHotkeyCombination &other) const;
//! Returns the delta (removing all keys and buttons contained in other)
CHotkeyCombination getDeltaComparedTo(const CHotkeyCombination &other) const;
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;