VR-Engage  2.3
Loading...
Searching...
No Matches
vreChatQML.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file vreChatQML.h
7//! \brief Defines ChannelInfo and DtVreChatQML, the QML interface for the VR-Engage chat system.
8
9#pragma once
10
13
15
16#include "vreUtil/attribute.h"
17
18#include <QObject>
19
20class QQuickItem;
21
22namespace makVre
23{
25
26//! \brief Structure defining a chat communication channel
27//!
28//! ChannelInfo represents a communication channel in the chat system,
29//! characterized by a name, associated force (friendly, enemy, etc.),
30//! and activation status. This structure is designed to be accessible from QML
31//! through the Q_PROPERTY mechanism, allowing the UI to display and interact
32//! with channel information.
34{
35 Q_GADGET;
36 //! \brief Channel name property exposed to QML
37 Q_PROPERTY(QString channel MEMBER myChannelName);
38
39 //! \brief Force identifier property exposed to QML
40 Q_PROPERTY(int force MEMBER myForce);
41
42 //! \brief Channel activation status property exposed to QML
43 Q_PROPERTY(bool active MEMBER myActive);
44
45 //! \brief List of entities in this channel property exposed to QML
46 Q_PROPERTY(QStringList entities MEMBER myEntities);
47
48public:
49 //! \brief Default constructor
50 ChannelInfo() = default;
51
52 //! \brief Constructor with parameters
53 //! \param ch Channel name
54 //! \param f Force identifier (friendly=1, enemy=2, neutral=3, etc.)
55 //! \param a Activation status (true if channel is currently active)
56 ChannelInfo(QString ch, int f, bool a)
57 : myChannelName(ch)
58 , myForce(f)
59 , myActive(a) {};
60
61 //! \brief Name of the communication channel
63
64 //! \brief Force identifier associated with this channel
65 //! (Typically: 1=friendly, 2=enemy, 3=neutral, etc.)
66 int myForce = 0;
67
68 //! \brief Flag indicating if this channel is currently active
69 bool myActive = false;
70
71 //! \brief List of entities (participants) in this channel
72 QStringList myEntities;
73};
75
76//! \brief QML interface for the VR-Engage chat system
77//!
78//! DtVreChatQML provides the bridge between the C++ chat functionality and
79//! the QML-based UI. It exposes properties and methods that can be accessed
80//! from QML to display chat messages, manage channels, and send/receive
81//! communications. This class handles the business logic of the chat system,
82//! including message formatting, channel management, and command processing.
83class PLAYERSTATION_DLL DtVreChatQML : public QObject
84{
85 // Needed QT Objects
86 Q_OBJECT;
87
88 // Q_PROPERTY that can be set from qml
89 //! \brief Index of the currently active chat channel
91
92 //! \brief Flag indicating if the chat window is pinned (always visible)
93 Q_PROPERTY(bool pinChat MEMBER myPinChat NOTIFY pinChatChanged);
94
95 //! \brief Flag indicating if the full chat window is currently visible
97
98 //! \brief Current username for the chat system
100
101 //! \brief Model containing chat messages for display
102 Q_PROPERTY(DtVreChatModel* chatModel READ getChat WRITE setChat NOTIFY chatChanged)
103
104public: // General Items
105 //! \brief Constructor
106 //! \param app Reference to the player station application
107 //! \param parent Parent QObject (default: nullptr)
108 //!
109 //! Creates a new chat QML interface associated with the specified application.
110 //! The interface will be initialized with default settings and an empty chat model.
111 explicit DtVreChatQML(DtPlayerStationApp& app, QObject* parent = nullptr);
112
113 //! \brief Virtual destructor
114 //!
115 //! Ensures proper cleanup of chat resources.
116 virtual ~DtVreChatQML() override;
117
118 //! \brief Sends a message to the system channel
119 //! \param message Text message to send to the system channel
120 //!
121 //! Sends a text message to the system notification channel, which is
122 //! typically used for system events, errors, and information messages.
123 //! These messages are visible to all users regardless of their channel settings.
124 virtual void sendToSystemChannel(const std::string& message);
125
126 //! \brief Converts plain text to HTML format for QML display
127 //! \param inputText Plain text to convert
128 //! \return HTML-formatted string
129 //!
130 //! Converts a plain text string to HTML format, handling special characters,
131 //! links, and other formatting needed for proper display in QML text components.
132 static std::string convertTextToHTML(const std::string& inputText);
133
134 //! \brief Adds a channel to the available channels list
135 //! \param channelInfo Information about the channel to add
136 //! \param updateAvailableChannels Whether to update the UI after adding the channel
137 //! \return True if channel was added successfully, false otherwise
138 //!
139 //! Adds a new communication channel to the chat system. If a channel with the
140 //! same name and force already exists, it will be updated instead.
141 virtual bool addChannel(const makVre::ChannelInfo& channelInfo, bool updateAvailableChannels = false);
142
143 //! \brief Updates the list of available channels in the UI
144 //!
145 //! Refreshes the available channels list in the QML interface to reflect
146 //! current channel state and availability.
148
149 //! \brief Removes all channels from the chat system
150 //!
151 //! Clears all channels from the chat system, typically used when
152 //! disconnecting from a session or changing scenarios.
153 virtual void clearChannels();
154
155 //! \brief Checks if a channel is currently active
156 //! \param channelName Name of the channel to check
157 //! \param force Force identifier of the channel
158 //! \return True if the channel is active, false otherwise
159 virtual bool isChannelActive(const QString& channelName, int force);
160
161 //! \brief Gets the list of all available channels
162 //! \return Constant reference to the vector of channel information
163 virtual const std::vector<ChannelInfo>& getChannels() const { return myChannels; }
164
165 //! \brief Switches to the first available channel
166 //!
167 //! Selects the first available channel as the active channel.
168 //! Used when initializing the chat or when the current channel becomes unavailable.
170
171 //! \brief Sets whether to use a custom username instead of entity name
172 //! \param usingCustom True to use custom username, false to use entity name
173 //!
174 //! Controls whether the chat system uses a custom username specified by the user
175 //! or automatically generates a username based on the entity information.
176 virtual void setUsingCustomUsername(bool usingCustom) { myUsingCustomUsername = usingCustom; }
177
178 //! \brief Checks if a custom username is being used
179 //! \return True if using custom username, false if using auto-generated name
180 virtual bool isUsingCustomUsername() const { return myUsingCustomUsername; }
181
182 //! \brief Gets the entity marking text for username generation
183 //! \return Current entity marking (call sign) text
184 virtual QString entityMarkingText() const { return myEntityMarkingText; }
185
186 //! \brief Sets the entity marking text for username generation
187 //! \param val New entity marking (call sign) text
188 virtual void setEntityMarkingText(QString val) { myEntityMarkingText = val; }
189
190 //! \brief Gets the entity force identifier for username generation
191 //! \return Current entity force identifier
192 virtual int entityForce() const { return myEntityForce; }
193
194 //! \brief Sets the entity force identifier for username generation
195 //! \param val New entity force identifier
196 virtual void setEntityForce(int val) { myEntityForce = val; }
197
198 //! \brief Gets the entity role text for username generation
199 //! \return Current entity role description
200 QString entityRole() const { return myEntityRole; }
201
202 //! \brief Sets the entity role text for username generation
203 //! \param val New entity role description
204 void setEntityRole(QString val) { myEntityRole = val; }
205
206 //! \brief Updates the username based on current settings
207 //!
208 //! Regenerates the username based on the current settings (custom or auto-generated).
209 //! Auto-generated usernames typically combine entity marking, force, and role.
210 virtual void updateUsername();
211
212 //! \brief Processes a slash command
213 //! \param message Command message starting with a slash (/)
214 //!
215 //! Handles special commands that begin with a slash character, such as
216 //! /help, /clear, /who, etc. This method is called from the send() method
217 //! when a message begins with a slash.
218 virtual void sendSlashCommand(const QString& message);
219
220 //! \brief Sends a regular chat message to a specific channel
221 //! \param message Text message to send
222 //! \param channel Target channel name
223 //! \param force Force identifier for the channel
224 //!
225 //! Sends a chat message to the specified channel. This method is called
226 //! from the send() method for regular (non-command) messages.
227 virtual void sendChatMessage(const QString& message, const QString& channel, const int force);
228
229 //! \brief Processes a channel switching command
230 //! \param channelCommand Command to switch channels (typically channel name)
231 //! \return True if channel switch was successful, false otherwise
232 //!
233 //! Handles commands to switch between communication channels. This can be
234 //! called directly or from a slash command like /channel [name].
235 virtual bool sendChannelCommand(const QString& channelCommand);
236
237public: // Invokable things
238 //! \brief Processes and sends a message or command
239 //! \param message Text message or command to process
240 //!
241 //! Main entry point for processing messages entered by the user. This method
242 //! determines whether the message is a command (starts with slash) or a regular
243 //! message, and routes it to the appropriate handler.
244 //! This method is invokable from QML.
245 Q_INVOKABLE virtual void send(const QString& message);
246
247 //! \brief Cycles through available channels
248 //! \param direction True to cycle forward, false to cycle backward
249 //!
250 //! Switches to the next or previous channel in the channel list based on the
251 //! direction parameter. This method is invokable from QML.
252 Q_INVOKABLE virtual void cycleChannels(bool direction);
253
254 //! \brief Gets information about a specific channel
255 //! \param idx Index of the channel to retrieve information for
256 //! \return QVariant containing the channel information
257 //!
258 //! Retrieves detailed information about a channel at the specified index.
259 //! The returned QVariant can be used in QML to display channel properties.
260 //! This method is invokable from QML.
261 Q_INVOKABLE virtual QVariant getChannelInfo(int idx);
262
263 //! \brief Toggles the pinned state of the chat window
264 //!
265 //! Switches between pinned (always visible) and unpinned (auto-hide) states
266 //! for the chat window. This method is invokable from QML.
267 Q_INVOKABLE virtual void togglePinChat();
268
269 //! \brief Gets whether the full chat window is visible
270 //! \return True if the full chat window is currently visible
271 bool isFullChatVisible() const { return myFullChatVisible; }
272
273 //! \brief Sets the full chat window visibility state
274 //! \param visible True if the full chat window is visible
275 void setFullChatVisible(bool visible);
276
277public:
278 //! \brief Gets the current username
279 //! \return Current username used in chat
280 virtual QString getCurrentUsername();
281
282 //! \brief Gets the chat message model
283 //! \return Pointer to the current chat model
285
286public slots:
287 //! \brief Sets the current username
288 //! \param username New username to use in chat
289 void setCurrentUsername(QString username);
290
291 //! \brief Sets the chat message model
292 //! \param model New chat model to use
294
295signals:
296 //! \brief Signal emitted when the username changes
297 //! \param username New username
298 void currentUsernameChanged(QString username);
299
300 //! \brief Signal emitted when the active channel changes
301 //! \param channelIdx Index of the new active channel
302 void currentChannelIdxChanged(int channelIdx);
303
304 //! \brief Signal emitted when the chat model changes
306
307 //! \brief Signal emitted when the pinned state changes
308 //! \param pinned New pinned state
309 void pinChatChanged(bool pinned);
310
311 //! \brief Signal emitted when the full chat visibility changes
312 //! \param visible New visibility state
313 void fullChatVisibleChanged(bool visible);
314
315protected:
316 // For entities engaged
322
323 // For channels
326 std::vector<ChannelInfo> myChannels;
328
329 // For pinning chat.
331
332 // For tracking full chat visibility.
334
335 // The actual chat model
336 QScopedPointer<DtVreChatModel> myChatModel;
337
338 // reference to the playstationapp
340};
341
342} // namespace makVre
Provides attribute handling system for hierarchical data storage and manipulation.
Top-level class representing the VR-Engage application.
Definition playerStationApp.h:155
Data model for the chat window contents.
Definition vreChatWindowModel.h:128
void setCurrentUsername(QString username)
Sets the current username.
std::vector< ChannelInfo > myChannels
Definition vreChatQML.h:326
void setFullChatVisible(bool visible)
Sets the full chat window visibility state.
QString myEntityRole
Definition vreChatQML.h:320
DtVreChatModel * chatModel
Model containing chat messages for display.
Definition vreChatQML.h:102
virtual Q_INVOKABLE void send(const QString &message)
Processes and sends a message or command.
void setChat(DtVreChatModel *model)
Sets the chat message model.
bool myUsingCustomUsername
Definition vreChatQML.h:318
void currentUsernameChanged(QString username)
Signal emitted when the username changes.
DtFilename myDefaultChatConfigFile
Definition vreChatQML.h:325
virtual void setUsingCustomUsername(bool usingCustom)
Sets whether to use a custom username instead of entity name.
Definition vreChatQML.h:176
QString currentUsername
Current username for the chat system.
Definition vreChatQML.h:99
virtual void sendSlashCommand(const QString &message)
Processes a slash command.
virtual void sendToSystemChannel(const std::string &message)
Sends a message to the system channel.
void setEntityRole(QString val)
Sets the entity role text for username generation.
Definition vreChatQML.h:204
bool myPinChat
Definition vreChatQML.h:330
DtPlayerStationApp & myApp
Definition vreChatQML.h:339
DtVreChatQML(DtPlayerStationApp &app, QObject *parent=nullptr)
Constructor.
virtual Q_INVOKABLE QVariant getChannelInfo(int idx)
Gets information about a specific channel.
int myCurrentChannelIdx
Definition vreChatQML.h:327
virtual void updateUsername()
Updates the username based on current settings.
virtual const std::vector< ChannelInfo > & getChannels() const
Gets the list of all available channels.
Definition vreChatQML.h:163
void chatChanged()
Signal emitted when the chat model changes.
QString entityRole() const
Gets the entity role text for username generation.
Definition vreChatQML.h:200
int myEntityForce
Definition vreChatQML.h:321
virtual bool sendChannelCommand(const QString &channelCommand)
Processes a channel switching command.
virtual void switchToFirstAvailableChannel()
Switches to the first available channel.
virtual bool isChannelActive(const QString &channelName, int force)
Checks if a channel is currently active.
virtual void clearChannels()
Removes all channels from the chat system.
virtual QString entityMarkingText() const
Gets the entity marking text for username generation.
Definition vreChatQML.h:184
virtual Q_INVOKABLE void cycleChannels(bool direction)
Cycles through available channels.
void pinChatChanged(bool pinned)
Signal emitted when the pinned state changes.
virtual int entityForce() const
Gets the entity force identifier for username generation.
Definition vreChatQML.h:192
virtual ~DtVreChatQML() override
Virtual destructor.
virtual void updateAvailableChannels()
Updates the list of available channels in the UI.
virtual Q_INVOKABLE void togglePinChat()
Toggles the pinned state of the chat window.
bool pinChat
Flag indicating if the chat window is pinned (always visible)
Definition vreChatQML.h:93
QScopedPointer< DtVreChatModel > myChatModel
Definition vreChatQML.h:336
virtual void setEntityForce(int val)
Sets the entity force identifier for username generation.
Definition vreChatQML.h:196
void fullChatVisibleChanged(bool visible)
Signal emitted when the full chat visibility changes.
DtFilename myCurrentChatConfigFile
Definition vreChatQML.h:324
int currentChannelIdx
Index of the currently active chat channel.
Definition vreChatQML.h:90
QString myCurrentUsername
Definition vreChatQML.h:317
virtual bool isUsingCustomUsername() const
Checks if a custom username is being used.
Definition vreChatQML.h:180
bool isFullChatVisible() const
Gets whether the full chat window is visible.
Definition vreChatQML.h:271
QString myEntityMarkingText
Definition vreChatQML.h:319
virtual QString getCurrentUsername()
Gets the current username.
void currentChannelIdxChanged(int channelIdx)
Signal emitted when the active channel changes.
virtual bool addChannel(const makVre::ChannelInfo &channelInfo, bool updateAvailableChannels=false)
Adds a channel to the available channels list.
bool myFullChatVisible
Definition vreChatQML.h:333
bool fullChatVisible
Flag indicating if the full chat window is currently visible.
Definition vreChatQML.h:96
virtual DtVreChatModel * getChat()
Gets the chat message model.
virtual void sendChatMessage(const QString &message, const QString &channel, const int force)
Sends a regular chat message to a specific channel.
static std::string convertTextToHTML(const std::string &inputText)
Converts plain text to HTML format for QML display.
virtual void setEntityMarkingText(QString val)
Sets the entity marking text for username generation.
Definition vreChatQML.h:188
Defines export macros for the VR-Engage Player Station library.
#define PLAYERSTATION_DLL
Definition export.h:24
!
Definition glsVreMessageUtil.h:50
Q_DECLARE_METATYPE(makVre::ChannelInfo)
Structure defining a chat communication channel.
Definition vreChatQML.h:34
int force
Force identifier property exposed to QML.
Definition vreChatQML.h:40
QString channel
Channel name property exposed to QML.
Definition vreChatQML.h:37
ChannelInfo()=default
Default constructor.
QStringList entities
List of entities in this channel property exposed to QML.
Definition vreChatQML.h:46
bool myActive
Flag indicating if this channel is currently active.
Definition vreChatQML.h:69
ChannelInfo(QString ch, int f, bool a)
Constructor with parameters.
Definition vreChatQML.h:56
bool active
Channel activation status property exposed to QML.
Definition vreChatQML.h:43
QString myChannelName
Name of the communication channel.
Definition vreChatQML.h:62
int myForce
Force identifier associated with this channel (Typically: 1=friendly, 2=enemy, 3=neutral,...
Definition vreChatQML.h:66
QStringList myEntities
List of entities (participants) in this channel.
Definition vreChatQML.h:72
Defines the data model for the chat window in VR-Engage.
Defines the base class for all VREngage messages.