VR-Engage  2.3
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//! \vreRoleParam{showInMenus,bool,false,qtQuickOverlay,Show overlay in menus.}
63constexpr const char* showInMenus = "showInMenus";
64
65//! @}
66} // namespace QtQuickOverlayConfig
67
68namespace makVre
69{
70//! \brief Type identifier for DtQtQuickOverlay component
71constexpr const char* DtQtQuickOverlayType = "DtQtQuickOverlay";
72
73//! \brief A component that manages Qt Quick overlays for rendering 2D UI elements on top of 3D graphics
74//!
75//! DtQtQuickOverlay loads and manages QML files as overlays for the 3D scene. It can bind state attributes
76//! to QML properties, control overlay visibility based on player state, and optionally hide the 3D scene when
77//! only the overlay should be visible.
79{
80public:
81 //! \brief Constructor for DtQtQuickOverlay
83
84 //! \brief Alternative constructor with target window parameter (commented out)
85 //! \param target_window The target window to display the overlay on
86 // DtQtQuickOverlay(const std::string& target_window = "" );
87
88 //! \brief Destructor that cleans up message handlers and attribute callbacks
89 virtual ~DtQtQuickOverlay() override;
90
91 //! \brief Initializes the overlay component with configuration options
92 //! \param player Pointer to the player station this component belongs to
93 //! \param config Configuration table containing overlay settings
94 //! \return True if initialization succeeded, false otherwise
95 //!
96 //! Required configuration parameters:
97 //! - qmlFilename: Path to the QML file to load
98 //! - qmlDataItemObjectName: Name of the QML object to bind data to
99 //! - qmlDataItemBindings: Table of bindings from state attributes to QML properties
100 //!
101 //! Optional configuration parameters:
102 //! - qmlTargetWindow: Window to display the overlay on
103 //! - visibilityAttribute: Attribute name to control visibility
104 //! - renderOverlayOnly: If true, hides the 3D scene when the overlay is visible
106
107 //! \brief Performs post-initialization steps after all components are initialized
108 //! \return True if post-initialization succeeded, false otherwise
109 //!
110 //! Builds connections between state attributes and QML properties,
111 //! then loads the QML file using the appropriate renderer method based on VR status
112 virtual bool postInitialize() override;
113
114 //! \brief Called every frame to update the overlay
115 //! \param dt Delta time since the last frame in seconds
116 //!
117 //! Updates QML property values from state attributes and handles scene visibility
118 virtual void tick(double dt) override;
119
120 //! \brief Shuts down the overlay component
121 //!
122 //! Closes the UI, restores 3D scene visibility if needed, and disconnects property bindings
123 virtual void shutdown() override;
124
125 //! \brief Returns the type identifier for this component
126 //! \return The type string for DtQtQuickOverlay
127 virtual const char* type() const override;
128
129 //! \brief Sets the root QQuickItem for this overlay
130 //! \param root Pointer to the root QQuickItem
131 virtual void setRoot(QQuickItem* root) { myRoot = root; }
132
133 //! \brief Initialize document with the root QQuickItem
134 //! \param root Pointer to the root QQuickItem
135 //!
136 //! Stores the root item and sets initial visibility based on the visibility attribute
137 virtual void initdoc(QQuickItem* root);
138
139 //! \brief Handles messages for entering player states
140 //! \param msg The message containing the state transition information
141 //! \return Message handling result indicating if the message was handled
142 //!
143 //! Special handling for MENU_STATE and ENGAGED states to control overlay visibility
144 //! and scene visibility when renderOverlayOnly is true
146
147 //! \brief Handles messages for exiting player states
148 //! \param msg The message containing the state transition information
149 //! \return Message handling result indicating if the message was handled
150 //!
151 //! Special handling for MENU_STATE to restore previous overlay visibility
152 //! and control scene visibility when renderOverlayOnly is true
154
155 //! \brief Sets the visibility of the overlay
156 //! \param visible True to show the overlay, false to hide it
157 //!
158 //! Sets the "visible" property on the root QML item
159 virtual void setVisibility(bool visible);
160
161 //! \brief Checks if the overlay is currently visible
162 //! \return True if the overlay is visible, false otherwise
163 //!
164 //! Reads the "visible" property from the root QML item
165 virtual bool isVisible();
166
167 //! \brief Updates the menu state and toggles visibility accordingly
168 //! \param on True if entering menu state, false if exiting
169 //!
170 //! When entering menu state, caches and hides the overlay
171 //! When exiting menu state, restores the previous visibility
172 virtual void setMenuState(bool on);
173
174protected:
175 //! \brief Updates QML property values from state attributes
176 //! \param dt Delta time since the last frame in seconds
177 //!
178 //! Finds the QML value source object and updates properties based on
179 //! current state attribute values, then calls the tick method on the source
180 virtual void updateVals(double dt);
181
182 //! \brief Disconnects all property bindings
183 //!
184 //! Clears the connections list to remove all bindings
185 virtual void disconnect();
186
187 //! \brief Builds connections between state attributes and QML properties
188 //! \param connections Configuration table defining the connections
189 //! \return True if connections were successfully built, false otherwise
190 //!
191 //! Each connection maps a state attribute to a QML property
192 virtual bool buildConnections(DtInitTable& connections);
193
194 //! \brief Called when the visibility attribute changes
195 //! \param on New visibility value
196 //!
197 //! Sets the overlay visibility based on the new attribute value
198 virtual void onVisibilityAttributeChanged(bool on);
199
200 //! \brief Removes the model set and sky from the channel
201 //!
202 //! Used when renderOverlayOnly is true to hide the 3D scene
203 //! and only show the overlay
205
206 //! \brief Restores the model set and sky to the channel
207 //!
208 //! Used to restore the 3D scene visibility after it was hidden
210
211protected:
212 //! \brief Configuration table containing QML data item bindings
214
215 //! \brief Pointer to the root QQuickItem for this overlay
216 QQuickItem* myRoot;
217
218 //! \brief Name of the target window to display the overlay on
219 std::string myTargetWindow;
220
221 //! \brief Structure defining a connection between a state attribute and QML property
223 {
224 //! \brief Name of the QML property to bind to
225 std::string myQmlProperty;
226
227 //! \brief Handle to the state attribute to bind from
229 };
230
231 //! \brief List of connections between state attributes and QML properties
232 std::vector<Connection> myConnections;
233
234 //! \brief Path to the QML file to load
235 std::string myQmlFile;
236
237 //! \brief Name of the QML object to bind data to
238 std::string myQmlDataItemName;
239
240 //! \brief Flag indicating if the PlayerStation is in the "MENU_STATE"
241 //! Used to determine whether the overlays should be visible
243
244 //! \brief Cached visibility value to restore when exiting menu state
246
247 //! \brief Handle to attribute that controls overlay visibility
249
250 //! \brief Flag indicating if only the overlay should be rendered without the 3D scene
252
253 //! \brief Flag indicating if the 3D scene should be hidden
255
256 //! \brief Pointer to the OSG channel used for rendering
257 makVrv::DtOsgChannel* myChannel;
258
259 //! \brief Pointer to the observer object for the channel
260 makVrv::DtObserverObject* myObserver;
261
262 //! \brief QObject used as the owner for the QML UI
263 QObject myQObject;
264
265 //! \brief Flag indicating whether the QML data item has a tick(double) function
267
268 //! \brief Flag indicating whether the overlay should be shown in menus
269 bool myShowInMenus = false;
270};
271} // 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:229
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:131
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:219
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:242
makVrv::DtOsgChannel * myChannel
Pointer to the OSG channel used for rendering.
Definition qtQuickOverlay.h:257
makVrv::DtObserverObject * myObserver
Pointer to the observer object for the channel.
Definition qtQuickOverlay.h:260
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:245
bool myShowInMenus
Flag indicating whether the overlay should be shown in menus.
Definition qtQuickOverlay.h:269
virtual void initdoc(QQuickItem *root)
Initialize document with the root QQuickItem.
std::string myQmlFile
Path to the QML file to load.
Definition qtQuickOverlay.h:235
DtInitTable myBindQmlPropertyToAttribute
Configuration table containing QML data item bindings.
Definition qtQuickOverlay.h:213
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:232
bool myWantSceneHidden
Flag indicating if the 3D scene should be hidden.
Definition qtQuickOverlay.h:254
QObject myQObject
QObject used as the owner for the QML UI.
Definition qtQuickOverlay.h:263
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:216
bool myHasTickFunction
Flag indicating whether the QML data item has a tick(double) function.
Definition qtQuickOverlay.h:266
virtual void shutdown() override
Shuts down the overlay component.
DtAttributeHandleType< bool > myVisibilityAttribute
Handle to attribute that controls overlay visibility.
Definition qtQuickOverlay.h:248
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:238
bool myRenderOverlayOnly
Flag indicating if only the overlay should be rendered without the 3D scene.
Definition qtQuickOverlay.h:251
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 * showInMenus
Definition qtQuickOverlay.h:63
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
!
Definition glsVreMessageUtil.h:50
constexpr const char * DtQtQuickOverlayType
Type identifier for DtQtQuickOverlay component.
Definition qtQuickOverlay.h:71
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:223
DtAttributeHandle myStateAttribute
Handle to the state attribute to bind from.
Definition qtQuickOverlay.h:228
std::string myQmlProperty
Name of the QML property to bind to.
Definition qtQuickOverlay.h:225
Defines the base class for all VREngage messages.