A custom widget that displays text with cyberpunk terminal-style "typing" reveal animation and glitch effects.
More...
#include <text_display_effect.h>
|
| qreal | GetGlitchIntensity () const |
| | Gets the current intensity of the glitch effect.
|
| |
| int | GetRevealedChars () const |
| | Gets the current number of revealed characters.
|
| |
| void | SetGlitchEffectEnabled (bool enabled) |
| | Enables or disables the random glitch effect timer. When disabled, it also resets the glitch intensity to 0.
|
| |
| void | SetGlitchIntensity (qreal intensity) |
| | Sets the intensity of the glitch effect. Updates the internal intensity value and triggers a repaint.
|
| |
| void | SetRevealedChars (int chars) |
| | Sets the number of revealed characters. Updates the internal count, triggers a repaint, and emits fullTextRevealed if the text becomes fully revealed.
|
| |
| void | SetText (const QString &new_text) |
| | Sets new text content for the widget. Updates the internal text, removes HTML, recalculates required height, resets the reveal state, and starts the reveal animation for the new text.
|
| |
| QSize | sizeHint () const override |
| | Returns the recommended size for the widget based on the calculated height of the text content.
|
| |
| void | StartReveal () |
| | Starts or restarts the text revealing animation from the beginning. If the text has been fully revealed once, it instantly shows the full text. Otherwise, resets the revealed character count and starts the text reveal timer and typing sound.
|
| |
| | 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 reveal and glitch effects, loads the monospace font, initializes the media player for typing sounds, and calculates initial height.
|
| |
| | ~TextDisplayEffect () override |
| | Destructor. Stops the media player if it's playing.
|
| |
|
| void | hideEvent (QHideEvent *event) override |
| | Overridden hide event handler. Stops the typing sound and timers when the widget is hidden.
|
| |
| void | paintEvent (QPaintEvent *event) override |
| | Overridden paint event handler. Draws the widget's appearance. Renders the background gradient, the revealed portion of the text with character-by-character coloring, the pulsing cursor, and the scanline effect. Applies glitch effects if intensity > 0.
|
| |
| void | resizeEvent (QResizeEvent *event) override |
| | Overridden resize event handler. Recalculates the required height based on the new width.
|
| |
|
| qreal | glitchIntensity |
| | Property controlling the intensity of the visual glitch effect (0.0 to 1.0+). Animatable.
|
| |
| int | revealedChars |
| | Property controlling the number of characters currently revealed in the typing animation. Animatable.
|
| |
|
| void | HandleFullTextRevealed () const |
| | Slot connected to the fullTextRevealed signal. Stops the text reveal timer and typing sound.
|
| |
| void | RandomGlitch () |
| | Slot called by the glitch_timer_. Randomly triggers a glitch effect or fades the current intensity.
|
| |
| void | RevealNextChar () |
| | Slot called by the text_timer_. Reveals the next character in the sequence. Adjusts the timer interval for pauses after spaces/newlines. Randomly triggers glitches.
|
| |
| void | TriggerGlitch () |
| | Initiates a short, animated glitch effect by animating the glitchIntensity property.
|
| |
|
| void | RecalculateHeight () |
| | Recalculates the required height for the widget based on the plain_text_ content and current width. Performs basic word wrapping and updates the widget's minimum height.
|
| |
|
| static QString | RemoveHtml (const QString &html) |
| | Static utility function to remove basic HTML tags and decode common entities from a string.
|
| |
|
| QAudioOutput * | audio_output_ |
| | Audio output handler (potentially unused if QMediaPlayer handles output directly).
|
| |
| QFont | font_ |
| | The monospace font used for rendering.
|
| |
| QString | full_text_ |
| | The original text content, potentially including HTML.
|
| |
| qreal | glitch_intensity_ |
| | The current intensity level of the visual glitch effect.
|
| |
| QTimer * | glitch_timer_ |
| | Timer controlling the random triggering and fading of glitch effects.
|
| |
| bool | has_been_fully_revealed_once_ |
| | Flag indicating if the text has completed its reveal animation at least once since the last SetText().
|
| |
| bool | is_fully_revealed_ |
| | Flag indicating if the text is currently fully revealed.
|
| |
| QMediaPlayer * | media_player_ |
| | Media player responsible for playing the typing sound effect.
|
| |
| QString | plain_text_ |
| | The processed text content with HTML removed and potentially word-wrapped by RecalculateHeight.
|
| |
| QMediaPlaylist * | playlist_ |
| | Playlist used to loop the typing sound effect in the media player.
|
| |
| int | revealed_chars_ |
| | The number of characters currently visible in the reveal animation.
|
| |
| TypingSoundType | sound_type_ |
| | The selected type of typing sound effect (determines the audio file used).
|
| |
| QTimer * | text_timer_ |
| | Timer controlling the character-by-character reveal animation.
|
| |
A custom widget that displays text with cyberpunk terminal-style "typing" reveal animation and glitch effects.
This widget simulates text being typed out character by character, accompanied by an optional typing sound effect. It also features random visual "glitch" effects and a pulsing cursor. The text is rendered with a monospace font and neon colors against a gradient background with scanlines. It handles HTML removal from the input text and recalculates its required height based on content and width.
◆ TypingSoundType
Enum defining the type of typing sound effect to use.
| Enumerator |
|---|
| kSystemSound | Use the system/alternative typing sound (terminal_typing2.wav).
|
| kUserSound | Use the default user typing sound (terminal_typing1.wav).
|
◆ TextDisplayEffect()
| TextDisplayEffect::TextDisplayEffect |
( |
const QString & | text, |
|
|
TypingSoundType | sound_type = kUserSound, |
|
|
QWidget * | parent = nullptr ) |
|
explicit |
Constructs a CyberTextDisplay widget. Initializes the widget with text, sets up timers for text reveal and glitch effects, loads the monospace font, initializes the media player for typing sounds, and calculates initial height.
- Parameters
-
| text | The initial text content (can include basic HTML for formatting, which will be stripped for display). |
| sound_type | The type of typing sounds to use (defaults to kUserSound). |
| parent | Optional parent widget. |
◆ ~TextDisplayEffect()
| TextDisplayEffect::~TextDisplayEffect |
( |
| ) |
|
|
override |
Destructor. Stops the media player if it's playing.
◆ fullTextRevealed
| void TextDisplayEffect::fullTextRevealed |
( |
| ) |
|
|
signal |
Emitted exactly once when the text revealing animation completes for the first time after StartReveal() or SetText() is called.
◆ GetGlitchIntensity()
| qreal TextDisplayEffect::GetGlitchIntensity |
( |
| ) |
const |
|
inline |
Gets the current intensity of the glitch effect.
- Returns
- The glitch intensity value (typically 0.0 to 1.0+).
◆ GetRevealedChars()
| int TextDisplayEffect::GetRevealedChars |
( |
| ) |
const |
|
inline |
Gets the current number of revealed characters.
- Returns
- The count of revealed characters.
◆ HandleFullTextRevealed
| void TextDisplayEffect::HandleFullTextRevealed |
( |
| ) |
const |
|
privateslot |
Slot connected to the fullTextRevealed signal. Stops the text reveal timer and typing sound.
◆ hideEvent()
| void TextDisplayEffect::hideEvent |
( |
QHideEvent * | event | ) |
|
|
overrideprotected |
Overridden hide event handler. Stops the typing sound and timers when the widget is hidden.
- Parameters
-
◆ paintEvent()
| void TextDisplayEffect::paintEvent |
( |
QPaintEvent * | event | ) |
|
|
overrideprotected |
Overridden paint event handler. Draws the widget's appearance. Renders the background gradient, the revealed portion of the text with character-by-character coloring, the pulsing cursor, and the scanline effect. Applies glitch effects if intensity > 0.
- Parameters
-
◆ RandomGlitch
| void TextDisplayEffect::RandomGlitch |
( |
| ) |
|
|
privateslot |
Slot called by the glitch_timer_. Randomly triggers a glitch effect or fades the current intensity.
◆ RecalculateHeight()
| void TextDisplayEffect::RecalculateHeight |
( |
| ) |
|
|
private |
Recalculates the required height for the widget based on the plain_text_ content and current width. Performs basic word wrapping and updates the widget's minimum height.
◆ RemoveHtml()
| QString TextDisplayEffect::RemoveHtml |
( |
const QString & | html | ) |
|
|
staticprivate |
Static utility function to remove basic HTML tags and decode common entities from a string.
- Parameters
-
| html | The input string potentially containing HTML. |
- Returns
- The plain text string.
◆ resizeEvent()
| void TextDisplayEffect::resizeEvent |
( |
QResizeEvent * | event | ) |
|
|
overrideprotected |
Overridden resize event handler. Recalculates the required height based on the new width.
- Parameters
-
◆ RevealNextChar
| void TextDisplayEffect::RevealNextChar |
( |
| ) |
|
|
privateslot |
Slot called by the text_timer_. Reveals the next character in the sequence. Adjusts the timer interval for pauses after spaces/newlines. Randomly triggers glitches.
◆ SetGlitchEffectEnabled()
| void TextDisplayEffect::SetGlitchEffectEnabled |
( |
bool | enabled | ) |
|
Enables or disables the random glitch effect timer. When disabled, it also resets the glitch intensity to 0.
- Parameters
-
| enabled | True to enable the glitch timer, false to disable it. |
◆ SetGlitchIntensity()
| void TextDisplayEffect::SetGlitchIntensity |
( |
qreal | intensity | ) |
|
Sets the intensity of the glitch effect. Updates the internal intensity value and triggers a repaint.
- Parameters
-
| intensity | The desired glitch intensity. |
◆ SetRevealedChars()
| void TextDisplayEffect::SetRevealedChars |
( |
int | chars | ) |
|
Sets the number of revealed characters. Updates the internal count, triggers a repaint, and emits fullTextRevealed if the text becomes fully revealed.
- Parameters
-
| chars | The desired number of revealed characters (clamped to text length). |
◆ SetText()
| void TextDisplayEffect::SetText |
( |
const QString & | new_text | ) |
|
Sets new text content for the widget. Updates the internal text, removes HTML, recalculates required height, resets the reveal state, and starts the reveal animation for the new text.
- Parameters
-
| new_text | The new text content. |
◆ sizeHint()
| QSize TextDisplayEffect::sizeHint |
( |
| ) |
const |
|
override |
Returns the recommended size for the widget based on the calculated height of the text content.
- Returns
- The calculated QSize hint.
◆ StartReveal()
| void TextDisplayEffect::StartReveal |
( |
| ) |
|
Starts or restarts the text revealing animation from the beginning. If the text has been fully revealed once, it instantly shows the full text. Otherwise, resets the revealed character count and starts the text reveal timer and typing sound.
◆ TriggerGlitch
| void TextDisplayEffect::TriggerGlitch |
( |
| ) |
|
|
privateslot |
Initiates a short, animated glitch effect by animating the glitchIntensity property.
◆ audio_output_
| QAudioOutput* TextDisplayEffect::audio_output_ |
|
private |
Audio output handler (potentially unused if QMediaPlayer handles output directly).
◆ font_
| QFont TextDisplayEffect::font_ |
|
private |
The monospace font used for rendering.
◆ full_text_
| QString TextDisplayEffect::full_text_ |
|
private |
The original text content, potentially including HTML.
◆ glitch_intensity_
| qreal TextDisplayEffect::glitch_intensity_ |
|
private |
The current intensity level of the visual glitch effect.
◆ glitch_timer_
| QTimer* TextDisplayEffect::glitch_timer_ |
|
private |
Timer controlling the random triggering and fading of glitch effects.
◆ has_been_fully_revealed_once_
| bool TextDisplayEffect::has_been_fully_revealed_once_ |
|
private |
Flag indicating if the text has completed its reveal animation at least once since the last SetText().
◆ is_fully_revealed_
| bool TextDisplayEffect::is_fully_revealed_ |
|
private |
Flag indicating if the text is currently fully revealed.
◆ media_player_
| QMediaPlayer* TextDisplayEffect::media_player_ |
|
private |
Media player responsible for playing the typing sound effect.
◆ plain_text_
| QString TextDisplayEffect::plain_text_ |
|
private |
The processed text content with HTML removed and potentially word-wrapped by RecalculateHeight.
◆ playlist_
| QMediaPlaylist* TextDisplayEffect::playlist_ |
|
private |
Playlist used to loop the typing sound effect in the media player.
◆ revealed_chars_
| int TextDisplayEffect::revealed_chars_ |
|
private |
The number of characters currently visible in the reveal animation.
◆ sound_type_
The selected type of typing sound effect (determines the audio file used).
◆ text_timer_
| QTimer* TextDisplayEffect::text_timer_ |
|
private |
Timer controlling the character-by-character reveal animation.
◆ glitchIntensity
| qreal TextDisplayEffect::glitchIntensity |
|
readwrite |
Property controlling the intensity of the visual glitch effect (0.0 to 1.0+). Animatable.
◆ revealedChars
| int TextDisplayEffect::revealedChars |
|
readwrite |
Property controlling the number of characters currently revealed in the typing animation. Animatable.
The documentation for this class was generated from the following files: