mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 11:45:40 +08:00
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:
committed by
Mat Sutcliffe
parent
c51a1b8c7b
commit
563a69e3f5
@@ -93,6 +93,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
m_captureActive = true;
|
m_captureActive = true;
|
||||||
m_capturedCombination = {};
|
m_capturedCombination = {};
|
||||||
|
m_combinationBeforeCapture = m_lastCombination;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputManager::callFunctionsBy(const QString &action, bool isKeyDown, bool shouldEmit)
|
void CInputManager::callFunctionsBy(const QString &action, bool isKeyDown, bool shouldEmit)
|
||||||
@@ -156,15 +157,20 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (m_captureActive)
|
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);
|
emit combinationSelectionFinished(m_capturedCombination);
|
||||||
m_captureActive = false;
|
m_captureActive = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit combinationSelectionChanged(currentCombination);
|
emit combinationSelectionChanged(deltaCombination);
|
||||||
m_capturedCombination = currentCombination;
|
m_capturedCombination = deltaCombination;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ namespace BlackCore
|
|||||||
bool m_captureActive = false;
|
bool m_captureActive = false;
|
||||||
BlackMisc::Input::CHotkeyCombination m_lastCombination;
|
BlackMisc::Input::CHotkeyCombination m_lastCombination;
|
||||||
BlackMisc::Input::CHotkeyCombination m_capturedCombination;
|
BlackMisc::Input::CHotkeyCombination m_capturedCombination;
|
||||||
|
BlackMisc::Input::CHotkeyCombination m_combinationBeforeCapture;
|
||||||
|
|
||||||
BlackMisc::CSetting<Application::TActionHotkeys> m_actionHotkeys { this, &CInputManager::reloadHotkeySettings };
|
BlackMisc::CSetting<Application::TActionHotkeys> m_actionHotkeys { this, &CInputManager::reloadHotkeySettings };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -185,7 +185,17 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CSettingsHotkeyComponent::hotkeySlot(bool keyDown)
|
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()
|
bool CConfigHotkeyWizardPage::validatePage()
|
||||||
|
|||||||
@@ -25,20 +25,30 @@ namespace BlackMisc
|
|||||||
CHotkeyCombination::CHotkeyCombination(const CKeyboardKeyList &keys) : m_keyboardKeys(keys)
|
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; }
|
if (m_keyboardKeys.contains(key)) { return; }
|
||||||
m_keyboardKeys.push_back(key);
|
m_keyboardKeys.push_back(key);
|
||||||
m_keyboardKeys.sortBy(&CKeyboardKey::getKey);
|
m_keyboardKeys.sortBy(&CKeyboardKey::getKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHotkeyCombination::addJoystickButton(CJoystickButton button)
|
void CHotkeyCombination::addJoystickButton(const CJoystickButton &button)
|
||||||
{
|
{
|
||||||
if (m_joystickButtons.contains(button)) { return; }
|
if (m_joystickButtons.contains(button)) { return; }
|
||||||
m_joystickButtons.push_back(button);
|
m_joystickButtons.push_back(button);
|
||||||
m_joystickButtons.sortBy(&CJoystickButton::getButtonIndex);
|
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)
|
void CHotkeyCombination::replaceKey(CKeyboardKey oldKey, CKeyboardKey newKey)
|
||||||
{
|
{
|
||||||
if (oldKey.hasKey())
|
if (oldKey.hasKey())
|
||||||
@@ -70,7 +80,24 @@ namespace BlackMisc
|
|||||||
bool CHotkeyCombination::isSubsetOf(const CHotkeyCombination &other) const
|
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); }) &&
|
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
|
QString CHotkeyCombination::convertToQString(bool i18n) const
|
||||||
|
|||||||
@@ -55,10 +55,16 @@ namespace BlackMisc
|
|||||||
CJoystickButtonList getJoystickButtons() const { return m_joystickButtons; }
|
CJoystickButtonList getJoystickButtons() const { return m_joystickButtons; }
|
||||||
|
|
||||||
//! Add keyboard key
|
//! Add keyboard key
|
||||||
void addKeyboardKey(CKeyboardKey key);
|
void addKeyboardKey(const CKeyboardKey &key);
|
||||||
|
|
||||||
//! Add joystick button
|
//! 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
|
//! Replace oldKey with newKey
|
||||||
void replaceKey(CKeyboardKey oldKey, CKeyboardKey newKey);
|
void replaceKey(CKeyboardKey oldKey, CKeyboardKey newKey);
|
||||||
@@ -82,6 +88,9 @@ namespace BlackMisc
|
|||||||
//! E.g. CTRL would be a subset of CTRL+D
|
//! E.g. CTRL would be a subset of CTRL+D
|
||||||
bool isSubsetOf(const CHotkeyCombination &other) const;
|
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
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user