VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtQmlGampad Class Reference

Detailed Description

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.

#include <qmlGamepad.h>

Inheritance diagram for makVre::DtQmlGampad:
[legend]

Public Member Functions

 DtQmlGampad ()
 
virtual ~DtQmlGampad ()
 
template<typename T, typename Method>
void addEventCallback (T *object, Method method)
 
template<typename T, typename Method>
void removeEventCallback (T *object, Method method)
 
virtual Q_INVOKABLE void qmlEvent (QString type, int id, qreal value)
 
virtual void show ()
 
virtual void hide ()
 

Protected Types

using EventCallback = DtDelegate<void, std::string, int, double>
 

Protected Member Functions

virtual makVre::DtVreMessageResult handleAppStateMessage (makVre::DtVreMessage *msg)
 
virtual bool isVisible ()
 
virtual void setVisibility (bool visible)
 

Protected Attributes

QQuickItem * myRoot
 
std::string myTargetWindow
 
std::string myTargetFile
 
std::map< void *, EventCallbackmyEventCallbacks
 

Member Typedef Documentation

◆ EventCallback

using makVre::DtQmlGampad::EventCallback = DtDelegate<void, std::string, int, double>
protected

Callback delegate type for input events.

Constructor & Destructor Documentation

◆ DtQmlGampad()

makVre::DtQmlGampad::DtQmlGampad ( )

◆ ~DtQmlGampad()

virtual makVre::DtQmlGampad::~DtQmlGampad ( )
virtual

Member Function Documentation

◆ addEventCallback()

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
TType of the object receiving callbacks
MethodMember function pointer type
Parameters
objectPointer to the object instance that will receive callbacks
methodMember function to invoke when events occur

References myEventCallbacks.

◆ removeEventCallback()

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
TType of the object that registered the callback
MethodMember function pointer type (unused but kept for symmetry)
Parameters
objectPointer to the object whose callback should be removed
methodMember function (unused in current implementation)

References myEventCallbacks.

◆ qmlEvent()

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
typeInput event type string ("axis", "button", "hat", etc.)
idControl identifier within that type (e.g., button 0, axis 1)
valueEvent value (button pressed=1.0/released=0.0, axis deflection)

◆ show()

virtual void makVre::DtQmlGampad::show ( )
virtual

Show the virtual gamepad UI.

Typically called when entering engaged/gameplay state. The QML page becomes visible and interactive.

◆ hide()

virtual void makVre::DtQmlGampad::hide ( )
virtual

Hide the virtual gamepad UI.

Typically called when leaving engaged state (returning to menus, disconnecting). The QML page is hidden but remains loaded for quick re-display.

◆ handleAppStateMessage()

virtual makVre::DtVreMessageResult makVre::DtQmlGampad::handleAppStateMessage ( makVre::DtVreMessage * msg)
protectedvirtual

Message handler to automatically show/hide gamepad based on app state.

PATTERN: UI Visibility Driven by Application State VR-Engage applications progress through states: Disconnected → Connecting → RoleSelection → Engaged. Custom UI should typically only be visible during the ENGAGED_STATE when the player is actively controlling an entity.

This handler listens for state change messages and automatically shows/hides the gamepad appropriately. This is preferable to manually tracking state in multiple places.

Parameters
msgState change message from DtPlayerStationStateManager
Returns
HANDLED to indicate message was processed

◆ isVisible()

virtual bool makVre::DtQmlGampad::isVisible ( )
protectedvirtual

Check if QML gamepad UI is currently visible.

Returns
true if visible, false if hidden or not loaded

◆ setVisibility()

virtual void makVre::DtQmlGampad::setVisibility ( bool visible)
protectedvirtual

Set QML gamepad UI visibility state.

Parameters
visibletrue to show, false to hide

Member Data Documentation

◆ myRoot

QQuickItem* makVre::DtQmlGampad::myRoot
protected

Root QML item of the gamepad UI.

◆ myTargetWindow

std::string makVre::DtQmlGampad::myTargetWindow
protected

Window identifier for QML placement.

◆ myTargetFile

std::string makVre::DtQmlGampad::myTargetFile
protected

Path to QML file defining UI.

◆ myEventCallbacks

std::map<void*, EventCallback> makVre::DtQmlGampad::myEventCallbacks
protected

Registered event callbacks keyed by object pointer When input events occur, all registered callbacks are invoked.

Referenced by addEventCallback(), and removeEventCallback().


The documentation for this class was generated from the following file: