|
|
|
@ -41,10 +41,11 @@ namespace CSMPrefs
|
|
|
|
|
else if (event->type() == QEvent::KeyRelease)
|
|
|
|
|
{
|
|
|
|
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
|
|
|
|
unsigned int mod = (unsigned int) keyEvent->modifiers();
|
|
|
|
|
unsigned int key = (unsigned int) keyEvent->key();
|
|
|
|
|
|
|
|
|
|
if (!keyEvent->isAutoRepeat())
|
|
|
|
|
return deactivate(key);
|
|
|
|
|
return deactivate(mod, key);
|
|
|
|
|
}
|
|
|
|
|
else if (event->type() == QEvent::MouseButtonPress)
|
|
|
|
|
{
|
|
|
|
@ -57,9 +58,10 @@ namespace CSMPrefs
|
|
|
|
|
else if (event->type() == QEvent::MouseButtonRelease)
|
|
|
|
|
{
|
|
|
|
|
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
|
|
|
|
|
unsigned int mod = (unsigned int) mouseEvent->modifiers();
|
|
|
|
|
unsigned int button = (unsigned int) mouseEvent->button();
|
|
|
|
|
|
|
|
|
|
return deactivate(button);
|
|
|
|
|
return deactivate(mod, button);
|
|
|
|
|
}
|
|
|
|
|
else if (event->type() == QEvent::FocusOut)
|
|
|
|
|
{
|
|
|
|
@ -68,10 +70,18 @@ namespace CSMPrefs
|
|
|
|
|
{
|
|
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
|
|
|
|
|
if (shortcut->isActive())
|
|
|
|
|
shortcut->setPosition(0);
|
|
|
|
|
shortcut->setModifierStatus(false);
|
|
|
|
|
|
|
|
|
|
if (shortcut->getActivationStatus() == Shortcut::AS_Regular)
|
|
|
|
|
{
|
|
|
|
|
shortcut->activate(false);
|
|
|
|
|
shortcut->setPosition(0);
|
|
|
|
|
shortcut->setActivationStatus(Shortcut::AS_Inactive);
|
|
|
|
|
emit shortcut->activated(false);
|
|
|
|
|
}
|
|
|
|
|
else if (shortcut->getActivationStatus() == Shortcut::AS_Secondary)
|
|
|
|
|
{
|
|
|
|
|
shortcut->setActivationStatus(Shortcut::AS_Inactive);
|
|
|
|
|
emit shortcut->secondary(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -88,39 +98,56 @@ namespace CSMPrefs
|
|
|
|
|
for (std::vector<Shortcut*>::iterator it = mShortcuts.begin(); it != mShortcuts.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
int pos = shortcut->getPosition();
|
|
|
|
|
int lastPos = shortcut->getLastPosition();
|
|
|
|
|
MatchResult result = match(mod, button, shortcut->getSequence()[pos]);
|
|
|
|
|
|
|
|
|
|
if (!shortcut->isEnabled())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int pos = shortcut->getPosition();
|
|
|
|
|
int lastPos = shortcut->getLastPosition();
|
|
|
|
|
MatchResult result = match(mod, button, shortcut->getSequence()[pos]);
|
|
|
|
|
|
|
|
|
|
if (result == Matches_WithMod || result == Matches_NoMod)
|
|
|
|
|
{
|
|
|
|
|
if (pos < lastPos && (result == Matches_WithMod || pos > 0))
|
|
|
|
|
{
|
|
|
|
|
shortcut->setPosition(pos+1);
|
|
|
|
|
used = true;
|
|
|
|
|
}
|
|
|
|
|
else if (pos == lastPos)
|
|
|
|
|
{
|
|
|
|
|
potentials.push_back(std::make_pair(result, shortcut));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (checkModifier(mod, button, shortcut, true))
|
|
|
|
|
used = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only activate the best match; in exact conflicts, this will favor the first shortcut added.
|
|
|
|
|
if (!potentials.empty())
|
|
|
|
|
{
|
|
|
|
|
std::sort(potentials.begin(), potentials.end(), ShortcutEventHandler::sort);
|
|
|
|
|
potentials.front().second->activate(true);
|
|
|
|
|
Shortcut* shortcut = potentials.front().second;
|
|
|
|
|
|
|
|
|
|
if (shortcut->getModifierStatus() && shortcut->getSecondaryMode() == Shortcut::SM_Replace)
|
|
|
|
|
{
|
|
|
|
|
shortcut->setActivationStatus(Shortcut::AS_Secondary);
|
|
|
|
|
emit shortcut->secondary(true);
|
|
|
|
|
emit shortcut->secondary();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shortcut->setActivationStatus(Shortcut::AS_Regular);
|
|
|
|
|
emit shortcut->activated(true);
|
|
|
|
|
emit shortcut->activated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
used = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return used;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ShortcutEventHandler::deactivate(unsigned int button)
|
|
|
|
|
bool ShortcutEventHandler::deactivate(unsigned int mod, unsigned int button)
|
|
|
|
|
{
|
|
|
|
|
const int KeyMask = 0x01FFFFFF;
|
|
|
|
|
|
|
|
|
@ -129,16 +156,66 @@ namespace CSMPrefs
|
|
|
|
|
for (std::vector<Shortcut*>::iterator it = mShortcuts.begin(); it != mShortcuts.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
|
|
|
|
|
if (checkModifier(mod, button, shortcut, false))
|
|
|
|
|
used = true;
|
|
|
|
|
|
|
|
|
|
int pos = shortcut->getPosition();
|
|
|
|
|
MatchResult result = match(0, button, shortcut->getSequence()[pos] & KeyMask);
|
|
|
|
|
|
|
|
|
|
if (result != Matches_Not)
|
|
|
|
|
{
|
|
|
|
|
if (shortcut->isActive())
|
|
|
|
|
shortcut->activate(false);
|
|
|
|
|
|
|
|
|
|
shortcut->setPosition(0);
|
|
|
|
|
|
|
|
|
|
if (shortcut->getActivationStatus() == Shortcut::AS_Regular)
|
|
|
|
|
{
|
|
|
|
|
shortcut->setActivationStatus(Shortcut::AS_Inactive);
|
|
|
|
|
emit shortcut->activated(false);
|
|
|
|
|
used = true;
|
|
|
|
|
}
|
|
|
|
|
else if (shortcut->getActivationStatus() == Shortcut::AS_Secondary)
|
|
|
|
|
{
|
|
|
|
|
shortcut->setActivationStatus(Shortcut::AS_Inactive);
|
|
|
|
|
emit shortcut->secondary(false);
|
|
|
|
|
used = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return used;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ShortcutEventHandler::checkModifier(unsigned int mod, unsigned int button, Shortcut* shortcut, bool activate)
|
|
|
|
|
{
|
|
|
|
|
if (!shortcut->isEnabled() || !shortcut->getModifier() || shortcut->getSecondaryMode() == Shortcut::SM_Ignore)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
MatchResult result = match(mod, button, shortcut->getModifier());
|
|
|
|
|
bool used = false;
|
|
|
|
|
|
|
|
|
|
if (result != Matches_Not)
|
|
|
|
|
{
|
|
|
|
|
shortcut->setModifierStatus(activate);
|
|
|
|
|
|
|
|
|
|
if (shortcut->getSecondaryMode() == Shortcut::SM_Detach)
|
|
|
|
|
{
|
|
|
|
|
if (activate)
|
|
|
|
|
{
|
|
|
|
|
emit shortcut->secondary(true);
|
|
|
|
|
emit shortcut->secondary();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
emit shortcut->secondary(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
used = true;
|
|
|
|
|
}
|
|
|
|
|
else if (!activate && shortcut->getActivationStatus() == Shortcut::AS_Secondary)
|
|
|
|
|
{
|
|
|
|
|
shortcut->setActivationStatus(Shortcut::AS_Inactive);
|
|
|
|
|
shortcut->setPosition(0);
|
|
|
|
|
emit shortcut->secondary(false);
|
|
|
|
|
used = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|