Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
communication_stream.h
Go to the documentation of this file.
1#ifndef COMMUNICATION_STREAM_H
2#define COMMUNICATION_STREAM_H
3
4#include <QOpenGLBuffer>
5#include <QOpenGLWidget>
6#include <QOpenGLFunctions>
7#include <QOpenGLVertexArrayObject>
8
9#include "stream_message.h"
11
12class QOpenGLShaderProgram;
14
21 QColor color;
22};
23
34class CommunicationStream final : public QOpenGLWidget, protected QOpenGLFunctions {
35 Q_OBJECT
37 Q_PROPERTY(qreal waveAmplitude READ GetWaveAmplitude WRITE SetWaveAmplitude)
39 Q_PROPERTY(qreal waveFrequency READ GetWaveFrequency WRITE SetWaveFrequency)
41 Q_PROPERTY(qreal waveSpeed READ GetWaveSpeed WRITE SetWaveSpeed)
45 Q_PROPERTY(qreal waveThickness READ GetWaveThickness WRITE SetWaveThickness)
46
47public:
56
57 Q_ENUM(StreamState)
58
59
65 explicit CommunicationStream(QWidget *parent = nullptr);
66
70 ~CommunicationStream() override;
71
82 StreamMessage *AddMessageWithAttachment(const QString &content, const QString &sender,
83 StreamMessage::MessageType type, const QString &message_id = QString());
84
86 qreal GetWaveAmplitude() const { return wave_amplitude_; }
87
89 void SetWaveAmplitude(qreal amplitude);
90
92 qreal GetWaveFrequency() const { return wave_frequency_; }
93
95 void SetWaveFrequency(qreal frequency);
96
98 qreal GetWaveSpeed() const { return wave_speed_; }
99
101 void SetWaveSpeed(qreal speed);
102
104 qreal GetGlitchIntensity() const { return glitch_intensity_; }
105
107 void SetGlitchIntensity(qreal intensity);
108
110 qreal GetWaveThickness() const { return wave_thickness_; }
111
113 void SetWaveThickness(qreal thickness);
114
119 void SetStreamName(const QString &name) const;
120
131 StreamMessage *AddMessage(const QString &content, const QString &sender, StreamMessage::MessageType type,
132 const QString &message_id = QString());
133
138 void ClearMessages();
139
140public slots:
147 void SetTransmittingUser(const QString &user_id) const;
148
152 void ClearTransmittingUser() const;
153
159 void SetAudioAmplitude(qreal amplitude);
160
161protected:
165 void initializeGL() override;
166
172 void resizeGL(int w, int h) override;
173
177 void paintGL() override;
178
183 void keyPressEvent(QKeyEvent *event) override;
184
185private slots:
191 void UpdateAnimation();
192
196 void TriggerRandomGlitch();
197
204
210
215 void StartGlitchAnimation(qreal intensity);
216
223 void ShowMessageAtIndex(int index);
224
228 void ShowNextMessage();
229
233 void ShowPreviousMessage();
234
239 void OnMessageRead();
240
247 void HandleMessageHidden();
248
254 void UpdateStreamColor(const QString &key);
255
256private:
262 static UserVisuals GenerateUserVisuals(const QString &user_id);
263
269 void ConnectSignalsForMessage(const StreamMessage *message);
270
275 void DisconnectSignalsForMessage(const StreamMessage *message) const;
276
282
286 void OptimizeForMessageTransition() const;
287
292
293 // wave animation parameters
295 const qreal amplitude_scale_;
302
303 // state and message management
305 QList<StreamMessage *> messages_;
308
309 // ui elements
312
313 // internal state
316
317 // timers
320
321 // OpenGL resources
322 QOpenGLShaderProgram *shader_program_;
323 QOpenGLVertexArrayObject vao_;
324 QOpenGLBuffer vertex_buffer_;
325
326 // regedit config
329};
330
331#endif // COMMUNICATION_STREAM_H
void SetTransmittingUser(const QString &user_id) const
Displays the identifier of the user currently transmitting audio. Generates a unique color for the us...
Definition communication_stream.cpp:197
qreal target_wave_amplitude_
Target amplitude for smooth interpolation.
Definition communication_stream.h:297
UserInfoLabel * transmitting_user_label_
Label displaying the transmitting user ID and color indicator.
Definition communication_stream.h:311
void SetWaveSpeed(qreal speed)
Sets the current wave speed and triggers an update.
Definition communication_stream.cpp:135
qreal wave_speed_
Current animated wave speed.
Definition communication_stream.h:299
StreamMessage * AddMessageWithAttachment(const QString &content, const QString &sender, StreamMessage::MessageType type, const QString &message_id=QString())
Adds a new message with attachment content to the stream. Initiates the receiving animation....
Definition communication_stream.cpp:98
void ReturnToIdleAnimation()
Initiates the animation returning the wave to the "Idle" state. Animates amplitude,...
Definition communication_stream.cpp:479
void UpdateNavigationButtonsForCurrentMessage()
Updates the visibility of the "Next" and "Previous" buttons on the currently displayed message based ...
Definition communication_stream.cpp:735
void SetAudioAmplitude(qreal amplitude)
Sets the target wave amplitude based on incoming audio level. The actual wave amplitude smoothly inte...
Definition communication_stream.cpp:220
qreal wave_frequency_
Current animated wave frequency.
Definition communication_stream.h:298
void TriggerRandomGlitch()
Slot called by glitch_timer_ to trigger random glitch effects during the Idle state.
Definition communication_stream.cpp:420
void HandleMessageHidden()
Slot triggered when a StreamMessage widget finishes its hiding animation (or is hidden)....
Definition communication_stream.cpp:610
void DisconnectSignalsForMessage(const StreamMessage *message) const
Disconnects all signals originating from the given StreamMessage widget that are connected to this Co...
Definition communication_stream.cpp:730
QList< StreamMessage * > messages_
List of message widgets managed by the stream.
Definition communication_stream.h:305
qreal GetGlitchIntensity() const
Gets the current glitch effect intensity.
Definition communication_stream.h:104
void OptimizeForMessageTransition() const
Temporarily reduces the background animation frame rate during message transitions for smoother UI pe...
Definition communication_stream.cpp:744
const qreal base_wave_amplitude_
Base amplitude in Idle state.
Definition communication_stream.h:294
QColor stream_color_
Color used for rendering the stream color chosen from the registry.
Definition communication_stream.h:328
CommunicationStream(QWidget *parent=nullptr)
Constructs a CommunicationStream widget. Initializes OpenGL format, timers for animation and glitches...
Definition communication_stream.cpp:15
void ClearMessages()
Removes all messages currently managed by the stream. Hides and schedules deletion for all message wi...
Definition communication_stream.cpp:179
qreal waveAmplitude
Property controlling the wave's vertical amplitude. Animatable.
Definition communication_stream.h:37
qreal wave_thickness_
Current animated wave thickness.
Definition communication_stream.h:301
qreal GetWaveSpeed() const
Gets the current wave speed.
Definition communication_stream.h:98
void ShowNextMessage()
Shows the next message in the list, if available.
Definition communication_stream.cpp:584
QLabel * stream_name_label_
Label displaying the stream name.
Definition communication_stream.h:310
qreal waveSpeed
Property controlling the wave's horizontal scrolling speed. Animatable.
Definition communication_stream.h:41
StreamState state_
Current visual state of the stream.
Definition communication_stream.h:304
const qreal amplitude_scale_
Multiplier for audio amplitude effect.
Definition communication_stream.h:295
void SetGlitchIntensity(qreal intensity)
Sets the current glitch effect intensity and triggers an update.
Definition communication_stream.cpp:140
void initializeGL() override
Initializes OpenGL resources (shaders, VAO, VBO). Called once before the first paintGL.
Definition communication_stream.cpp:224
QOpenGLVertexArrayObject vao_
Vertex Array Object.
Definition communication_stream.h:323
void OnMessageRead()
Slot triggered when the user requests to close the current message (e.g., clicks "Read" or presses En...
Definition communication_stream.cpp:598
qreal waveFrequency
Property controlling the wave's horizontal frequency. Animatable.
Definition communication_stream.h:39
void keyPressEvent(QKeyEvent *event) override
Handles key presses for message navigation (Left/Right arrows) and closing (Enter).
Definition communication_stream.cpp:373
void ShowPreviousMessage()
Shows the previous message in the list, if available.
Definition communication_stream.cpp:591
StreamState
Enum defining the different visual states of the communication stream.
Definition communication_stream.h:51
@ kIdle
Default state: Simple wave with occasional random glitches.
Definition communication_stream.h:52
@ kReceiving
Active animation during message reception (before display).
Definition communication_stream.h:53
@ kDisplaying
State when a message is actively displayed.
Definition communication_stream.h:54
bool initialized_
Flag indicating if OpenGL resources are initialized.
Definition communication_stream.h:314
void StartReceivingAnimation()
Initiates the "Receiving" state animation (wave becomes more active). Animates amplitude,...
Definition communication_stream.cpp:430
qreal wave_amplitude_
Current animated wave amplitude.
Definition communication_stream.h:296
QOpenGLBuffer vertex_buffer_
Vertex Buffer Object holding the fullscreen quad vertices.
Definition communication_stream.h:324
void ConnectSignalsForMessage(const StreamMessage *message)
Connects the necessary signals (navigation, read, hidden) from a StreamMessage widget to this Communi...
Definition communication_stream.cpp:719
void SetWaveThickness(qreal thickness)
Sets the current wave thickness and triggers an update.
Definition communication_stream.cpp:145
QTimer * glitch_timer_
Timer triggering random glitches in Idle state.
Definition communication_stream.h:319
int current_message_index_
Index of the currently displayed message in messages_.
Definition communication_stream.h:306
void ShowMessageAtIndex(int index)
Displays the message at the specified index in the messages_ list. Hides the previously displayed mes...
Definition communication_stream.cpp:529
QTimer * animation_timer_
Timer driving the main wave animation updates.
Definition communication_stream.h:318
void UpdateMessagePosition()
Updates the position of the currently displayed message to keep it centered.
Definition communication_stream.cpp:763
qreal waveThickness
Property controlling the thickness of the rendered wave line. Animatable.
Definition communication_stream.h:45
void SetStreamName(const QString &name) const
Sets the text displayed in the stream name label at the top center.
Definition communication_stream.cpp:150
static UserVisuals GenerateUserVisuals(const QString &user_id)
Generates visual properties (currently color) based on a user ID hash.
Definition communication_stream.cpp:707
void SetWaveFrequency(qreal frequency)
Sets the current wave frequency and triggers an update.
Definition communication_stream.cpp:130
void UpdateAnimation()
Slot called by animation_timer_ to update animation time and parameters. Advances time offset,...
Definition communication_stream.cpp:409
void ClearTransmittingUser() const
Hides the transmitting user label.
Definition communication_stream.cpp:215
qreal GetWaveAmplitude() const
Gets the current wave amplitude.
Definition communication_stream.h:86
qreal glitch_intensity_
Current animated glitch intensity.
Definition communication_stream.h:300
void paintGL() override
Renders the OpenGL scene (animated wave, grid, glitches). Called on update().
Definition communication_stream.cpp:349
qreal GetWaveFrequency() const
Gets the current wave frequency.
Definition communication_stream.h:92
qreal GetWaveThickness() const
Gets the current wave thickness.
Definition communication_stream.h:110
qreal glitchIntensity
Property controlling the intensity of visual glitch effects. Animatable.
Definition communication_stream.h:43
QOpenGLShaderProgram * shader_program_
Compiled shader program for rendering the wave.
Definition communication_stream.h:322
WavelengthConfig * config_
Pointer to the RegeditConfig object for accessing configuration settings.
Definition communication_stream.h:327
StreamMessage * AddMessage(const QString &content, const QString &sender, StreamMessage::MessageType type, const QString &message_id=QString())
Adds a new standard message to the stream. Initiates the receiving animation. The message is displaye...
Definition communication_stream.cpp:156
void UpdateStreamColor(const QString &key)
Slot called when a configuration setting changes in WavelengthConfig. Updates the stream color if the...
Definition communication_stream.cpp:698
void resizeGL(int w, int h) override
Handles resizing of the OpenGL viewport and repositions overlay widgets.
Definition communication_stream.cpp:340
bool is_clearing_all_messages_
Flag indicating if a full clear operation is in progress.
Definition communication_stream.h:307
void SetWaveAmplitude(qreal amplitude)
Sets the current wave amplitude and triggers an update.
Definition communication_stream.cpp:125
qreal time_offset_
Time variable for shader animations.
Definition communication_stream.h:315
~CommunicationStream() override
Destructor. Cleans up OpenGL resources (VAO, VBO, shader program).
Definition communication_stream.cpp:90
void StartGlitchAnimation(qreal intensity)
Starts a short, intense glitch animation.
Definition communication_stream.cpp:516
A custom widget representing a single message within the CommunicationStream.
Definition stream_message.h:26
MessageType
Enum defining the type/origin of the message, affecting its styling.
Definition stream_message.h:39
A custom QLabel that displays text alongside a colored circle with a glow effect.
Definition user_info_label.h:14
Manages application configuration settings using a singleton pattern.
Definition wavelength_config.h:36
Structure holding visual properties generated for a user ID. Currently only holds the generated color...
Definition communication_stream.h:19
QColor color
A unique color generated based on the user ID hash.
Definition communication_stream.h:21