VR-Engage  2.2
Loading...
Searching...
No Matches
qtQuickOverlay.h
Go to the documentation of this file.
1
2/*******************************************************************************
3** Copyright (c) 2025 MAK Technologies
4** All rights reserved.
5*******************************************************************************/
6
7//! \file qtQuickOverlay.h
8//! \brief Contains DtQtQuickOverlay class which provides a Qt Quick overlay component for rendering 2D UI over 3D
9//! graphics
10//! \ingroup vreCommonComponents
11
12
13#pragma once
14
16
18
20
21#include "vreUtil/attribute.h"
22
23#include <string>
24#include <vector>
25
26#include <QObject>
27
28class QQuickItem;
29
30namespace makVrv
31{
32class DtOsgChannel;
33class DtObserverObject;
34} // namespace makVrv
35
37{
38//! \ingroup RoleConfigParams
39//! \defgroup QtQuickOverlayRoleParams Qt Quick Overlay Role Parameters
40//! \roleInherits{PlayerComponentRoleParams}
41//! Configuration Options for qt quick overlay role.
42//! @{
43
44//! \vreRoleParamRequired{bindQmlPropertyToAttribute,DtInitTable,qtQuickOverlay,"Table",Table of bindings from state attributes to QML properties.}
45constexpr const char* bindQmlPropertyToAttribute = "bindQmlPropertyToAttribute";
46
47//! \vreRoleParamRequired{qmlDataItemObjectName,string,qtQuickOverlay,"dataItem",Name of the QML object to bind data to.}
48constexpr const char* qmlDataItemObjectName = "qmlDataItemObjectName";
49
50//! \vreRoleParamRequired{qmlFilename,string,qtQuickOverlay,"overlay.qml",Path to the QML file to load.}
51constexpr const char* qmlFilename = "qmlFilename";
52
53//! \vreRoleParam{qmlTargetWindow,string,"",qtQuickOverlay,Window to display the overlay on.}
54constexpr const char* qmlTargetWindow = "qmlTargetWindow";
55
56//! \vreRoleParam{renderOverlayOnly,bool,false,qtQuickOverlay,If true hides the 3D scene when the overlay is visible.}
57constexpr const char* renderOverlayOnly = "renderOverlayOnly";
58
59//! \vreRoleParam{visibilityAttribute,string,"",qtQuickOverlay,Attribute name to control overlay visibility.}
60constexpr const char* visibilityAttribute = "visibilityAttribute";
61
62//! @}
63} // namespace QtQuickOverlayConfig
64
65namespace makVre
66{
67//! \brief Type identifier for DtQtQuickOverlay component
68constexpr const char* DtQtQuickOverlayType = "DtQtQuickOverlay";
69
70//! \brief A component that manages Qt Quick overlays for rendering 2D UI elements on top of 3D graphics
71//!
72//! DtQtQuickOverlay loads and manages QML files as overlays for the 3D scene. It can bind state attributes
73//! to QML properties, control overlay visibility based on player state, and optionally hide the 3D scene when
74//! only the overlay should be visible.
76{
77public:
78 //! \brief Constructor for DtQtQuickOverlay
80
81 //! \brief Alternative constructor with target window parameter (commented out)
82 //! \param target_window The target window to display the overlay on
83 // DtQtQuickOverlay(const std::string& target_window = "" );
84
85 //! \brief Destructor that cleans up message handlers and attribute callbacks
86 virtual ~DtQtQuickOverlay() override;
87
88 //! \brief Initializes the overlay component with configuration options
89 //! \param player Pointer to the player station this component belongs to
90 //! \param config Configuration table containing overlay settings
91 //! \return True if initialization succeeded, false otherwise
92 //!
93 //! Required configuration parameters:
94 //! - qmlFilename: Path to the QML file to load
95 //! - qmlDataItemObjectName: Name of the QML object to bind data to
96 //! - qmlDataItemBindings: Table of bindings from state attributes to QML properties
97 //!
98 //! Optional configuration parameters:
99 //! - qmlTargetWindow: Window to display the overlay on
100 //! - visibilityAttribute: Attribute name to control visibility
101 //! - renderOverlayOnly: If true, hides the 3D scene when the overlay is visible
103
104 //! \brief Performs post-initialization steps after all components are initialized
105 //! \return True if post-initialization succeeded, false otherwise
106 //!
107 //! Builds connections between state attributes and QML properties,
108 //! then loads the QML file using the appropriate renderer method based on VR status
109 virtual bool postInitialize() override;
110
111 //! \brief Called every frame to update the overlay
112 //! \param dt Delta time since the last frame in seconds
113 //!
114 //! Updates QML property values from state attributes and handles scene visibility
115 virtual void tick(double dt) override;
116
117 //! \brief Shuts down the overlay component
118 //!
119 //! Closes the UI, restores 3D scene visibility if needed, and disconnects property bindings
120 virtual void shutdown() override;
121
122 //! \brief Returns the type identifier for this component
123 //! \return The type string for DtQtQuickOverlay
124 virtual const char* type() const override;
125
126 //! \brief Sets the root QQuickItem for this overlay
127 //! \param root Pointer to the root QQuickItem
128 virtual void setRoot(QQuickItem* root) { myRoot = root; }
129
130 //! \brief Initialize document with the root QQuickItem
131 //! \param root Pointer to the root QQuickItem
132 //!
133 //! Stores the root item and sets initial visibility based on the visibility attribute
134 virtual void initdoc(QQuickItem* root);
135
136 //! \brief Handles messages for entering player states
137 //! \param msg The message containing the state transition information
138 //! \return Message handling result indicating if the message was handled
139 //!
140 //! Special handling for MENU_STATE and ENGAGED states to control overlay visibility
141 //! and scene visibility when renderOverlayOnly is true
143
144 //! \brief Handles messages for exiting player states
145 //! \param msg The message containing the state transition information
146 //! \return Message handling result indicating if the message was handled
147 //!
148 //! Special handling for MENU_STATE to restore previous overlay visibility
149 //! and control scene visibility when renderOverlayOnly is true
151
152 //! \brief Sets the visibility of the overlay
153 //! \param visible True to show the overlay, false to hide it
154 //!
155 //! Sets the "visible" property on the root QML item
156 virtual void setVisibility(bool visible);
157
158 //! \brief Checks if the overlay is currently visible
159 //! \return True if the overlay is visible, false otherwise
160 //!
161 //! Reads the "visible" property from the root QML item
162 virtual bool isVisible();
163
164 //! \brief Updates the menu state and toggles visibility accordingly
165 //! \param on True if entering menu state, false if exiting
166 //!
167 //! When entering menu state, caches and hides the overlay
168 //! When exiting menu state, restores the previous visibility
169 virtual void setMenuState(bool on);
170
171protected:
172 //! \brief Updates QML property values from state attributes
173 //! \param dt Delta time since the last frame in seconds
174 //!
175 //! Finds the QML value source object and updates properties based on
176 //! current state attribute values, then calls the tick method on the source
177 virtual void updateVals(double dt);
178
179 //! \brief Disconnects all property bindings
180 //!
181 //! Clears the connections list to remove all bindings
182 virtual void disconnect();
183
184 //! \brief Builds connections between state attributes and QML properties
185 //! \param connections Configuration table defining the connections
186 //! \return True if connections were successfully built, false otherwise
187 //!
188 //! Each connection maps a state attribute to a QML property
189 virtual bool buildConnections(DtInitTable& connections);
190
191 //! \brief Called when the visibility attribute changes
192 //! \param on New visibility value
193 //!
194 //! Sets the overlay visibility based on the new attribute value
195 virtual void onVisibilityAttributeChanged(bool on);
196
197 //! \brief Removes the model set and sky from the channel
198 //!
199 //! Used when renderOverlayOnly is true to hide the 3D scene
200 //! and only show the overlay
202
203 //! \brief Restores the model set and sky to the channel
204 //!
205 //! Used to restore the 3D scene visibility after it was hidden
207
208protected:
209 //! \brief Configuration table containing QML data item bindings
211
212 //! \brief Pointer to the root QQuickItem for this overlay
213 QQuickItem* myRoot;
214
215 //! \brief Name of the target window to display the overlay on
216 std::string myTargetWindow;
217
218 //! \brief Structure defining a connection between a state attribute and QML property
220 {
221 //! \brief Name of the QML property to bind to
222 std::string myQmlProperty;
223
224 //! \brief Handle to the state attribute to bind from
226 };
227
228 //! \brief List of connections between state attributes and QML properties
229 std::vector<Connection> myConnections;
230
231 //! \brief Path to the QML file to load
232 std::string myQmlFile;
233
234 //! \brief Name of the QML object to bind data to
235 std::string myQmlDataItemName;
236
237 //! \brief Flag indicating if the PlayerStation is in the "MENU_STATE"
238 //! Used to determine whether the overlays should be visible
240
241 //! \brief Cached visibility value to restore when exiting menu state
243
244 //! \brief Handle to attribute that controls overlay visibility
246
247 //! \brief Flag indicating if only the overlay should be rendered without the 3D scene
249
250 //! \brief Flag indicating if the 3D scene should be hidden
252
253 //! \brief Pointer to the OSG channel used for rendering
254 makVrv::DtOsgChannel* myChannel;
255
256 //! \brief Pointer to the observer object for the channel
257 makVrv::DtObserverObject* myObserver;
258
259 //! \brief QObject used as the owner for the QML UI
260 QObject myQObject;
261
262 //! \brief Flag indicating whether the QML data item has a tick(double) function
264};
265} // namespace makVre
Provides attribute handling system for hierarchical data storage and manipulation.
Handle class for safe access to attributes.
Definition attributeHandle.h:30
Type-specific handle class for attributes.
Definition attributeHandle.h:181
Table-based access to Lua state for configuration data.
Definition initializer.h:38
virtual DtPlayerStation & player()
Gets the player station.
DtPlayerComponent()
Constructor.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
virtual bool postInitialize() override
Performs post-initialization steps after all components are initialized.
virtual void disconnect()
Disconnects all property bindings.
virtual void restoreModelSetAndSkyToChannel()
Restores the model set and sky to the channel.
virtual bool isVisible()
Checks if the overlay is currently visible.
virtual void setVisibility(bool visible)
Sets the visibility of the overlay.
virtual void setRoot(QQuickItem *root)
Sets the root QQuickItem for this overlay.
Definition qtQuickOverlay.h:128
virtual void onVisibilityAttributeChanged(bool on)
Called when the visibility attribute changes.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the overlay component with configuration options.
std::string myTargetWindow
Name of the target window to display the overlay on.
Definition qtQuickOverlay.h:216
virtual DtVreMessageResult handleExitPlayerState(DtVreMessage *msg)
Handles messages for exiting player states.
virtual ~DtQtQuickOverlay() override
Alternative constructor with target window parameter (commented out)
virtual const char * type() const override
Returns the type identifier for this component.
bool myIsInMenuState
Flag indicating if the PlayerStation is in the "MENU_STATE" Used to determine whether the overlays sh...
Definition qtQuickOverlay.h:239
makVrv::DtOsgChannel * myChannel
Pointer to the OSG channel used for rendering.
Definition qtQuickOverlay.h:254
makVrv::DtObserverObject * myObserver
Pointer to the observer object for the channel.
Definition qtQuickOverlay.h:257
virtual void removeModelSetAndSkyFromChannel()
Removes the model set and sky from the channel.
bool myCachedVisibility
Cached visibility value to restore when exiting menu state.
Definition qtQuickOverlay.h:242
virtual void initdoc(QQuickItem *root)
Initialize document with the root QQuickItem.
std::string myQmlFile
Path to the QML file to load.
Definition qtQuickOverlay.h:232
DtInitTable myBindQmlPropertyToAttribute
Configuration table containing QML data item bindings.
Definition qtQuickOverlay.h:210
virtual bool buildConnections(DtInitTable &connections)
Builds connections between state attributes and QML properties.
std::vector< Connection > myConnections
List of connections between state attributes and QML properties.
Definition qtQuickOverlay.h:229
bool myWantSceneHidden
Flag indicating if the 3D scene should be hidden.
Definition qtQuickOverlay.h:251
QObject myQObject
QObject used as the owner for the QML UI.
Definition qtQuickOverlay.h:260
virtual void setMenuState(bool on)
Updates the menu state and toggles visibility accordingly.
DtQtQuickOverlay()
Constructor for DtQtQuickOverlay.
virtual DtVreMessageResult handleEnterPlayerState(DtVreMessage *msg)
Handles messages for entering player states.
QQuickItem * myRoot
Pointer to the root QQuickItem for this overlay.
Definition qtQuickOverlay.h:213
bool myHasTickFunction
Flag indicating whether the QML data item has a tick(double) function.
Definition qtQuickOverlay.h:263
virtual void shutdown() override
Shuts down the overlay component.
DtAttributeHandleType< bool > myVisibilityAttribute
Handle to attribute that controls overlay visibility.
Definition qtQuickOverlay.h:245
virtual void tick(double dt) override
Called every frame to update the overlay.
std::string myQmlDataItemName
Name of the QML object to bind data to.
Definition qtQuickOverlay.h:235
bool myRenderOverlayOnly
Flag indicating if only the overlay should be rendered without the 3D scene.
Definition qtQuickOverlay.h:248
virtual void updateVals(double dt)
Updates QML property values from state attributes.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
constexpr const char * qmlFilename
Definition qtQuickOverlay.h:51
constexpr const char * visibilityAttribute
Definition qtQuickOverlay.h:60
constexpr const char * renderOverlayOnly
Definition qtQuickOverlay.h:57
constexpr const char * bindQmlPropertyToAttribute
Definition qtQuickOverlay.h:45
constexpr const char * qmlTargetWindow
Definition qtQuickOverlay.h:54
constexpr const char * qmlDataItemObjectName
Definition qtQuickOverlay.h:48
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition qtQuickOverlay.h:37
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtQtQuickOverlayType
Type identifier for DtQtQuickOverlay component.
Definition qtQuickOverlay.h:68
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Defines the DtPlayerComponent base class for VR-Engage role components.
Structure defining a connection between a state attribute and QML property.
Definition qtQuickOverlay.h:220
DtAttributeHandle myStateAttribute
Handle to the state attribute to bind from.
Definition qtQuickOverlay.h:225
std::string myQmlProperty
Name of the QML property to bind to.
Definition qtQuickOverlay.h:222
Defines the base class for all VREngage messages.