DtQmlGamepad loads a QML user interface displaying virtual gamepad controls (buttons, joysticks) and translates Qt Quick touch events into a generic event format that can be consumed by VR-Engage's input system.
Key Patterns Demonstrated:
- QML-to-C++ event bridging using Q_INVOKABLE methods
- Context property registration for QML access to C++ objects
- QML page lifecycle management (load, show/hide, unload)
- Application state-driven UI visibility control
- Generic event callback system using DtDelegate
This class acts as the "view" layer in a custom input device implementation, handling presentation and user interaction while delegating input processing to DtQmlGamepadInputDevice.
Integration with DtQmlGamepadInputDevice: DtQmlGamepadInputDevice registers callbacks with this class to receive input events, then transforms them into DtInputData structures for VR-Engage's input mapping system.
template<typename T, typename Method>
| void makVre::DtQmlGampad::addEventCallback |
( |
T * | object, |
|
|
Method | method ) |
|
inline |
Register a callback to receive virtual gamepad input events.
PATTERN: Callback Registration for Custom Input Devices Custom input devices should provide a callback mechanism allowing consumers to receive events without tight coupling. This pattern uses DtDelegate to store member function pointers with type-safe invocation.
The callback signature is: void(std::string eventType, int id, double value)
- eventType: "axis", "button", "hat", etc.
- id: Control identifier (e.g., axis 0, button 1)
- value: Event value (axis deflection, button state)
REUSABLE: This callback pattern can be adapted for any event-driven device interface where multiple consumers need to receive events.
- Template Parameters
-
| T | Type of the object receiving callbacks |
| Method | Member function pointer type |
- Parameters
-
| object | Pointer to the object instance that will receive callbacks |
| method | Member function to invoke when events occur |
References myEventCallbacks.
template<typename T, typename Method>
| void makVre::DtQmlGampad::removeEventCallback |
( |
T * | object, |
|
|
Method | method ) |
|
inline |
Remove a previously registered event callback.
Should be called during cleanup (typically in the input device's shutdown() method) to prevent callbacks to destroyed objects.
- Template Parameters
-
| T | Type of the object that registered the callback |
| Method | Member function pointer type (unused but kept for symmetry) |
- Parameters
-
| object | Pointer to the object whose callback should be removed |
| method | Member function (unused in current implementation) |
References myEventCallbacks.
| virtual Q_INVOKABLE void makVre::DtQmlGampad::qmlEvent |
( |
QString | type, |
|
|
int | id, |
|
|
qreal | value ) |
|
virtual |
QML-invokable method called when virtual gamepad generates input.
PATTERN: QML-to-C++ Event Bridge This method is marked Q_INVOKABLE and registered as a QML context property (named "DtQmlGamepad" in QML), allowing the QML UI to call directly into C++ when user interacts with on-screen controls:
// In QML: onPressed: DtQmlGamepad.qmlEvent("button", buttonId, 1.0)
The Q_INVOKABLE macro makes this method accessible from QML script code. Qt's meta-object system handles type conversions between QML types (QString, qreal) and C++ types automatically.
REUSABLE: This pattern applies to any QML-based custom UI that needs to communicate events to VR-Engage components.
- Parameters
-
| type | Input event type string ("axis", "button", "hat", etc.) |
| id | Control identifier within that type (e.g., button 0, axis 1) |
| value | Event value (button pressed=1.0/released=0.0, axis deflection) |