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

@@ -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;