|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
A custom OpenGL widget displaying an animated communication stream visualization. More...
#include <communication_stream.h>
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 | |
| 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 displayed after the animation completes if no other message is currently shown. Connects signals for navigation and closing. | |
| 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. 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. | |
| WavelengthConfig * | config_ |
| 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. | |
| UserInfoLabel * | transmitting_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. | |
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).
|
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.
| parent | Optional parent widget. |
|
override |
Destructor. Cleans up OpenGL resources (VAO, VBO, shader program).
| 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.
| content | The message content. |
| sender | The sender's identifier. |
| type | The type of the message (e.g., Text, System). |
| message_id | Optional unique ID, used for progress messages. |
| 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.
| content | The main content or description of the attachment. |
| sender | The sender's identifier. |
| type | The type of the message (e.g., Attachment). |
| message_id | Optional unique ID, used for progress messages. |
| void CommunicationStream::ClearMessages | ( | ) |
Removes all messages currently managed by the stream. Hides and schedules deletion for all message widgets and resets the stream state.
|
slot |
Hides the transmitting user label.
|
private |
Connects the necessary signals (navigation, read, hidden) from a StreamMessage widget to this CommunicationStream. Uses Qt::UniqueConnection to prevent duplicate connections.
| message | Pointer to the StreamMessage widget. |
|
private |
Disconnects all signals originating from the given StreamMessage widget that are connected to this CommunicationStream.
| message | Pointer to the StreamMessage widget. |
|
staticprivate |
Generates visual properties (currently color) based on a user ID hash.
| user_id | The user identifier string. |
|
inline |
Gets the current glitch effect intensity.
|
inline |
Gets the current wave amplitude.
|
inline |
Gets the current wave frequency.
|
inline |
Gets the current wave speed.
|
inline |
Gets the current wave thickness.
|
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.
|
overrideprotected |
Initializes OpenGL resources (shaders, VAO, VBO). Called once before the first paintGL.
|
overrideprotected |
Handles key presses for message navigation (Left/Right arrows) and closing (Enter).
| event | The key event. |
|
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.
|
private |
Temporarily reduces the background animation frame rate during message transitions for smoother UI performance.
|
overrideprotected |
Renders the OpenGL scene (animated wave, grid, glitches). Called on update().
|
overrideprotected |
Handles resizing of the OpenGL viewport and repositions overlay widgets.
| w | New width. |
| h | New height. |
|
privateslot |
Initiates the animation returning the wave to the "Idle" state. Animates amplitude, frequency, speed, and thickness back to base values.
|
slot |
Sets the target wave amplitude based on incoming audio level. The actual wave amplitude smoothly interpolates towards this target value.
| amplitude | The audio amplitude level (typically 0.0 to 1.0). |
| void CommunicationStream::SetGlitchIntensity | ( | qreal | intensity | ) |
Sets the current glitch effect intensity and triggers an update.
| void CommunicationStream::SetStreamName | ( | const QString & | name | ) | const |
Sets the text displayed in the stream name label at the top center.
| name | The new name for the stream. |
|
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.
| user_id | The identifier of the transmitting user. |
| void CommunicationStream::SetWaveAmplitude | ( | qreal | amplitude | ) |
Sets the current wave amplitude and triggers an update.
| void CommunicationStream::SetWaveFrequency | ( | qreal | frequency | ) |
Sets the current wave frequency and triggers an update.
| void CommunicationStream::SetWaveSpeed | ( | qreal | speed | ) |
Sets the current wave speed and triggers an update.
| void CommunicationStream::SetWaveThickness | ( | qreal | thickness | ) |
Sets the current wave thickness and triggers an update.
|
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.
| index | The index of the message to display. |
|
privateslot |
Shows the next message in the list, if available.
|
privateslot |
Shows the previous message in the list, if available.
|
privateslot |
Starts a short, intense glitch animation.
| intensity | The peak intensity of the glitch. |
|
privateslot |
Initiates the "Receiving" state animation (wave becomes more active). Animates amplitude, frequency, speed, thickness, and glitch intensity. Transitions to Displaying state upon completion.
|
privateslot |
Slot called by glitch_timer_ to trigger random glitch effects during the Idle state.
|
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.
|
private |
Updates the position of the currently displayed message to keep it centered.
|
private |
Updates the visibility of the "Next" and "Previous" buttons on the currently displayed message based on its position in the messages_ list.
|
privateslot |
Slot called when a configuration setting changes in WavelengthConfig. Updates the stream color if the relevant key ("stream_color" or "all") is provided.
| key | The key of the changed setting. |
|
private |
Multiplier for audio amplitude effect.
|
private |
Timer driving the main wave animation updates.
|
private |
Base amplitude in Idle state.
|
private |
Pointer to the RegeditConfig object for accessing configuration settings.
|
private |
Index of the currently displayed message in messages_.
|
private |
Current animated glitch intensity.
|
private |
Timer triggering random glitches in Idle state.
|
private |
Flag indicating if OpenGL resources are initialized.
|
private |
Flag indicating if a full clear operation is in progress.
|
private |
List of message widgets managed by the stream.
|
private |
Compiled shader program for rendering the wave.
|
private |
Current visual state of the stream.
|
private |
Color used for rendering the stream color chosen from the registry.
|
private |
Label displaying the stream name.
|
private |
Target amplitude for smooth interpolation.
|
private |
Time variable for shader animations.
|
private |
Label displaying the transmitting user ID and color indicator.
|
private |
Vertex Array Object.
|
private |
Vertex Buffer Object holding the fullscreen quad vertices.
|
private |
Current animated wave amplitude.
|
private |
Current animated wave frequency.
|
private |
Current animated wave speed.
|
private |
Current animated wave thickness.
|
readwrite |
Property controlling the intensity of visual glitch effects. Animatable.
|
readwrite |
Property controlling the wave's vertical amplitude. Animatable.
|
readwrite |
Property controlling the wave's horizontal frequency. Animatable.
|
readwrite |
Property controlling the wave's horizontal scrolling speed. Animatable.
|
readwrite |
Property controlling the thickness of the rendered wave line. Animatable.