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

A custom widget representing a single message within the CommunicationStream. More...

#include <stream_message.h>

Inheritance diagram for StreamMessage:
Collaboration diagram for StreamMessage:

Public Types

enum  MessageType { kReceived , kTransmitted , kSystem }
 Enum defining the type/origin of the message, affecting its styling. More...
 

Public Slots

void MarkAsRead ()
 Marks the message as read, triggers the appropriate closing animation (Electronic Shutdown or a simpler fade/glitch for long messages), and emits messageRead(). Prevents multiple calls.
 

Signals

void hidden ()
 Emitted when the message finishes its fade-out or closing animation and becomes hidden.
 
void messageRead ()
 Emitted when the message is marked as read (MarkAsRead() is called).
 

Public Member Functions

void AddAttachment (const QString &html)
 Parses HTML content to find an attachment placeholder and adds the corresponding AttachmentPlaceholder widget. Extracts attachment details (ID, MIME type, filename) from the HTML attributes. Removes the old attachment widget if present. Adjusts message size constraints. Connects signals to handle attachment loading and size changes.
 
void AdjustSizeToContent ()
 Adjusts the size of the message widget to fit its content, especially after an attachment has loaded. Forces layout recalculation and calculates optimal size based on attachment dimensions, respecting screen boundaries. Updates geometry and parent layout.
 
void FadeIn ()
 Starts the fade-in animation (opacity and glow). Also triggers the text reveal animation (CyberTextDisplay) upon completion. Sets focus.
 
void FadeOut ()
 Starts the fade-out animation (opacity and glow). Hides the widget and emits the hidden() signal upon completion.
 
QString GetContent () const
 Gets the original message content (may include HTML).
 
qreal GetGlowIntensity () const
 Gets the current glow intensity level.
 
QString GetMessageId () const
 Gets the unique message identifier (if provided).
 
QString GetMessageSender () const
 Gets the sender identifier.
 
QPushButton * GetNextButton () const
 Gets a pointer to the Next navigation button.
 
qreal GetOpacity () const
 Gets the current opacity level.
 
QPushButton * GetPrevButton () const
 Gets a pointer to the Previous navigation button.
 
qreal GetShutdownProgress () const
 Gets the current electronic shutdown effect progress.
 
MessageType GetType () const
 Gets the message type (Received, Transmitted, System).
 
bool IsRead () const
 Checks if the message has been marked as read.
 
void SetGlowIntensity (qreal intensity)
 Sets the glow intensity level and triggers a repaint.
 
void SetOpacity (qreal opacity)
 Sets the opacity level and updates the QGraphicsOpacityEffect.
 
void SetShutdownProgress (qreal progress)
 Sets the electronic shutdown effect progress and updates the ElectronicShutdownEffect.
 
void ShowNavigationButtons (bool has_previous, bool has_next) const
 Shows or hides the navigation buttons (Next, Previous) and the Mark Read button. Updates the layout to position the buttons correctly.
 
QSize sizeHint () const override
 Returns the recommended size for the widget based on its content (text length or attachment size).
 
void StartShutdownAnimation ()
 Starts the electronic shutdown closing animation. Applies the ElectronicShutdownEffect and animates its progress. Hides the widget and emits hidden() upon completion.
 
 StreamMessage (QString content, QString sender, MessageType type, QString message_id=QString(), QWidget *parent=nullptr)
 Constructs a StreamMessage widget. Initializes UI elements (layout, text display/label/scroll area), sets up effects and animations, cleans the content, and determines the display method based on content length and type.
 
void UpdateContent (const QString &new_content)
 Updates the content of an existing message, typically used for progress updates. Cleans the new content, updates the appropriate display widget (CyberTextDisplay, CyberLongTextDisplay, or QLabel), and adjusts the widget size if necessary.
 
void UpdateScrollAreaMaxHeight () const
 Updates the maximum height constraint for the scroll area used for long messages. Limits the height to a percentage of the available screen height.
 

Static Public Member Functions

static QIcon CreateColoredSvgIcon (const QString &svg_path, const QColor &color, const QSize &size)
 Static utility function to create a QIcon from an SVG file, colored with the specified color.
 

Public Attributes

QPushButton * mark_read_button
 Button used to mark the message as read and trigger the closing animation.
 

Protected Member Functions

void focusInEvent (QFocusEvent *event) override
 Overridden focus in event handler. Slightly increases glow intensity for visual feedback.
 
void focusOutEvent (QFocusEvent *event) override
 Overridden focus out event handler. Resets glow intensity.
 
void keyPressEvent (QKeyEvent *event) override
 Overridden key press event handler. Handles Space/Enter to mark as read, and Left/Right arrows for navigation.
 
void paintEvent (QPaintEvent *event) override
 Overridden paint event handler. Draws the custom cyberpunk message bubble appearance. Renders the clipped background, neon border, glow effect, decorative lines/markers, sender text, and other AR-style elements based on the message type.
 
void resizeEvent (QResizeEvent *event) override
 Overridden resize event handler. Updates the layout of internal elements (buttons, scroll area).
 

Properties

qreal glowIntensity
 Property controlling the intensity of the border glow effect (0.0 to 1.0+). Animatable.
 
qreal opacity
 Property controlling the widget's overall opacity (0.0 to 1.0). Animatable.
 
qreal shutdownProgress
 Property controlling the progress of the electronic shutdown effect (0.0 to 1.0). Animatable.
 

Private Slots

void AdjustScrollAreaStyle () const
 Adjusts the stylesheet of the scroll area (scrollbar colors) based on the message type.
 
void UpdateAnimation ()
 Slot called by animation_timer_ to update subtle background animations (e.g., glow pulsing).
 

Private Member Functions

void CleanupContent ()
 Cleans the message content by removing HTML tags and placeholders, and decoding HTML entities. Updates the clean_content_ member variable. Applies specific formatting for long text.
 
void ProcessAudioAttachment (const QString &html)
 Helper to process audio attachments (likely superseded by AddAttachment).
 
void ProcessGifAttachment (const QString &html)
 Helper to process GIF attachments (likely superseded by AddAttachment).
 
void ProcessImageAttachment (const QString &html)
 Helper to process image attachments (likely superseded by AddAttachment).
 
void ProcessVideoAttachment (const QString &html)
 Helper to process video attachments (likely superseded by AddAttachment).
 
void StartLongMessageClosingAnimation ()
 Starts a simpler closing animation (glitch/fade) used specifically for long messages displayed in a scroll area.
 
void UpdateLayout () const
 Updates the position of the navigation and mark read buttons based on the widget's current size.
 

Static Private Member Functions

static QString ExtractAttribute (const QString &html, const QString &attribute)
 Static utility function to extract the value of an HTML attribute from a string.
 

Private Attributes

QTimer * animation_timer_
 Timer for subtle background animations.
 
QWidget * attachment_widget_ = nullptr
 Widget holding the attachment placeholder/viewer.
 
QString clean_content_
 Processed message content (plain text).
 
QString content_
 Original message content (may contain HTML).
 
QLabel * content_label_ = nullptr
 Label for displaying short text content (if no CyberTextDisplay).
 
qreal glow_intensity_
 Current glow intensity level (for animation).
 
bool is_read_
 Flag indicating if the message has been marked as read.
 
LongTextDisplayEffectlong_text_display_ = nullptr
 Widget for displaying long text within scroll area.
 
QVBoxLayout * main_layout_
 Main vertical layout.
 
QString message_id_
 Unique identifier for the message (optional).
 
QPushButton * next_button_
 Button to navigate to the next message.
 
qreal opacity_
 Current opacity level (for animation).
 
QPushButton * prev_button_
 Button to navigate to the previous message.
 
QScrollArea * scroll_area_ = nullptr
 Scroll area for long messages.
 
QString sender_
 Sender identifier.
 
ElectronicShutdownEffectshutdown_effect_ = nullptr
 Graphics effect for electronic shutdown animation.
 
qreal shutdown_progress_
 Current electronic shutdown progress.
 
TextDisplayEffecttext_display_ = nullptr
 Widget for animated text reveal (short messages).
 
MessageType type_
 Message type (Received, Transmitted, System).
 

Detailed Description

A custom widget representing a single message within the CommunicationStream.

This widget displays message content (text or attachment placeholder) with cyberpunk styling, including background, borders, glow effects, and AR-style markers. It handles different message types (Received, Transmitted, System) with distinct color schemes. It supports animations for fading in/out, disintegration, and electronic shutdown. For short messages, it uses CyberTextDisplay for a typing reveal effect. For long messages, it uses CyberLongTextDisplay within a QScrollArea. It also manages navigation buttons (Next/Previous) and a "Mark as Read" button.

