Trigger action only if it is enabled.

This commit is contained in:
Gres 2015-09-27 18:58:06 +03:00
parent 26ddd92584
commit 5c7220707e
2 changed files with 9 additions and 8 deletions

View File

@ -62,6 +62,12 @@ bool GlobalActionHelper::removeGlobal (QAction *action) {
return res; return res;
} }
void GlobalActionHelper::triggerHotKey (quint32 nativeKey, quint32 nativeMods) {
QAction *action = actions_.value (qMakePair (nativeKey, nativeMods));
if (action && action->isEnabled ()) {
action->activate (QAction::Trigger);
}
}
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
@ -124,10 +130,7 @@ bool GlobalActionHelper::nativeEventFilter (const QByteArray &eventType,
xcb_key_press_event_t *keyEvent = static_cast<xcb_key_press_event_t *>(message); xcb_key_press_event_t *keyEvent = static_cast<xcb_key_press_event_t *>(message);
const quint32 keycode = keyEvent->detail; const quint32 keycode = keyEvent->detail;
const quint32 modifiers = keyEvent->state & ~XCB_MOD_MASK_2; const quint32 modifiers = keyEvent->state & ~XCB_MOD_MASK_2;
QAction *action = actions_.value (qMakePair (keycode, modifiers)); triggerHotKey (keycode, modifiers);
if (action) {
action->activate (QAction::Trigger);
}
} }
return false; return false;
} }
@ -177,10 +180,7 @@ bool GlobalActionHelper::nativeEventFilter (const QByteArray &eventType,
if (msg->message == WM_HOTKEY) { if (msg->message == WM_HOTKEY) {
const quint32 keycode = HIWORD (msg->lParam); const quint32 keycode = HIWORD (msg->lParam);
const quint32 modifiers = LOWORD (msg->lParam); const quint32 modifiers = LOWORD (msg->lParam);
QAction *action = actions_.value (qMakePair (keycode, modifiers)); triggerHotKey (keycode, modifiers);
if (action) {
action->activate (QAction::Trigger);
}
} }
return false; return false;
} }

View File

@ -22,6 +22,7 @@ class GlobalActionHelper : public QAbstractNativeEventFilter {
static quint32 nativeModifiers (Qt::KeyboardModifiers modifiers); static quint32 nativeModifiers (Qt::KeyboardModifiers modifiers);
static bool registerHotKey (quint32 nativeKey, quint32 nativeMods); static bool registerHotKey (quint32 nativeKey, quint32 nativeMods);
static bool unregisterHotKey (quint32 nativeKey, quint32 nativeMods); static bool unregisterHotKey (quint32 nativeKey, quint32 nativeMods);
static void triggerHotKey (quint32 nativeKey, quint32 nativeMods);
}; };