Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
text_display_effect.h
Go to the documentation of this file.
1#ifndef CYBER_TEXT_DISPLAY_H
2#define CYBER_TEXT_DISPLAY_H
3
4#include <QWidget>
5
6class QMediaPlaylist;
7class QAudioOutput;
8class QMediaPlayer;
9
18class TextDisplayEffect final : public QWidget {
19 Q_OBJECT
24
25public:
33
34 Q_ENUM(TypingSoundType)
35
36
44 explicit TextDisplayEffect(const QString &text, TypingSoundType sound_type = kUserSound, QWidget *parent = nullptr);
45
49 ~TextDisplayEffect() override;
50
56 void StartReveal();
57
64 void SetText(const QString &new_text);
65
70 int GetRevealedChars() const { return revealed_chars_; }
71
77 void SetRevealedChars(int chars);
78
83 qreal GetGlitchIntensity() const { return glitch_intensity_; }
84
90 void SetGlitchIntensity(qreal intensity);
91
97 void SetGlitchEffectEnabled(bool enabled);
98
103 QSize sizeHint() const override;
104
105signals:
111
112protected:
119 void paintEvent(QPaintEvent *event) override;
120
125 void resizeEvent(QResizeEvent *event) override;
126
131 void hideEvent(QHideEvent *event) override;
132
133private slots:
137 void HandleFullTextRevealed() const;
138
143 void RevealNextChar();
144
148 void RandomGlitch();
149
153 void TriggerGlitch();
154
155private:
161 static QString RemoveHtml(const QString &html);
162
167 void RecalculateHeight();
168
170 QString full_text_;
172 QString plain_text_;
180 QFont font_;
182 QTimer *text_timer_;
188 QMediaPlayer *media_player_;
190 QAudioOutput *audio_output_;
192 QMediaPlaylist *playlist_;
195};
196
197#endif // CYBER_TEXT_DISPLAY_H
QFont font_
The monospace font used for rendering.
Definition text_display_effect.h:180
qreal glitchIntensity
Property controlling the intensity of the visual glitch effect (0.0 to 1.0+). Animatable.
Definition text_display_effect.h:23
void SetText(const QString &new_text)
Sets new text content for the widget. Updates the internal text, removes HTML, recalculates required ...
Definition text_display_effect.cpp:108
QTimer * text_timer_
Timer controlling the character-by-character reveal animation.
Definition text_display_effect.h:182
void RecalculateHeight()
Recalculates the required height for the widget based on the plain_text_ content and current width....
Definition text_display_effect.cpp:306
static QString RemoveHtml(const QString &html)
Static utility function to remove basic HTML tags and decode common entities from a string.
Definition text_display_effect.cpp:292
QString full_text_
The original text content, potentially including HTML.
Definition text_display_effect.h:170
TypingSoundType sound_type_
The selected type of typing sound effect (determines the audio file used).
Definition text_display_effect.h:194
QMediaPlayer * media_player_
Media player responsible for playing the typing sound effect.
Definition text_display_effect.h:188
void hideEvent(QHideEvent *event) override
Overridden hide event handler. Stops the typing sound and timers when the widget is hidden.
Definition text_display_effect.cpp:234
void resizeEvent(QResizeEvent *event) override
Overridden resize event handler. Recalculates the required height based on the new width.
Definition text_display_effect.cpp:229
bool has_been_fully_revealed_once_
Flag indicating if the text has completed its reveal animation at least once since the last SetText()...
Definition text_display_effect.h:186
bool is_fully_revealed_
Flag indicating if the text is currently fully revealed.
Definition text_display_effect.h:178
QSize sizeHint() const override
Returns the recommended size for the widget based on the calculated height of the text content.
Definition text_display_effect.cpp:146
QTimer * glitch_timer_
Timer controlling the random triggering and fading of glitch effects.
Definition text_display_effect.h:184
int revealed_chars_
The number of characters currently visible in the reveal animation.
Definition text_display_effect.h:174
TypingSoundType
Enum defining the type of typing sound effect to use.
Definition text_display_effect.h:29
@ kUserSound
Use the default user typing sound (terminal_typing1.wav).
Definition text_display_effect.h:31
@ kSystemSound
Use the system/alternative typing sound (terminal_typing2.wav).
Definition text_display_effect.h:30
void SetRevealedChars(int chars)
Sets the number of revealed characters. Updates the internal count, triggers a repaint,...
Definition text_display_effect.cpp:116
QMediaPlaylist * playlist_
Playlist used to loop the typing sound effect in the media player.
Definition text_display_effect.h:192
void SetGlitchEffectEnabled(bool enabled)
Enables or disables the random glitch effect timer. When disabled, it also resets the glitch intensit...
Definition text_display_effect.cpp:136
int revealedChars
Property controlling the number of characters currently revealed in the typing animation....
Definition text_display_effect.h:21
TextDisplayEffect(const QString &text, TypingSoundType sound_type=kUserSound, QWidget *parent=nullptr)
Constructs a CyberTextDisplay widget. Initializes the widget with text, sets up timers for text revea...
Definition text_display_effect.cpp:12
QAudioOutput * audio_output_
Audio output handler (potentially unused if QMediaPlayer handles output directly).
Definition text_display_effect.h:190
void TriggerGlitch()
Initiates a short, animated glitch effect by animating the glitchIntensity property.
Definition text_display_effect.cpp:283
void HandleFullTextRevealed() const
Slot connected to the fullTextRevealed signal. Stops the text reveal timer and typing sound.
Definition text_display_effect.cpp:243
qreal GetGlitchIntensity() const
Gets the current intensity of the glitch effect.
Definition text_display_effect.h:83
QString plain_text_
The processed text content with HTML removed and potentially word-wrapped by RecalculateHeight.
Definition text_display_effect.h:172
void paintEvent(QPaintEvent *event) override
Overridden paint event handler. Draws the widget's appearance. Renders the background gradient,...
Definition text_display_effect.cpp:153
void StartReveal()
Starts or restarts the text revealing animation from the beginning. If the text has been fully reveal...
Definition text_display_effect.cpp:83
~TextDisplayEffect() override
Destructor. Stops the media player if it's playing.
Definition text_display_effect.cpp:77
int GetRevealedChars() const
Gets the current number of revealed characters.
Definition text_display_effect.h:70
void fullTextRevealed()
Emitted exactly once when the text revealing animation completes for the first time after StartReveal...
void SetGlitchIntensity(qreal intensity)
Sets the intensity of the glitch effect. Updates the internal intensity value and triggers a repaint.
Definition text_display_effect.cpp:131
qreal glitch_intensity_
The current intensity level of the visual glitch effect.
Definition text_display_effect.h:176
void RandomGlitch()
Slot called by the glitch_timer_. Randomly triggers a glitch effect or fades the current intensity.
Definition text_display_effect.cpp:273
void RevealNextChar()
Slot called by the text_timer_. Reveals the next character in the sequence. Adjusts the timer interva...
Definition text_display_effect.cpp:256