Member Enumeration Documentation

◆ MessageType

Enum defining the type/origin of the message, affecting its styling.

Enumerator
kReceived 

Message received from another user (pink/purple theme).

kTransmitted 

Message sent by the current user (blue/cyan theme).

kSystem 

System notification (yellow/orange theme).

Constructor & Destructor Documentation

◆ StreamMessage()

StreamMessage::StreamMessage ( QString content,
QString sender,
MessageType type,
QString message_id = QString(),
QWidget * parent = nullptr )
explicit

Constructs a StreamMessage widget. Initializes UI elements (layout, text display/label/scroll area), sets up effects and animations, cleans the content, and determines the display method based on content length and type.

Parameters
contentThe message content (can be plain text or HTML with attachment placeholders).
senderThe identifier of the message sender ("SYSTEM" for system messages).
typeThe type of the message (Received, Transmitted, System).
message_idOptional unique identifier, used for progress updates.
parentOptional parent widget.
Here is the call graph for this function:

Member Function Documentation

◆ AddAttachment()

void StreamMessage::AddAttachment ( const QString & html)

Parses HTML content to find an attachment placeholder and adds the corresponding AttachmentPlaceholder widget. Extracts attachment details (ID, MIME type, filename) from the HTML attributes. Removes the old attachment widget if present. Adjusts message size constraints. Connects signals to handle attachment loading and size changes.

Parameters
htmlThe HTML string containing the attachment placeholder div.
Here is the call graph for this function:

◆ AdjustScrollAreaStyle

void StreamMessage::AdjustScrollAreaStyle ( ) const
privateslot

Adjusts the stylesheet of the scroll area (scrollbar colors) based on the message type.

Here is the caller graph for this function:

◆ AdjustSizeToContent()

void StreamMessage::AdjustSizeToContent ( )

Adjusts the size of the message widget to fit its content, especially after an attachment has loaded. Forces layout recalculation and calculates optimal size based on attachment dimensions, respecting screen boundaries. Updates geometry and parent layout.

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

◆ CleanupContent()

void StreamMessage::CleanupContent ( )
private

Cleans the message content by removing HTML tags and placeholders, and decoding HTML entities. Updates the clean_content_ member variable. Applies specific formatting for long text.

Here is the caller graph for this function:

◆ CreateColoredSvgIcon()

QIcon StreamMessage::CreateColoredSvgIcon ( const QString & svg_path,
const QColor & color,
const QSize & size )
static

Static utility function to create a QIcon from an SVG file, colored with the specified color.

Parameters
svg_pathPath to the SVG file.
colorThe desired color for the icon.
sizeThe desired size of the output icon pixmap.
Returns
A QIcon containing the colored pixmap, or a null QIcon on failure.
Here is the caller graph for this function:

◆ ExtractAttribute()

QString StreamMessage::ExtractAttribute ( const QString & html,
const QString & attribute )
staticprivate

Static utility function to extract the value of an HTML attribute from a string.

Parameters
htmlThe HTML string.
attributeThe name of the attribute to extract (e.g., "data-attachment-id").
Returns
The attribute's value, or an empty string if not found.
Here is the caller graph for this function:

◆ FadeIn()

void StreamMessage::FadeIn ( )

Starts the fade-in animation (opacity and glow). Also triggers the text reveal animation (CyberTextDisplay) upon completion. Sets focus.

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

◆ FadeOut()

void StreamMessage::FadeOut ( )

Starts the fade-out animation (opacity and glow). Hides the widget and emits the hidden() signal upon completion.

Here is the call graph for this function:

◆ focusInEvent()

void StreamMessage::focusInEvent ( QFocusEvent * event)
overrideprotected

Overridden focus in event handler. Slightly increases glow intensity for visual feedback.

Parameters
eventThe focus event.

◆ focusOutEvent()

void StreamMessage::focusOutEvent ( QFocusEvent * event)
overrideprotected

Overridden focus out event handler. Resets glow intensity.

Parameters
eventThe focus event.

◆ GetContent()

QString StreamMessage::GetContent ( ) const
inline

Gets the original message content (may include HTML).

◆ GetGlowIntensity()

qreal StreamMessage::GetGlowIntensity ( ) const
inline

Gets the current glow intensity level.

◆ GetMessageId()

QString StreamMessage::GetMessageId ( ) const
inline

Gets the unique message identifier (if provided).

◆ GetMessageSender()

QString StreamMessage::GetMessageSender ( ) const
inline

Gets the sender identifier.

◆ GetNextButton()

QPushButton * StreamMessage::GetNextButton ( ) const
inline

Gets a pointer to the Next navigation button.

Here is the caller graph for this function:

◆ GetOpacity()

qreal StreamMessage::GetOpacity ( ) const
inline

Gets the current opacity level.

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

◆ GetPrevButton()

QPushButton * StreamMessage::GetPrevButton ( ) const
inline

Gets a pointer to the Previous navigation button.

Here is the caller graph for this function:

◆ GetShutdownProgress()

qreal StreamMessage::GetShutdownProgress ( ) const
inline

Gets the current electronic shutdown effect progress.

◆ GetType()

MessageType StreamMessage::GetType ( ) const
inline

Gets the message type (Received, Transmitted, System).

◆ hidden

void StreamMessage::hidden ( )
signal

Emitted when the message finishes its fade-out or closing animation and becomes hidden.

Here is the caller graph for this function:

◆ IsRead()

bool StreamMessage::IsRead ( ) const
inline

Checks if the message has been marked as read.

◆ keyPressEvent()

void StreamMessage::keyPressEvent ( QKeyEvent * event)
overrideprotected

Overridden key press event handler. Handles Space/Enter to mark as read, and Left/Right arrows for navigation.

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

◆ MarkAsRead

void StreamMessage::MarkAsRead ( )
slot

Marks the message as read, triggers the appropriate closing animation (Electronic Shutdown or a simpler fade/glitch for long messages), and emits messageRead(). Prevents multiple calls.

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

◆ messageRead

void StreamMessage::messageRead ( )
signal

Emitted when the message is marked as read (MarkAsRead() is called).

Here is the caller graph for this function:

◆ paintEvent()

void StreamMessage::paintEvent ( QPaintEvent * event)
overrideprotected

Overridden paint event handler. Draws the custom cyberpunk message bubble appearance. Renders the clipped background, neon border, glow effect, decorative lines/markers, sender text, and other AR-style elements based on the message type.

Parameters
eventThe paint event.

◆ ProcessAudioAttachment()

void StreamMessage::ProcessAudioAttachment ( const QString & html)
private

Helper to process audio attachments (likely superseded by AddAttachment).

Here is the call graph for this function:

◆ ProcessGifAttachment()

void StreamMessage::ProcessGifAttachment ( const QString & html)
private

Helper to process GIF attachments (likely superseded by AddAttachment).

Here is the call graph for this function:

◆ ProcessImageAttachment()

void StreamMessage::ProcessImageAttachment ( const QString & html)
private

Helper to process image attachments (likely superseded by AddAttachment).

Here is the call graph for this function:

◆ ProcessVideoAttachment()

void StreamMessage::ProcessVideoAttachment ( const QString & html)
private

Helper to process video attachments (likely superseded by AddAttachment).

Here is the call graph for this function:

◆ resizeEvent()

void StreamMessage::resizeEvent ( QResizeEvent * event)
overrideprotected

Overridden resize event handler. Updates the layout of internal elements (buttons, scroll area).

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

◆ SetGlowIntensity()

void StreamMessage::SetGlowIntensity ( qreal intensity)

Sets the glow intensity level and triggers a repaint.

Here is the caller graph for this function:

◆ SetOpacity()

void StreamMessage::SetOpacity ( qreal opacity)

Sets the opacity level and updates the QGraphicsOpacityEffect.

◆ SetShutdownProgress()

void StreamMessage::SetShutdownProgress ( qreal progress)

Sets the electronic shutdown effect progress and updates the ElectronicShutdownEffect.

◆ ShowNavigationButtons()

void StreamMessage::ShowNavigationButtons ( bool has_previous,
bool has_next ) const

Shows or hides the navigation buttons (Next, Previous) and the Mark Read button. Updates the layout to position the buttons correctly.

Parameters
has_previousTrue to show the Previous button.
has_nextTrue to show the Next button.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sizeHint()

QSize StreamMessage::sizeHint ( ) const
override

