Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
CommunicationStream Class Referencefinal

A custom OpenGL widget displaying an animated communication stream visualization. More...

#include <communication_stream.h>

Inheritance diagram for CommunicationStream:
Collaboration diagram for CommunicationStream:

Public Types

enum  StreamState { kIdle , kReceiving , kDisplaying }
 Enum defining the different visual states of the communication stream. More...
 

Public Slots

void ClearTransmittingUser () const
 Hides the transmitting user label.
 
void SetAudioAmplitude (qreal amplitude)
 Sets the target wave amplitude based on incoming audio level. The actual wave amplitude smoothly interpolates towards this target value.
 
void SetTransmittingUser (const QString &user_id) const
 Displays the identifier of the user currently transmitting audio. Generates a unique color for the user and shows their ID (potentially shortened) in a label at the top right.
 

Public Member Functions

StreamMessageAddMessage (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 displayed after the animation completes if no other message is currently shown. Connects signals for navigation and closing.
 
StreamMessageAddMessageWithAttachment (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. The message is displayed after the animation completes if no other message is currently shown. Connects signals for navigation and closing.
 
void ClearMessages ()
 Removes all messages currently managed by the stream. Hides and schedules deletion for all message widgets and resets the stream state.
 
 CommunicationStream (QWidget *parent=nullptr)
 Constructs a CommunicationStream widget. Initializes OpenGL format, timers for animation and glitches, labels for stream name and transmitting user, and sets default animation parameters.
 
qreal GetGlitchIntensity () const
 Gets the current glitch effect intensity.
 
qreal GetWaveAmplitude () const
 Gets the current wave amplitude.
 
qreal GetWaveFrequency () const
 Gets the current wave frequency.
 
qreal GetWaveSpeed () const
 Gets the current wave speed.
 
qreal GetWaveThickness () const
 Gets the current wave thickness.
 
void SetGlitchIntensity (qreal intensity)
 Sets the current glitch effect intensity and triggers an update.
 
void SetStreamName (const QString &name) const
 Sets the text displayed in the stream name label at the top center.
 
void SetWaveAmplitude (qreal amplitude)
 Sets the current wave amplitude and triggers an update.
 
void SetWaveFrequency (qreal frequency)
 Sets the current wave frequency and triggers an update.
 
void SetWaveSpeed (qreal speed)
 Sets the current wave speed and triggers an update.
 
void SetWaveThickness (qreal thickness)
 Sets the current wave thickness and triggers an update.
 
 ~CommunicationStream () override
 Destructor. Cleans up OpenGL resources (VAO, VBO, shader program).
 

Protected Member Functions

void initializeGL () override
 Initializes OpenGL resources (shaders, VAO, VBO). Called once before the first paintGL.
 
void keyPressEvent (QKeyEvent *event) override
 Handles key presses for message navigation (Left/Right arrows) and closing (Enter).
 
void paintGL () override
 Renders the OpenGL scene (animated wave, grid, glitches). Called on update().
 
void resizeGL (int w, int h) override
 Handles resizing of the OpenGL viewport and repositions overlay widgets.
 

Properties

qreal glitchIntensity
 Property controlling the intensity of visual glitch effects. Animatable.
 
qreal waveAmplitude
 Property controlling the wave's vertical amplitude. Animatable.
 
qreal waveFrequency
 Property controlling the wave's horizontal frequency. Animatable.
 
qreal waveSpeed
 Property controlling the wave's horizontal scrolling speed. Animatable.
 
qreal waveThickness
 Property controlling the thickness of the rendered wave line. Animatable.
 

Private Slots

void HandleMessageHidden ()
 Slot triggered when a StreamMessage widget finishes its hiding animation (or is hidden). Handles logic for removing the message from the list, deleting the widget, showing the next message, or returning to the Idle state. Differentiates between closing a single message, removing a progress message, and clearing all messages.
 
void OnMessageRead ()
 Slot triggered when the user requests to close the current message (e.g., clicks "Read" or presses Enter). Initiates the process of closing the current message, which might trigger clearing all messages if Enter was pressed.
 
void ReturnToIdleAnimation ()
 Initiates the animation returning the wave to the "Idle" state. Animates amplitude, frequency, speed, and thickness back to base values.
 
void ShowMessageAtIndex (int index)
 Displays the message at the specified index in the messages_ list. Hides the previously displayed message, updates the current index, positions and shows the new message, connects signals, updates navigation buttons, and sets focus.
 
void ShowNextMessage ()
 Shows the next message in the list, if available.
 
void ShowPreviousMessage ()
 Shows the previous message in the list, if available.
 
void StartGlitchAnimation (qreal intensity)
 Starts a short, intense glitch animation.
 
void StartReceivingAnimation ()
 Initiates the "Receiving" state animation (wave becomes more active). Animates amplitude, frequency, speed, thickness, and glitch intensity. Transitions to Displaying state upon completion.
 
void TriggerRandomGlitch ()
 Slot called by glitch_timer_ to trigger random glitch effects during the Idle state.
 
void UpdateAnimation ()
 Slot called by animation_timer_ to update animation time and parameters. Advances time offset, interpolates wave amplitude towards target, fades glitch intensity, and schedules a repaint.
 
void UpdateStreamColor (const QString &key)
 Slot called when a configuration setting changes in WavelengthConfig. Updates the stream color if the relevant key ("stream_color" or "all") is provided.
 

Private Member Functions

void ConnectSignalsForMessage (const StreamMessage *message)
 Connects the necessary signals (navigation, read, hidden) from a StreamMessage widget to this CommunicationStream. Uses Qt::UniqueConnection to prevent duplicate connections.
 
void DisconnectSignalsForMessage (const StreamMessage *message) const
 Disconnects all signals originating from the given StreamMessage widget that are connected to this CommunicationStream.
 
void OptimizeForMessageTransition () const
 Temporarily reduces the background animation frame rate during message transitions for smoother UI performance.
 
void UpdateMessagePosition ()
 Updates the position of the currently displayed message to keep it centered.
 
void UpdateNavigationButtonsForCurrentMessage ()
 Updates the visibility of the "Next" and "Previous" buttons on the currently displayed message based on its position in the messages_ list.
 

Static Private Member Functions

static UserVisuals GenerateUserVisuals (const QString &user_id)
 Generates visual properties (currently color) based on a user ID hash.
 

Private Attributes

const qreal amplitude_scale_
 Multiplier for audio amplitude effect.
 
QTimer * animation_timer_
 Timer driving the main wave animation updates.
 
const qreal base_wave_amplitude_
 Base amplitude in Idle state.
 
WavelengthConfigconfig_
 Pointer to the RegeditConfig object for accessing configuration settings.
 
int current_message_index_
 Index of the currently displayed message in messages_.
 
qreal glitch_intensity_
 Current animated glitch intensity.
 
QTimer * glitch_timer_
 Timer triggering random glitches in Idle state.
 
bool initialized_
 Flag indicating if OpenGL resources are initialized.
 
bool is_clearing_all_messages_ = false
 Flag indicating if a full clear operation is in progress.
 
QList< StreamMessage * > messages_
 List of message widgets managed by the stream.
 
QOpenGLShaderProgram * shader_program_
 Compiled shader program for rendering the wave.
 
StreamState state_
 Current visual state of the stream.
 
QColor stream_color_
 Color used for rendering the stream color chosen from the registry.
 
QLabel * stream_name_label_
 Label displaying the stream name.
 
qreal target_wave_amplitude_
 Target amplitude for smooth interpolation.
 
qreal time_offset_
 Time variable for shader animations.
 
UserInfoLabeltransmitting_user_label_
 Label displaying the transmitting user ID and color indicator.
 
QOpenGLVertexArrayObject vao_
 Vertex Array Object.
 
QOpenGLBuffer vertex_buffer_
 Vertex Buffer Object holding the fullscreen quad vertices.
 
qreal wave_amplitude_
 Current animated wave amplitude.
 
qreal wave_frequency_
 Current animated wave frequency.
 
qreal wave_speed_
 Current animated wave speed.
 
qreal wave_thickness_
 Current animated wave thickness.
 

Detailed Description

A custom OpenGL widget displaying an animated communication stream visualization.

This widget renders a dynamic sine wave with cyberpunk aesthetics, including grid lines, glitch effects, and scanlines, using OpenGL shaders. It can display incoming messages (StreamMessage) overlaid on the animation. The wave's amplitude reacts to audio input (via SetAudioAmplitude) and changes appearance based on its state (Idle, Receiving, Displaying). It also shows the name of the stream and the ID of the currently transmitting user. Message navigation (next/previous) and closing are handled via keyboard input (arrows, Enter).

Member Enumeration Documentation

◆ StreamState

Enum defining the different visual states of the communication stream.

Enumerator
kIdle 

Default state: Simple wave with occasional random glitches.

kReceiving 

Active animation during message reception (before display).

kDisplaying 

State when a message is actively displayed.

Constructor & Destructor Documentation

◆ CommunicationStream()

CommunicationStream::CommunicationStream ( QWidget * parent = nullptr)
explicit

Constructs a CommunicationStream widget. Initializes OpenGL format, timers for animation and glitches, labels for stream name and transmitting user, and sets default animation parameters.

Parameters
parentOptional parent widget.
Here is the call graph for this function:

◆ ~CommunicationStream()

CommunicationStream::~CommunicationStream ( )
override

Destructor. Cleans up OpenGL resources (VAO, VBO, shader program).

Member Function Documentation

◆ AddMessage()

StreamMessage * CommunicationStream::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 displayed after the animation completes if no other message is currently shown. Connects signals for navigation and closing.

Parameters
contentThe message content.
senderThe sender's identifier.
typeThe type of the message (e.g., Text, System).
message_idOptional unique ID, used for progress messages.
Returns
Pointer to the created StreamMessage widget.
Here is the call graph for this function:

◆ AddMessageWithAttachment()

StreamMessage * CommunicationStream::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. The message is displayed after the animation completes if no other message is currently shown. Connects signals for navigation and closing.

Parameters
contentThe main content or description of the attachment.
senderThe sender's identifier.
typeThe type of the message (e.g., Attachment).
message_idOptional unique ID, used for progress messages.
Returns
Pointer to the created StreamMessage widget.
Here is the call graph for this function:

◆ ClearMessages()

void CommunicationStream::ClearMessages ( )

Removes all messages currently managed by the stream. Hides and schedules deletion for all message widgets and resets the stream state.

Here is the call graph for this function:

◆ ClearTransmittingUser

void CommunicationStream::ClearTransmittingUser ( ) const
slot

Hides the transmitting user label.

◆ ConnectSignalsForMessage()

void CommunicationStream::ConnectSignalsForMessage ( const StreamMessage * message)
private

Connects the necessary signals (navigation, read, hidden) from a StreamMessage widget to this CommunicationStream. Uses Qt::UniqueConnection to prevent duplicate connections.

Parameters
messagePointer to the StreamMessage widget.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DisconnectSignalsForMessage()

void CommunicationStream::DisconnectSignalsForMessage ( const StreamMessage * message) const
private

Disconnects all signals originating from the given StreamMessage widget that are connected to this CommunicationStream.

Parameters
messagePointer to the StreamMessage widget.
Here is the caller graph for this function:

◆ GenerateUserVisuals()

UserVisuals CommunicationStream::GenerateUserVisuals ( const QString & user_id)
staticprivate

Generates visual properties (currently color) based on a user ID hash.

Parameters
user_idThe user identifier string.
Returns
A UserVisuals struct containing the generated properties.
Here is the caller graph for this function:

◆ GetGlitchIntensity()

qreal CommunicationStream::GetGlitchIntensity ( ) const
inline

Gets the current glitch effect intensity.

◆ GetWaveAmplitude()

qreal CommunicationStream::GetWaveAmplitude ( ) const
inline

Gets the current wave amplitude.

◆ GetWaveFrequency()

qreal CommunicationStream::GetWaveFrequency ( ) const
inline

Gets the current wave frequency.

◆ GetWaveSpeed()

qreal CommunicationStream::GetWaveSpeed ( ) const
inline

Gets the current wave speed.

◆ GetWaveThickness()

qreal CommunicationStream::GetWaveThickness ( ) const
inline

Gets the current wave thickness.

◆ HandleMessageHidden

void CommunicationStream::HandleMessageHidden ( )
privateslot

Slot triggered when a StreamMessage widget finishes its hiding animation (or is hidden). Handles logic for removing the message from the list, deleting the widget, showing the next message, or returning to the Idle state. Differentiates between closing a single message, removing a progress message, and clearing all messages.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initializeGL()

void CommunicationStream::initializeGL ( )
overrideprotected

Initializes OpenGL resources (shaders, VAO, VBO). Called once before the first paintGL.

◆ keyPressEvent()

void CommunicationStream::keyPressEvent ( QKeyEvent * event)
overrideprotected

Handles key presses for message navigation (Left/Right arrows) and closing (Enter).

Parameters
eventThe key event.
Here is the call graph for this function:

◆ OnMessageRead

void CommunicationStream::OnMessageRead ( )
privateslot

Slot triggered when the user requests to close the current message (e.g., clicks "Read" or presses Enter). Initiates the process of closing the current message, which might trigger clearing all messages if Enter was pressed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OptimizeForMessageTransition()

void CommunicationStream::OptimizeForMessageTransition ( ) const
private

Temporarily reduces the background animation frame rate during message transitions for smoother UI performance.

Here is the caller graph for this function:

◆ paintGL()

void CommunicationStream::paintGL ( )
overrideprotected

Renders the OpenGL scene (animated wave, grid, glitches). Called on update().

◆ resizeGL()

void CommunicationStream::resizeGL ( int w,
int h )
overrideprotected

Handles resizing of the OpenGL viewport and repositions overlay widgets.

Parameters
wNew width.
hNew height.
Here is the call graph for this function:

◆ ReturnToIdleAnimation

void CommunicationStream::ReturnToIdleAnimation ( )
privateslot

Initiates the animation returning the wave to the "Idle" state. Animates amplitude, frequency, speed, and thickness back to base values.

Here is the caller graph for this function:

◆ SetAudioAmplitude

void CommunicationStream::SetAudioAmplitude ( qreal amplitude)
slot

Sets the target wave amplitude based on incoming audio level. The actual wave amplitude smoothly interpolates towards this target value.

Parameters
amplitudeThe audio amplitude level (typically 0.0 to 1.0).

◆ SetGlitchIntensity()

void CommunicationStream::SetGlitchIntensity ( qreal intensity)

Sets the current glitch effect intensity and triggers an update.

◆ SetStreamName()

void CommunicationStream::SetStreamName ( const QString & name) const

Sets the text displayed in the stream name label at the top center.

Parameters
nameThe new name for the stream.

◆ SetTransmittingUser

void CommunicationStream::SetTransmittingUser ( const QString & user_id) const
slot

Displays the identifier of the user currently transmitting audio. Generates a unique color for the user and shows their ID (potentially shortened) in a label at the top right.

Parameters
user_idThe identifier of the transmitting user.
Here is the call graph for this function:

◆ SetWaveAmplitude()

void CommunicationStream::SetWaveAmplitude ( qreal amplitude)

Sets the current wave amplitude and triggers an update.

◆ SetWaveFrequency()

void CommunicationStream::SetWaveFrequency ( qreal frequency)

Sets the current wave frequency and triggers an update.

◆ SetWaveSpeed()

void CommunicationStream::SetWaveSpeed ( qreal speed)

Sets the current wave speed and triggers an update.

◆ SetWaveThickness()

void CommunicationStream::SetWaveThickness ( qreal thickness)

Sets the current wave thickness and triggers an update.

◆ ShowMessageAtIndex

void CommunicationStream::ShowMessageAtIndex ( int index)
privateslot

Displays the message at the specified index in the messages_ list. Hides the previously displayed message, updates the current index, positions and shows the new message, connects signals, updates navigation buttons, and sets focus.

Parameters
indexThe index of the message to display.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowNextMessage

void CommunicationStream::ShowNextMessage ( )
privateslot

Shows the next message in the list, if available.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowPreviousMessage

void CommunicationStream::ShowPreviousMessage ( )
privateslot

Shows the previous message in the list, if available.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartGlitchAnimation

void CommunicationStream::StartGlitchAnimation ( qreal intensity)
privateslot

Starts a short, intense glitch animation.

Parameters
intensityThe peak intensity of the glitch.
Here is the caller graph for this function:

◆ StartReceivingAnimation

void CommunicationStream::StartReceivingAnimation ( )
privateslot

Initiates the "Receiving" state animation (wave becomes more active). Animates amplitude, frequency, speed, thickness, and glitch intensity. Transitions to Displaying state upon completion.

Here is the caller graph for this function:

◆ TriggerRandomGlitch

void CommunicationStream::TriggerRandomGlitch ( )
privateslot

Slot called by glitch_timer_ to trigger random glitch effects during the Idle state.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateAnimation

void CommunicationStream::UpdateAnimation ( )
privateslot

Slot called by animation_timer_ to update animation time and parameters. Advances time offset, interpolates wave amplitude towards target, fades glitch intensity, and schedules a repaint.

Here is the caller graph for this function:

◆ UpdateMessagePosition()

void CommunicationStream::UpdateMessagePosition ( )
private

Updates the position of the currently displayed message to keep it centered.

Here is the caller graph for this function:

◆ UpdateNavigationButtonsForCurrentMessage()

void CommunicationStream::UpdateNavigationButtonsForCurrentMessage ( )
private

Updates the visibility of the "Next" and "Previous" buttons on the currently displayed message based on its position in the messages_ list.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateStreamColor

void CommunicationStream::UpdateStreamColor ( const QString & key)
privateslot

Slot called when a configuration setting changes in WavelengthConfig. Updates the stream color if the relevant key ("stream_color" or "all") is provided.

Parameters
keyThe key of the changed setting.
Here is the caller graph for this function:

Member Data Documentation

◆ amplitude_scale_

const qreal CommunicationStream::amplitude_scale_
private

Multiplier for audio amplitude effect.

◆ animation_timer_

QTimer* CommunicationStream::animation_timer_
private

Timer driving the main wave animation updates.

◆ base_wave_amplitude_

const qreal CommunicationStream::base_wave_amplitude_
private

Base amplitude in Idle state.

◆ config_

WavelengthConfig* CommunicationStream::config_
private

Pointer to the RegeditConfig object for accessing configuration settings.

◆ current_message_index_

int CommunicationStream::current_message_index_
private

Index of the currently displayed message in messages_.

◆ glitch_intensity_

qreal CommunicationStream::glitch_intensity_
private

Current animated glitch intensity.

◆ glitch_timer_

QTimer* CommunicationStream::glitch_timer_
private

Timer triggering random glitches in Idle state.

◆ initialized_

bool CommunicationStream::initialized_
private

Flag indicating if OpenGL resources are initialized.

◆ is_clearing_all_messages_

bool CommunicationStream::is_clearing_all_messages_ = false
private

Flag indicating if a full clear operation is in progress.

◆ messages_

QList<StreamMessage *> CommunicationStream::messages_
private

List of message widgets managed by the stream.

◆ shader_program_

QOpenGLShaderProgram* CommunicationStream::shader_program_
private

Compiled shader program for rendering the wave.

◆ state_

StreamState CommunicationStream::state_
private

Current visual state of the stream.

◆ stream_color_

QColor CommunicationStream::stream_color_
private

Color used for rendering the stream color chosen from the registry.

◆ stream_name_label_

QLabel* CommunicationStream::stream_name_label_
private

Label displaying the stream name.

◆ target_wave_amplitude_

qreal CommunicationStream::target_wave_amplitude_
private

Target amplitude for smooth interpolation.

◆ time_offset_

qreal CommunicationStream::time_offset_
private

Time variable for shader animations.

◆ transmitting_user_label_

UserInfoLabel* CommunicationStream::transmitting_user_label_
private

Label displaying the transmitting user ID and color indicator.

◆ vao_

QOpenGLVertexArrayObject CommunicationStream::vao_
private

Vertex Array Object.

◆ vertex_buffer_

QOpenGLBuffer CommunicationStream::vertex_buffer_
private

Vertex Buffer Object holding the fullscreen quad vertices.

◆ wave_amplitude_

qreal CommunicationStream::wave_amplitude_
private

Current animated wave amplitude.

◆ wave_frequency_

qreal CommunicationStream::wave_frequency_
private

Current animated wave frequency.

◆ wave_speed_

qreal CommunicationStream::wave_speed_
private

Current animated wave speed.

◆ wave_thickness_

qreal CommunicationStream::wave_thickness_
private

Current animated wave thickness.

Property Documentation

◆ glitchIntensity

qreal CommunicationStream::glitchIntensity
readwrite

Property controlling the intensity of visual glitch effects. Animatable.

◆ waveAmplitude

qreal CommunicationStream::waveAmplitude
readwrite

Property controlling the wave's vertical amplitude. Animatable.

◆ waveFrequency

qreal CommunicationStream::waveFrequency
readwrite

Property controlling the wave's horizontal frequency. Animatable.

◆ waveSpeed

qreal CommunicationStream::waveSpeed
readwrite

Property controlling the wave's horizontal scrolling speed. Animatable.

◆ waveThickness

qreal CommunicationStream::waveThickness
readwrite

Property controlling the thickness of the rendered wave line. Animatable.


The documentation for this class was generated from the following files: