Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
stream_message.h
Go to the documentation of this file.
1#ifndef STREAM_MESSAGE_H
2#define STREAM_MESSAGE_H
3
4#include <QWidget>
5
8class QScrollArea;
10class QLabel;
11class QVBoxLayout;
12class QPushButton;
14
26class StreamMessage final : public QWidget {
27 Q_OBJECT
29 Q_PROPERTY(qreal opacity READ GetOpacity WRITE SetOpacity)
31 Q_PROPERTY(qreal glowIntensity READ GetGlowIntensity WRITE SetGlowIntensity)
34
35public:
44
45 Q_ENUM(MessageType)
46
47
48 QPushButton *mark_read_button;
49
57 static QIcon CreateColoredSvgIcon(const QString &svg_path, const QColor &color, const QSize &size);
58
69 explicit StreamMessage(QString content, QString sender, MessageType type, QString message_id = QString(),
70 QWidget *parent = nullptr);
71
78 void UpdateContent(const QString &new_content);
79
81 qreal GetOpacity() const { return opacity_; }
82
84 void SetOpacity(qreal opacity);
85
87 qreal GetGlowIntensity() const { return glow_intensity_; }
88
90 void SetGlowIntensity(qreal intensity);
91
93 qreal GetShutdownProgress() const { return shutdown_progress_; }
94
96 void SetShutdownProgress(qreal progress);
97
99 bool IsRead() const { return is_read_; }
101 QString GetMessageSender() const { return sender_; }
103 QString GetContent() const { return content_; }
105 MessageType GetType() const { return type_; }
107 QString GetMessageId() const { return message_id_; }
108
116 void AddAttachment(const QString &html);
117
123 void AdjustSizeToContent();
124
129 QSize sizeHint() const override;
130
135 void FadeIn();
136
141 void FadeOut();
142
147 void UpdateScrollAreaMaxHeight() const;
148
155
162 void ShowNavigationButtons(bool has_previous, bool has_next) const;
163
165 QPushButton *GetNextButton() const { return next_button_; }
167 QPushButton *GetPrevButton() const { return prev_button_; }
168
169signals:
172
174 void hidden();
175
176public slots:
182 void MarkAsRead();
183
184protected:
191 void paintEvent(QPaintEvent *event) override;
192
197 void resizeEvent(QResizeEvent *event) override;
198
203 void keyPressEvent(QKeyEvent *event) override;
204
209 void focusInEvent(QFocusEvent *event) override;
210
215 void focusOutEvent(QFocusEvent *event) override;
216
217private slots:
221 void UpdateAnimation();
222
226 void AdjustScrollAreaStyle() const;
227
228private:
235 static QString ExtractAttribute(const QString &html, const QString &attribute);
236
241
243 void ProcessImageAttachment(const QString &html);
244
246 void ProcessGifAttachment(const QString &html);
247
249 void ProcessAudioAttachment(const QString &html);
250
252 void ProcessVideoAttachment(const QString &html);
253
258 void CleanupContent();
259
263 void UpdateLayout() const;
264
265 QString message_id_;
266 QString content_;
268 QString sender_;
270 qreal opacity_;
273 bool is_read_;
274
275 QVBoxLayout *main_layout_;
276 QPushButton *next_button_;
277 QPushButton *prev_button_;
279 QWidget *attachment_widget_ = nullptr;
280 QLabel *content_label_ = nullptr;
282 QScrollArea *scroll_area_ = nullptr;
285};
286
287#endif // STREAM_MESSAGE_H
A widget that displays another widget (content) with a cyberpunk-themed decryption animation.
Definition attachment_viewer.h:25
A QGraphicsEffect that simulates an old CRT monitor or electronic device shutting down.
Definition electronic_shutdown_effect.h:18
A custom widget for displaying potentially long text with cyberpunk aesthetics and efficient renderin...
Definition long_text_display_effect.h:15
void UpdateContent(const QString &new_content)
Updates the content of an existing message, typically used for progress updates. Cleans the new conte...
Definition stream_message.cpp:175
QString content_
Original message content (may contain HTML).
Definition stream_message.h:266
void UpdateScrollAreaMaxHeight() const
Updates the maximum height constraint for the scroll area used for long messages. Limits the height t...
Definition stream_message.cpp:447
ElectronicShutdownEffect * shutdown_effect_
Graphics effect for electronic shutdown animation.
Definition stream_message.h:284
void SetGlowIntensity(qreal intensity)
Sets the glow intensity level and triggers a repaint.
Definition stream_message.cpp:197
QWidget * attachment_widget_
Widget holding the attachment placeholder/viewer.
Definition stream_message.h:279
void keyPressEvent(QKeyEvent *event) override
Overridden key press event handler. Handles Space/Enter to mark as read, and Left/Right arrows for na...
Definition stream_message.cpp:664
void AdjustSizeToContent()
Adjusts the size of the message widget to fit its content, especially after an attachment has loaded....
Definition stream_message.cpp:289
QString sender_
Sender identifier.
Definition stream_message.h:268
qreal opacity
Property controlling the widget's overall opacity (0.0 to 1.0). Animatable.
Definition stream_message.h:29
QString GetContent() const
Gets the original message content (may include HTML).
Definition stream_message.h:103
void FadeIn()
Starts the fade-in animation (opacity and glow). Also triggers the text reveal animation (CyberTextDi...
Definition stream_message.cpp:389
bool is_read_
Flag indicating if the message has been marked as read.
Definition stream_message.h:273
qreal glowIntensity
Property controlling the intensity of the border glow effect (0.0 to 1.0+). Animatable.
Definition stream_message.h:31
LongTextDisplayEffect * long_text_display_
Widget for displaying long text within scroll area.
Definition stream_message.h:283
void ProcessAudioAttachment(const QString &html)
Helper to process audio attachments (likely superseded by AddAttachment).
Definition stream_message.cpp:818
QString clean_content_
Processed message content (plain text).
Definition stream_message.h:267
QVBoxLayout * main_layout_
Main vertical layout.
Definition stream_message.h:275
void paintEvent(QPaintEvent *event) override
Overridden paint event handler. Draws the custom cyberpunk message bubble appearance....
Definition stream_message.cpp:514
void ProcessGifAttachment(const QString &html)
Helper to process GIF attachments (likely superseded by AddAttachment).
Definition stream_message.cpp:797
MessageType
Enum defining the type/origin of the message, affecting its styling.
Definition stream_message.h:39
@ kSystem
System notification (yellow/orange theme).
Definition stream_message.h:42
@ kTransmitted
Message sent by the current user (blue/cyan theme).
Definition stream_message.h:41
@ kReceived
Message received from another user (pink/purple theme).
Definition stream_message.h:40
void UpdateLayout() const
Updates the position of the navigation and mark read buttons based on the widget's current size.
Definition stream_message.cpp:896
void StartLongMessageClosingAnimation()
Starts a simpler closing animation (glitch/fade) used specifically for long messages displayed in a s...
Definition stream_message.cpp:745
void resizeEvent(QResizeEvent *event) override
Overridden resize event handler. Updates the layout of internal elements (buttons,...
Definition stream_message.cpp:652
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.
Definition stream_message.cpp:908
void focusOutEvent(QFocusEvent *event) override
Overridden focus out event handler. Resets glow intensity.
Definition stream_message.cpp:685
void CleanupContent()
Cleans the message content by removing HTML tags and placeholders, and decoding HTML entities....
Definition stream_message.cpp:860
qreal shutdown_progress_
Current electronic shutdown progress.
Definition stream_message.h:272
qreal shutdownProgress
Property controlling the progress of the electronic shutdown effect (0.0 to 1.0). Animatable.
Definition stream_message.h:33
qreal opacity_
Current opacity level (for animation).
Definition stream_message.h:270
qreal GetOpacity() const
Gets the current opacity level.
Definition stream_message.h:81
MessageType GetType() const
Gets the message type (Received, Transmitted, System).
Definition stream_message.h:105
static QString ExtractAttribute(const QString &html, const QString &attribute)
Static utility function to extract the value of an HTML attribute from a string.
Definition stream_message.cpp:733
void focusInEvent(QFocusEvent *event) override
Overridden focus in event handler. Slightly increases glow intensity for visual feedback.
Definition stream_message.cpp:679
QTimer * animation_timer_
Timer for subtle background animations.
Definition stream_message.h:278
QString GetMessageSender() const
Gets the sender identifier.
Definition stream_message.h:101
void StartShutdownAnimation()
Starts the electronic shutdown closing animation. Applies the ElectronicShutdownEffect and animates i...
Definition stream_message.cpp:465
void ProcessVideoAttachment(const QString &html)
Helper to process video attachments (likely superseded by AddAttachment).
Definition stream_message.cpp:839
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),...
Definition stream_message.cpp:30
qreal GetShutdownProgress() const
Gets the current electronic shutdown effect progress.
Definition stream_message.h:93
qreal glow_intensity_
Current glow intensity level (for animation).
Definition stream_message.h:271
void hidden()
Emitted when the message finishes its fade-out or closing animation and becomes hidden.
void AdjustScrollAreaStyle() const
Adjusts the stylesheet of the scroll area (scrollbar colors) based on the message type.
Definition stream_message.cpp:696
void SetOpacity(qreal opacity)
Sets the opacity level and updates the QGraphicsOpacityEffect.
Definition stream_message.cpp:190
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 t...
Definition stream_message.cpp:488
QPushButton * next_button_
Button to navigate to the next message.
Definition stream_message.h:276
void AddAttachment(const QString &html)
Parses HTML content to find an attachment placeholder and adds the corresponding AttachmentPlaceholde...
Definition stream_message.cpp:210
void FadeOut()
Starts the fade-out animation (opacity and glow). Hides the widget and emits the hidden() signal upon...
Definition stream_message.cpp:420
QPushButton * prev_button_
Button to navigate to the previous message.
Definition stream_message.h:277
MessageType type_
Message type (Received, Transmitted, System).
Definition stream_message.h:269
void messageRead()
Emitted when the message is marked as read (MarkAsRead() is called).
QScrollArea * scroll_area_
Scroll area for long messages.
Definition stream_message.h:282
void UpdateAnimation()
Slot called by animation_timer_ to update subtle background animations (e.g., glow pulsing).
Definition stream_message.cpp:691
qreal GetGlowIntensity() const
Gets the current glow intensity level.
Definition stream_message.h:87
QPushButton * GetPrevButton() const
Gets a pointer to the Previous navigation button.
Definition stream_message.h:167
void SetShutdownProgress(qreal progress)
Sets the electronic shutdown effect progress and updates the ElectronicShutdownEffect.
Definition stream_message.cpp:203
QPushButton * mark_read_button
Button used to mark the message as read and trigger the closing animation.
Definition stream_message.h:48
void MarkAsRead()
Marks the message as read, triggers the appropriate closing animation (Electronic Shutdown or a simpl...
Definition stream_message.cpp:500
QPushButton * GetNextButton() const
Gets a pointer to the Next navigation button.
Definition stream_message.h:165
void ProcessImageAttachment(const QString &html)
Helper to process image attachments (likely superseded by AddAttachment).
Definition stream_message.cpp:776
bool IsRead() const
Checks if the message has been marked as read.
Definition stream_message.h:99
QSize sizeHint() const override
Returns the recommended size for the widget based on its content (text length or attachment size).
Definition stream_message.cpp:351
QLabel * content_label_
Label for displaying short text content (if no CyberTextDisplay).
Definition stream_message.h:280
QString GetMessageId() const
Gets the unique message identifier (if provided).
Definition stream_message.h:107
QString message_id_
Unique identifier for the message (optional).
Definition stream_message.h:265
TextDisplayEffect * text_display_
Widget for animated text reveal (short messages).
Definition stream_message.h:281
A custom widget that displays text with cyberpunk terminal-style "typing" reveal animation and glitch...
Definition text_display_effect.h:18