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

A custom widget for displaying potentially long text with cyberpunk aesthetics and efficient rendering. More...

#include <long_text_display_effect.h>

Inheritance diagram for LongTextDisplayEffect:
Collaboration diagram for LongTextDisplayEffect:

Signals

void contentHeightChanged (int new_height)
 Emitted after ProcessText() finishes, indicating the total calculated height required to display all the processed lines.
 

Public Member Functions

 LongTextDisplayEffect (QString text, const QColor &text_color, QWidget *parent=nullptr)
 Constructs a CyberLongTextDisplay widget. Initializes the widget with default size policies, font, text color, and sets up a timer for delayed text processing.
 
QSize minimumSizeHint () const override
 
void SetScrollPosition (int position)
 Sets the vertical scroll position. This determines which part of the processed text is rendered in the paintEvent. Schedules a repaint if the position changes.
 
void SetText (const QString &text)
 Sets the text content to be displayed. Updates the internal original text, invalidates the processed text cache, triggers delayed processing, and schedules a repaint.
 
void SetTextColor (const QColor &color)
 Sets the color for the displayed text. Updates the internal text color and schedules a repaint.
 
QSize sizeHint () const override
 Returns the recommended size for the widget based on the processed text content. The height is calculated based on the number of processed lines and font metrics. The width is calculated based on the longest processed line.
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 Overridden paint event handler. Draws the widget's appearance. Ensures the text is processed, draws the background gradient, renders the visible lines of the processed text based on the scroll position, and applies a scanline effect.
 
void resizeEvent (QResizeEvent *event) override
 Overridden resize event handler. Invalidates the processed text cache and triggers delayed text processing when the widget's size changes.
 

Private Member Functions

void ProcessText ()
 Processes the original_text_ into wrapped lines based on the current widget width. Splits the text into paragraphs and words, then reconstructs lines ensuring they fit within the available width. Handles word wrapping and breaking long words. Updates the processed_lines_ cache, calculates the required dimensions (width and height), updates the size_hint_, marks the cache as valid, and emits contentHeightChanged.
 

Private Attributes

bool cached_text_valid_
 Flag indicating if the processed_lines_ cache is up to date with the original_text_ and widget width.
 
QFont font_
 The font used for rendering text and calculating metrics.
 
QString original_text_
 The original, unprocessed text content set via constructor or SetText().
 
QStringList processed_lines_
 List of strings representing the text after processing (line wrapping).
 
int scroll_position_
 Current vertical scroll position in pixels.
 
QSize size_hint_
 Cached size hint calculated based on processed text dimensions.
 
QColor text_color_
 The color used to render the text.
 
QTimer * update_timer_ {}
 Timer used to delay text processing after resize or text change events.
 

Detailed Description

A custom widget for displaying potentially long text with cyberpunk aesthetics and efficient rendering.

This widget takes a long string, processes it by wrapping lines based on the widget's width, and renders only the visible portion of the text. It includes a cyberpunk-style background gradient and scanline effect. Text processing is delayed and cached to avoid excessive recalculations during resizing. It supports vertical scrolling via the SetScrollPosition method and emits a signal indicating the total required height for the content.

Constructor & Destructor Documentation

◆ LongTextDisplayEffect()

LongTextDisplayEffect::LongTextDisplayEffect ( QString text,
const QColor & text_color,
QWidget * parent = nullptr )
explicit

Constructs a CyberLongTextDisplay widget. Initializes the widget with default size policies, font, text color, and sets up a timer for delayed text processing.

Parameters
textThe initial text content to display.
text_colorThe color for the displayed text.
parentOptional parent widget.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ contentHeightChanged

void LongTextDisplayEffect::contentHeightChanged ( int new_height)
signal

Emitted after ProcessText() finishes, indicating the total calculated height required to display all the processed lines.

Parameters
new_heightThe total content height in pixels.
Here is the caller graph for this function:

◆ minimumSizeHint()

QSize LongTextDisplayEffect::minimumSizeHint ( ) const
nodiscardoverride
Here is the call graph for this function:

◆ paintEvent()

void LongTextDisplayEffect::paintEvent ( QPaintEvent * event)
overrideprotected

Overridden paint event handler. Draws the widget's appearance. Ensures the text is processed, draws the background gradient, renders the visible lines of the processed text based on the scroll position, and applies a scanline effect.

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

◆ ProcessText()

void LongTextDisplayEffect::ProcessText ( )
private

Processes the original_text_ into wrapped lines based on the current widget width. Splits the text into paragraphs and words, then reconstructs lines ensuring they fit within the available width. Handles word wrapping and breaking long words. Updates the processed_lines_ cache, calculates the required dimensions (width and height), updates the size_hint_, marks the cache as valid, and emits contentHeightChanged.

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

◆ resizeEvent()

void LongTextDisplayEffect::resizeEvent ( QResizeEvent * event)
overrideprotected

Overridden resize event handler. Invalidates the processed text cache and triggers delayed text processing when the widget's size changes.

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

◆ SetScrollPosition()

void LongTextDisplayEffect::SetScrollPosition ( int position)

Sets the vertical scroll position. This determines which part of the processed text is rendered in the paintEvent. Schedules a repaint if the position changes.

Parameters
positionThe vertical scroll position in pixels.
Here is the caller graph for this function:

◆ SetText()

void LongTextDisplayEffect::SetText ( const QString & text)

Sets the text content to be displayed. Updates the internal original text, invalidates the processed text cache, triggers delayed processing, and schedules a repaint.

Parameters
textThe new text content.
Here is the call graph for this function:

◆ SetTextColor()

void LongTextDisplayEffect::SetTextColor ( const QColor & color)

Sets the color for the displayed text. Updates the internal text color and schedules a repaint.

Parameters
colorThe new text color.

◆ sizeHint()

QSize LongTextDisplayEffect::sizeHint ( ) const
nodiscardoverride

Returns the recommended size for the widget based on the processed text content. The height is calculated based on the number of processed lines and font metrics. The width is calculated based on the longest processed line.

Returns
The calculated QSize hint.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cached_text_valid_

bool LongTextDisplayEffect::cached_text_valid_
private

Flag indicating if the processed_lines_ cache is up to date with the original_text_ and widget width.

◆ font_

QFont LongTextDisplayEffect::font_
private

The font used for rendering text and calculating metrics.

◆ original_text_

QString LongTextDisplayEffect::original_text_
private

The original, unprocessed text content set via constructor or SetText().

◆ processed_lines_

QStringList LongTextDisplayEffect::processed_lines_
private

List of strings representing the text after processing (line wrapping).

◆ scroll_position_

int LongTextDisplayEffect::scroll_position_
private

Current vertical scroll position in pixels.

◆ size_hint_

QSize LongTextDisplayEffect::size_hint_
private

Cached size hint calculated based on processed text dimensions.

◆ text_color_

QColor LongTextDisplayEffect::text_color_
private

The color used to render the text.

◆ update_timer_

QTimer* LongTextDisplayEffect::update_timer_ {}
private

Timer used to delay text processing after resize or text change events.


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