diff options
author | Colin Ogilvie <colin.ogilvie@kdab.com> | 2016-01-15 13:40:10 +0000 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2016-01-19 15:21:06 +0000 |
commit | d38cd8cd2d913f30b0e23c8d6b9a274f4f47036d (patch) | |
tree | 67894812a624be31f705207a84b3c3bc6fe9878b /src/input/backend/updateaxisactionjob.cpp | |
parent | 034ac26201c87179a9bba25571f926a212542cd9 (diff) |
Aggregate action functionality
Change-Id: Iac5e6bfd2ad67b3c1c9a794ea528204eff238d20
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input/backend/updateaxisactionjob.cpp')
-rw-r--r-- | src/input/backend/updateaxisactionjob.cpp | 72 |
1 files changed, 61 insertions, 11 deletions
diff --git a/src/input/backend/updateaxisactionjob.cpp b/src/input/backend/updateaxisactionjob.cpp index 406aa952c..6b7f0f457 100644 --- a/src/input/backend/updateaxisactionjob.cpp +++ b/src/input/backend/updateaxisactionjob.cpp @@ -62,8 +62,9 @@ bool anyOfRequiredKeysPressed(const QVector<int> &keys, QAbstractPhysicalDeviceB } // anonymous -UpdateAxisActionJob::UpdateAxisActionJob(InputHandler *handler, HLogicalDevice handle) +UpdateAxisActionJob::UpdateAxisActionJob(qint64 currentTime, InputHandler *handler, HLogicalDevice handle) : Qt3DCore::QAspectJob() + , m_currentTime(currentTime) , m_handler(handler) , m_handle(handle) { @@ -85,21 +86,70 @@ void UpdateAxisActionJob::updateAction(LogicalDevice *device) Action *action = m_handler->actionManager()->lookupResource(actionId); Q_FOREACH (const Qt3DCore::QNodeId actionInputId, action->inputs()) { - ActionInput *actionInput = m_handler->actionInputManager()->lookupResource(actionInputId); - QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = Q_NULLPTR; + actionTriggered |= processActionInput(actionInputId); + } + action->setActionTriggered(actionTriggered); + } +} - Q_FOREACH (QInputDeviceIntegration *integration, m_handler->inputDeviceIntegrations()) { - if ((physicalDeviceBackend = integration->physicalDevice(actionInput->sourceDevice())) != Q_NULLPTR) - break; - } +bool UpdateAxisActionJob::processActionInput(const Qt3DCore::QNodeId actionInputId) +{ - if (physicalDeviceBackend != Q_NULLPTR) { - // Update the value - actionTriggered |= anyOfRequiredKeysPressed(actionInput->keys(), physicalDeviceBackend); + if (m_handler->actionInputManager()->lookupResource(actionInputId)) { + ActionInput *actionInput = m_handler->actionInputManager()->lookupResource(actionInputId); + QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = Q_NULLPTR; + + Q_FOREACH (QInputDeviceIntegration *integration, m_handler->inputDeviceIntegrations()) { + if ((physicalDeviceBackend = integration->physicalDevice(actionInput->sourceDevice())) != Q_NULLPTR) + break; + } + + if (physicalDeviceBackend != Q_NULLPTR) { + // Update the value + return anyOfRequiredKeysPressed(actionInput->keys(), physicalDeviceBackend); + } + } else if (m_handler->inputSequenceManager()->lookupResource(actionInputId)) { + InputSequence *inputSequence = m_handler->inputSequenceManager()->lookupResource(actionInputId); + const qint64 startTime = inputSequence->startTime(); + if (startTime != 0) { + // Check if we are still inside the time limit for the chord + if ((m_currentTime - startTime) > inputSequence->timeout()) { + inputSequence->reset(); + return false; } } - action->setActionTriggered(actionTriggered); + bool actionTriggered = false; + Q_FOREACH (const Qt3DCore::QNodeId actionInputId, inputSequence->inputs()) { + if (processActionInput(actionInputId)){ + actionTriggered |= inputSequence->actionTriggered(actionInputId, m_currentTime); + // Set the start time if it wasn't set before + if (startTime == 0) + inputSequence->setStartTime(m_currentTime); + } + } + return actionTriggered; + } else if (m_handler->inputChordManager()->lookupResource(actionInputId)) { + InputChord *inputChord = m_handler->inputChordManager()->lookupResource(actionInputId); + const qint64 startTime = inputChord->startTime(); + if (startTime != 0) { + // Check if we are still inside the time limit for the chord + if ((m_currentTime - startTime) > inputChord->tolerance()) { + inputChord->reset(); + return false; + } + } + bool actionTriggered = false; + Q_FOREACH (const Qt3DCore::QNodeId actionInputId, inputChord->inputs()) { + if (processActionInput(actionInputId)){ + actionTriggered |= inputChord->actionTriggered(actionInputId); + if (startTime == 0) + inputChord->setStartTime(m_currentTime); + } + } + return actionTriggered; } + //Should Never reach this point + return false; } void UpdateAxisActionJob::updateAxis(LogicalDevice *device) |