Returns the recommended size for the widget based on its content (text length or attachment size).

Returns
The calculated QSize hint.

◆ StartLongMessageClosingAnimation()

void StreamMessage::StartLongMessageClosingAnimation ( )
private

Starts a simpler closing animation (glitch/fade) used specifically for long messages displayed in a scroll area.

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

◆ StartShutdownAnimation()

void StreamMessage::StartShutdownAnimation ( )

Starts the electronic shutdown closing animation. Applies the ElectronicShutdownEffect and animates its progress. Hides the widget and emits hidden() upon completion.

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

◆ UpdateAnimation

void StreamMessage::UpdateAnimation ( )
privateslot

Slot called by animation_timer_ to update subtle background animations (e.g., glow pulsing).

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

◆ UpdateContent()

void StreamMessage::UpdateContent ( const QString & new_content)

Updates the content of an existing message, typically used for progress updates. Cleans the new content, updates the appropriate display widget (CyberTextDisplay, CyberLongTextDisplay, or QLabel), and adjusts the widget size if necessary.

Parameters
new_contentThe updated message content.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateLayout()

void StreamMessage::UpdateLayout ( ) const
private

Updates the position of the navigation and mark read buttons based on the widget's current size.

Here is the caller graph for this function:

◆ UpdateScrollAreaMaxHeight()

void StreamMessage::UpdateScrollAreaMaxHeight ( ) const

Updates the maximum height constraint for the scroll area used for long messages. Limits the height to a percentage of the available screen height.

Here is the caller graph for this function:

Member Data Documentation

◆ animation_timer_

QTimer* StreamMessage::animation_timer_
private

Timer for subtle background animations.

◆ attachment_widget_

QWidget* StreamMessage::attachment_widget_ = nullptr
private

Widget holding the attachment placeholder/viewer.

◆ clean_content_

QString StreamMessage::clean_content_
private

Processed message content (plain text).

◆ content_

QString StreamMessage::content_
private

Original message content (may contain HTML).

◆ content_label_

QLabel* StreamMessage::content_label_ = nullptr
private

Label for displaying short text content (if no CyberTextDisplay).

◆ glow_intensity_

qreal StreamMessage::glow_intensity_
private

Current glow intensity level (for animation).

◆ is_read_

bool StreamMessage::is_read_
private

Flag indicating if the message has been marked as read.

◆ long_text_display_

LongTextDisplayEffect* StreamMessage::long_text_display_ = nullptr
private

Widget for displaying long text within scroll area.

◆ main_layout_

QVBoxLayout* StreamMessage::main_layout_
private

Main vertical layout.

◆ mark_read_button

QPushButton* StreamMessage::mark_read_button

Button used to mark the message as read and trigger the closing animation.

◆ message_id_

QString StreamMessage::message_id_
private

Unique identifier for the message (optional).

◆ next_button_

QPushButton* StreamMessage::next_button_
private

Button to navigate to the next message.

◆ opacity_

qreal StreamMessage::opacity_
private

Current opacity level (for animation).

◆ prev_button_

QPushButton* StreamMessage::prev_button_
private

Button to navigate to the previous message.

◆ scroll_area_

QScrollArea* StreamMessage::scroll_area_ = nullptr
private

Scroll area for long messages.

◆ sender_

QString StreamMessage::sender_
private

Sender identifier.

◆ shutdown_effect_

ElectronicShutdownEffect* StreamMessage::shutdown_effect_ = nullptr
private

Graphics effect for electronic shutdown animation.

◆ shutdown_progress_

qreal StreamMessage::shutdown_progress_
private

Current electronic shutdown progress.

◆ text_display_

TextDisplayEffect* StreamMessage::text_display_ = nullptr
private

Widget for animated text reveal (short messages).

◆ type_

MessageType StreamMessage::type_
private

Message type (Received, Transmitted, System).

Property Documentation

◆ glowIntensity

qreal StreamMessage::glowIntensity
readwrite

Property controlling the intensity of the border glow effect (0.0 to 1.0+). Animatable.

◆ opacity

qreal StreamMessage::opacity
readwrite

Property controlling the widget's overall opacity (0.0 to 1.0). Animatable.

◆ shutdownProgress

qreal StreamMessage::shutdownProgress
readwrite

Property controlling the progress of the electronic shutdown effect (0.0 to 1.0). Animatable.


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