A custom widget for displaying potentially long text with cyberpunk aesthetics and efficient rendering.
More...
#include <long_text_display_effect.h>
|
| | 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.
|
| |
|
| 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.
|
| |
|
| 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.
|
| |
|
| 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.
|
| |
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.
◆ 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
-
| text | The initial text content to display. |
| text_color | The color for the displayed text. |
| parent | Optional parent widget. |
◆ 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_height | The total content height in pixels. |
◆ minimumSizeHint()
| QSize LongTextDisplayEffect::minimumSizeHint |
( |
| ) |
const |
|
nodiscardoverride |
◆ 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
-
◆ 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.
◆ 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
-
◆ 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
-
| position | The vertical scroll position in pixels. |
◆ 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
-
| text | The new text content. |
◆ SetTextColor()
| void LongTextDisplayEffect::SetTextColor |
( |
const QColor & | color | ) |
|
Sets the color for the displayed text. Updates the internal text color and schedules a repaint.
- Parameters
-
◆ 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.
◆ 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: