refs #318 Let CInputManager forward HotkeyFunc events

This commit is contained in:
Roland Winklmeier
2014-08-20 01:29:58 +02:00
parent f970e7cfaa
commit bdd7de1459
2 changed files with 14 additions and 0 deletions

View File

@@ -87,6 +87,9 @@ namespace BlackCore
void CInputManager::callFunctionsBy(const CHotkeyFunction &hotkeyFunction, bool isKeyDown)
{
BlackMisc::Event::CEventHotkeyFunction hotkeyEvent(hotkeyFunction, isKeyDown);
if(m_eventForwardingEnabled) emit hotkeyFuncEvent(hotkeyEvent);
if (!m_hashRegisteredFunctions.contains(hotkeyFunction)) return;
auto func = m_hashRegisteredFunctions.value(hotkeyFunction);
func(isKeyDown);

View File

@@ -12,6 +12,7 @@
#include "blackmisc/hwjoystickbutton.h"
#include "blackmisc/hotkeyfunction.h"
#include "blackmisc/setkeyboardhotkeylist.h"
#include "blackmisc/eveventhotkeyfunction.h"
#include <QObject>
#include <QHash>
#include <type_traits>
@@ -65,6 +66,9 @@ namespace BlackCore
//! Deletes all registered hotkeys. Be careful with this method!
void resetAllHotkeyFuncs() { m_hashRegisteredFunctions.clear(); }
//! Enable event forwarding to core
void setEventForwarding(bool enabled) { m_eventForwardingEnabled = enabled; }
//! Creates a native keyboard handler object
static CInputManager *getInstance();
@@ -76,6 +80,11 @@ namespace BlackCore
//! Call functions by hotkeyfunction
void callFunctionsBy(const BlackMisc::CHotkeyFunction &hotkeyFunction, bool isKeyDown);
signals:
//! Event hotkeyfunction occured
void hotkeyFuncEvent(const BlackMisc::Event::CEventHotkeyFunction &event);
protected:
//! Constructor
CInputManager(QObject *parent = nullptr);
@@ -102,6 +111,8 @@ namespace BlackCore
QHash<BlackMisc::CHotkeyFunction, std::function<void(bool)> > m_hashRegisteredFunctions;
QHash<BlackMisc::Hardware::CKeyboardKey, BlackMisc::CHotkeyFunction> m_hashKeyboardKeyFunctions;
QHash<BlackMisc::Hardware::CJoystickButton, BlackMisc::CHotkeyFunction> m_hashJoystickKeyFunctions;
bool m_eventForwardingEnabled = false;
};
}