VR-Engage  2.2
Loading...
Searching...
No Matches
vreStartPage.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file vreStartPage.h
7//! \brief Defines the start page UI component for VR-Engage
8//!
9//! This file contains the DtVreStartPage class and supporting classes which
10//! provide the UI for the application's start menu. It includes functionality
11//! for listing and selecting scenarios, displaying scenario information, and
12//! initiating session hosting or joining. The UI dynamically updates as new
13//! scenarios are added to the scenario directory.
14#pragma once
15
18
19#include <QObject>
20#include <QScopedPointer>
21#include <QAbstractListModel>
22
23class QQuickItem;
24
25namespace makVre
26{
27//! \brief Forward declaration of the player station application class
29
30//! \brief Class representing a file entry in the file selection models
31//!
32//! DtFileEntry encapsulates information about a single file in the
33//! file selection lists, storing both the display name and the full path.
34//! This is used for scenarios and terrain files displayed in the start page.
36{
37public:
38 //! \brief Default constructor
39 //!
40 //! Creates an empty file entry with blank name and path.
42
43 //! \brief Constructor with name and path
44 //! \param fileName Display name of the file
45 //! \param filePath Full path to the file
46 //!
47 //! Creates a file entry with the specified name and path.
48 DtFileEntry(const QString& fileName, const QString& filePath);
49
50 //! \brief Gets the display name of the file
51 //! \return File name as a QString
52 //!
53 //! Returns the display name of this file entry.
54 QString getFileName() const;
55
56 //! \brief Sets the display name of the file
57 //! \param name New file name
58 //!
59 //! Updates the display name of this file entry.
60 void setFileName(const QString& name);
61
62 //! \brief Gets the full path to the file
63 //! \return File path as a QString
64 //!
65 //! Returns the full path to this file entry.
66 QString getFilePath() const;
67
68 //! \brief Sets the full path to the file
69 //! \param name New file path
70 //!
71 //! Updates the full path to this file entry.
72 void setFilePath(const QString& name);
73
74protected:
75 //! \brief Display name of the file
76 QString myFileName;
77
78 //! \brief Full path to the file
79 QString myFilePath;
80};
81
82//! \brief Model for displaying files in a list view
83//!
84//! DtRecursiveFileModel is a Qt model class that provides a list of files
85//! to QML list views. It manages a collection of file entries and exposes
86//! them through the Qt model-view framework, making them accessible to the UI.
87class PLAYERSTATION_DLL DtRecursiveFileModel : public QAbstractListModel
88{
89 Q_OBJECT;
90
91public:
92 //! \brief Enumeration of data roles for the model
93 //!
94 //! Defines the custom roles used to access different aspects of the file entries.
96 {
97 FileNameRole = Qt::UserRole + 1, //!< Role for accessing the file name
98 FilePathRole //!< Role for accessing the file path
99 };
100
101 //! \brief Constructor
102 //! \param parent Optional parent QObject for memory management
103 //!
104 //! Creates a new empty file model.
105 DtRecursiveFileModel(QObject* parent = 0);
106
107 //! \brief Adds a file entry to the model
108 //! \param entry File entry to add
109 //!
110 //! Adds a new file entry to the end of the model's file list.
111 virtual void addFile(const DtFileEntry& entry);
112
113 //! \brief Clears all file entries from the model
114 //!
115 //! Removes all file entries from the model, leaving it empty.
116 virtual void clear();
117
118 //! \brief Sorts the file entries
119 //! \param column Column index to sort by (ignored in this implementation)
120 //! \param order Sort order (ascending or descending)
121 //!
122 //! Sorts the file entries case-insensitively using QCollator.
123 //! This ensures proper alphabetical sorting regardless of locale.
124 virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
125
126 //! \brief Removes rows from the model
127 //! \param row Starting row index
128 //! \param column Number of columns to remove (ignored in this implementation)
129 //! \param parent Parent model index (ignored in this implementation)
130 //! \return True if rows were successfully removed
131 //!
132 //! Implementation of QAbstractItemModel::removeRows for removing file entries.
133 virtual bool removeRows(int row, int column = 0, const QModelIndex& parent = QModelIndex()) override;
134
135 //! \brief Gets the number of rows in the model
136 //! \param parent Parent model index (ignored in this implementation)
137 //! \return Number of file entries in the model
138 //!
139 //! Implementation of QAbstractItemModel::rowCount that returns the number of file entries.
140 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
141
142 //! \brief Gets data for a specific index and role
143 //! \param index Model index to get data for
144 //! \param role Data role to retrieve
145 //! \return Requested data as a QVariant
146 //!
147 //! Implementation of QAbstractItemModel::data that provides access to file entry data.
148 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
149
150 //! \brief Sets data for a specific index and role
151 //! \param index Model index to set data for
152 //! \param value New value to set
153 //! \param role Data role to set
154 //! \return True if data was successfully set
155 //!
156 //! Implementation of QAbstractItemModel::setData for updating file entry data.
157 virtual bool setData(const QModelIndex& index, const QVariant& value, int role) override;
158
159protected:
160 //! \brief Gets the mapping from role IDs to role names
161 //! \return Hash mapping role IDs to their name strings
162 //!
163 //! Implementation of QAbstractItemModel::roleNames that provides the mapping
164 //! from role enum values to the string names used in QML.
165 virtual QHash<int, QByteArray> roleNames() const override;
166
167 //! \brief List of file entries in the model
168 //!
169 //! Storage for all the file entries managed by this model.
170 QList<DtFileEntry> myFiles;
171};
172
173//! \brief QML interface for the start page
174//!
175//! DtVreStartPageQml provides the interface between the C++ backend
176//! and the QML frontend of the start page. It manages the selection state,
177//! scenario descriptions, SMS information, and button actions, exposing these
178//! to QML for the user interface.
180{
181 Q_OBJECT;
182
183 //! \brief Current button action state
184 //!
185 //! QML property that exposes the current button action state (HOST, UNHOST, NONE).
186 //! This determines which actions are available in the UI.
188
189 //! \brief Scenario description
190 //!
191 //! QML property that exposes the description text for the selected scenario.
192 Q_PROPERTY(QString description READ getDescription WRITE setDescription NOTIFY descriptionChanged);
193
194 //! \brief SMS configuration information
195 //!
196 //! QML property that exposes the SMS (System Management Status) information.
197 Q_PROPERTY(QString sms READ getSMS WRITE setSMS NOTIFY smsChanged);
198
199 //! \brief Currently selected file
200 //!
201 //! QML property that exposes the path of the currently selected file.
202 Q_PROPERTY(QString selectedFile READ getSelectedFile WRITE setSelectedFile NOTIFY fileSelected);
203
204public:
205 //! \brief Constructor
206 //! \param parent Optional parent QObject for memory management
207 //!
208 //! Creates a new QML interface for the start page.
209 explicit DtVreStartPageQml(QObject* parent = nullptr);
210
211 //! \brief Destructor
212 //!
213 //! Cleans up resources used by the QML interface.
214 virtual ~DtVreStartPageQml() override;
215
216 //! \brief Updates the description information from the selected file
217 //!
218 //! Loads and sets the description text based on the currently selected file.
219 //! This is called automatically when a new file is selected.
221
222public:
223 //! \brief Enumeration of possible button actions
224 //!
225 //! Defines the possible states for the main action button in the UI.
227 {
228 HOST, //!< Host a new session with the selected scenario
229 UNHOST, //!< Stop hosting the current session
230 NONE //!< No action available
231 };
233
234 //! \brief Gets the current button action state
235 //! \return Current button action state
236 //!
237 //! Returns the current button action state for the UI.
239
240 //! \brief Gets the currently selected file
241 //! \return Path to the selected file
242 //!
243 //! Returns the path to the currently selected file.
244 virtual QString getSelectedFile() const;
245
246 //! \brief Gets the current description text
247 //! \return Description text
248 //!
249 //! Returns the description text for the selected scenario.
250 virtual QString getDescription() const;
251
252 //! \brief Gets the current SMS information
253 //! \return SMS information text
254 //!
255 //! Returns the SMS (System Management Status) information.
256 virtual QString getSMS() const;
257
258 //! \brief Starts a new session as host
259 //!
260 //! QML-invokable method that initiates a new session using the selected scenario,
261 //! with this instance as the host. Emits the sessionStarted signal.
262 Q_INVOKABLE virtual void startSession();
263
264 //! \brief Joins an existing session
265 //!
266 //! QML-invokable method that joins an existing session using the current settings.
267 //! Emits the sessionJoined signal.
268 Q_INVOKABLE virtual void joinSession();
269
270 //! \brief Resets properties to their default values
271 //!
272 //! QML-invokable method that resets all property values to their defaults.
273 //! Emits the propertiesChanged signal.
274 Q_INVOKABLE virtual void resetProperties();
275
276public slots:
277 //! \brief Sets the button action state
278 //! \param ba New button action state
279 //!
280 //! Updates the button action state and emits the buttonClicked signal.
282
283 //! \brief Sets the selected file
284 //! \param file Path to the newly selected file
285 //!
286 //! Updates the selected file and emits the fileSelected signal.
287 //! Also triggers a description update.
288 virtual void setSelectedFile(QString file);
289
290 //! \brief Sets the description text
291 //! \param description New description text
292 //!
293 //! Updates the description text and emits the descriptionChanged signal.
294 virtual void setDescription(QString description);
295
296 //! \brief Sets the SMS information
297 //! \param sms New SMS information text
298 //!
299 //! Updates the SMS information and emits the smsChanged signal.
300 virtual void setSMS(QString sms);
301
302signals:
303 //! \brief Signal emitted when the button action changes
304 //! \param btnAction New button action state
306
307 //! \brief Signal emitted when a file is selected
308 //! \param file Path to the selected file
309 void fileSelected(QString file);
310
311 //! \brief Signal emitted when the description changes
312 //! \param description New description text
314
315 //! \brief Signal emitted when the SMS information changes
316 //! \param sms New SMS information text
317 void smsChanged(QString sms);
318
319 //! \brief Signal emitted when a session is started
321
322 //! \brief Signal emitted when a session is joined
324
325 //! \brief Signal emitted when properties are reset
327
328protected:
329 //! \brief Path to the selected file
331
332 //! \brief Current button action state
334
335 //! \brief Current description text
337
338 //! \brief Current SMS information text
339 QString mySms;
340
341 //! \brief Pointer to the player station application
342 //!
343 //! Provides access to application services and state. Not owned
344 //! by this class, simply a convenience pointer.
346};
347
348//! \brief Start page UI component for VR-Engage
349//!
350//! DtVreStartPage provides the main start page UI for VR-Engage, which includes
351//! scenario selection, scenario information display, and session control.
352//! It manages the models for scenarios and terrain files, and coordinates
353//! the interaction between the UI and the application backend.
355{
356 Q_OBJECT;
357
358public:
359 //! \brief Constructor
360 //! \param app Reference to the player station application
361 //! \param target_window Name of the window to display in (empty for default)
362 //!
363 //! Creates a new start page UI for the specified application and target window.
364 DtVreStartPage(DtPlayerStationApp& app, const std::string& target_window = "");
365
366 //! \brief Destructor
367 //!
368 //! Cleans up resources used by the start page.
369 virtual ~DtVreStartPage() override;
370
371 //! \brief Updates the start page each frame
372 //! \param dt Time in seconds since the last update
373 //!
374 //! Called once per frame to update the start page UI elements.
375 virtual void tick(double dt) override;
376
377 //! \brief Initializes the main content of the page
378 //!
379 //! Sets up the main content area of the page, including the file models
380 //! and QML components. Called during initialization.
381 virtual void initMain() override;
382
383 //! \brief Controls the background video playback
384 //! \param visible True to play the video, false to pause it
385 //!
386 //! Controls whether the background video is playing or paused.
387 virtual void setVideoPlaying(bool visible);
388
389 //! \brief Sets the visibility of the start page
390 //! \param visible True to show the page, false to hide it
391 //!
392 //! Controls whether the start page is visible. This override adds
393 //! additional page-specific handling when visibility changes.
394 virtual void setVisibility(bool visible) override;
395
396 //! \brief Sets the visibility of the menu part of the page
397 //! \param visible True to show the menu, false to hide it
398 //!
399 //! Controls whether the menu portion of the start page is visible.
400 //! This allows showing/hiding just the menu while keeping the rest
401 //! of the page visible.
402 virtual void setMenuVisibility(bool visible);
403
404 //! \brief Gets the QML interface singleton
405 //! \return Pointer to the QML interface singleton
406 //!
407 //! Returns a pointer to the QML interface singleton used by this page.
409
410protected:
411 //! \brief Handles application mode changes
412 //! \param newAppMode Identifier of the new application mode
413 //! \param oldAppMode Identifier of the previous application mode
414 //!
415 //! Updates the page when the application mode changes, ensuring the UI
416 //! reflects the current mode appropriately.
417 virtual void appModeUpdated(const std::string& newAppMode, const std::string& oldAppMode) override;
418
419protected:
420 //! \brief QML interface singleton
421 //!
422 //! Managed pointer to the QML interface singleton for this page.
423 QScopedPointer<DtVreStartPageQml> myQmlSingleton;
424
425 //! \brief Model containing available scenarios
426 //!
427 //! File model for the list of available scenarios.
429
430 //! \brief Model containing available terrain files
431 //!
432 //! File model for the list of available terrain files.
434};
435
436} // namespace makVre
Class representing a file entry in the file selection models.
Definition vreStartPage.h:36
QString getFilePath() const
Gets the full path to the file.
QString myFileName
Display name of the file.
Definition vreStartPage.h:76
QString myFilePath
Full path to the file.
Definition vreStartPage.h:79
QString getFileName() const
Gets the display name of the file.
DtFileEntry()
Default constructor.
DtFileEntry(const QString &fileName, const QString &filePath)
Constructor with name and path.
void setFilePath(const QString &name)
Sets the full path to the file.
void setFileName(const QString &name)
Sets the display name of the file.
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:163
Model for displaying files in a list view.
Definition vreStartPage.h:88
FileModelRoles
Enumeration of data roles for the model.
Definition vreStartPage.h:96
@ FileNameRole
Role for accessing the file name.
Definition vreStartPage.h:97
@ FilePathRole
Role for accessing the file path.
Definition vreStartPage.h:98
virtual void clear()
Clears all file entries from the model.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Gets data for a specific index and role.
virtual void addFile(const DtFileEntry &entry)
Adds a file entry to the model.
QList< DtFileEntry > myFiles
List of file entries in the model.
Definition vreStartPage.h:170
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets data for a specific index and role.
virtual void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Sorts the file entries.
virtual QHash< int, QByteArray > roleNames() const override
Gets the mapping from role IDs to role names.
virtual bool removeRows(int row, int column=0, const QModelIndex &parent=QModelIndex()) override
Removes rows from the model.
DtRecursiveFileModel(QObject *parent=0)
Constructor.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Gets the number of rows in the model.
virtual void initMain() override
Initializes the main content of the page.
virtual void setMenuVisibility(bool visible)
Sets the visibility of the menu part of the page.
DtVreStartPage(DtPlayerStationApp &app, const std::string &target_window="")
Constructor.
virtual void appModeUpdated(const std::string &newAppMode, const std::string &oldAppMode) override
Handles application mode changes.
DtRecursiveFileModel myTerrainsModel
Model containing available terrain files.
Definition vreStartPage.h:433
virtual DtVreStartPageQml * getSingleton() const
Gets the QML interface singleton.
virtual void tick(double dt) override
Updates the start page each frame.
QScopedPointer< DtVreStartPageQml > myQmlSingleton
QML interface singleton.
Definition vreStartPage.h:423
DtRecursiveFileModel myScenariosModel
Model containing available scenarios.
Definition vreStartPage.h:428
virtual void setVisibility(bool visible) override
Sets the visibility of the start page.
virtual ~DtVreStartPage() override
Destructor.
virtual void setVideoPlaying(bool visible)
Controls the background video playback.
QML interface for the start page.
Definition vreStartPage.h:180
void sessionStarted()
Signal emitted when a session is started.
virtual Q_INVOKABLE void resetProperties()
Resets properties to their default values.
virtual Q_INVOKABLE void startSession()
Starts a new session as host.
virtual ButtonAction getButtonAction() const
Gets the current button action state.
QString sms
SMS configuration information.
Definition vreStartPage.h:197
DtVreStartPageQml(QObject *parent=nullptr)
Constructor.
virtual void setButtonAction(ButtonAction ba)
Sets the button action state.
DtPlayerStationApp * myApp
Pointer to the player station application.
Definition vreStartPage.h:345
ButtonAction myButtonAction
Current button action state.
Definition vreStartPage.h:333
QString myDescription
Current description text.
Definition vreStartPage.h:336
virtual QString getDescription() const
Gets the current description text.
void setDescriptionInformation()
Updates the description information from the selected file.
void fileSelected(QString file)
Signal emitted when a file is selected.
void propertiesChanged()
Signal emitted when properties are reset.
virtual Q_INVOKABLE void joinSession()
Joins an existing session.
virtual QString getSelectedFile() const
Gets the currently selected file.
virtual void setSelectedFile(QString file)
Sets the selected file.
virtual void setSMS(QString sms)
Sets the SMS information.
ButtonAction
Enumeration of possible button actions.
Definition vreStartPage.h:227
@ UNHOST
Stop hosting the current session.
Definition vreStartPage.h:229
@ NONE
No action available.
Definition vreStartPage.h:230
@ HOST
Host a new session with the selected scenario.
Definition vreStartPage.h:228
QString mySms
Current SMS information text.
Definition vreStartPage.h:339
void sessionJoined()
Signal emitted when a session is joined.
virtual QString getSMS() const
Gets the current SMS information.
void smsChanged(QString sms)
Signal emitted when the SMS information changes.
virtual ~DtVreStartPageQml() override
Destructor.
virtual void setDescription(QString description)
Sets the description text.
QString mySelectedFile
Path to the selected file.
Definition vreStartPage.h:330
QString selectedFile
Currently selected file.
Definition vreStartPage.h:202
QString description
Scenario description.
Definition vreStartPage.h:192
void buttonClicked(ButtonAction btnAction)
Signal emitted when the button action changes.
ButtonAction buttonAction
Current button action state.
Definition vreStartPage.h:187
void descriptionChanged(QString description)
Signal emitted when the description changes.
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
Include export definitions for this library.
Definition glsVreMessageUtil.h:49