Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
long_text_display_effect.h
Go to the documentation of this file.
1#ifndef CYBER_LONG_TEXT_DISPLAY_H
2#define CYBER_LONG_TEXT_DISPLAY_H
3
4#include <QWidget>
5
15class LongTextDisplayEffect final : public QWidget {
16 Q_OBJECT
17
18public:
27 explicit LongTextDisplayEffect(QString text, const QColor &text_color, QWidget *parent = nullptr);
28
35 void SetText(const QString &text);
36
42 void SetTextColor(const QColor &color);
43
50 [[nodiscard]] QSize sizeHint() const override;
51
52 [[nodiscard]] QSize minimumSizeHint() const override;
53
60 void SetScrollPosition(int position);
61
62protected:
69 void paintEvent(QPaintEvent *event) override;
70
77 void resizeEvent(QResizeEvent *event) override;
78
79private:
87 void ProcessText();
88
89signals:
95 void contentHeightChanged(int new_height);
96
97private:
101 QStringList processed_lines_;
105 QFont font_;
113 QTimer *update_timer_{};
114};
115
116#endif // CYBER_LONG_TEXT_DISPLAY_H
QSize sizeHint() const override
Returns the recommended size for the widget based on the processed text content. The height is calcul...
Definition long_text_display_effect.cpp:30
QStringList processed_lines_
List of strings representing the text after processing (line wrapping).
Definition long_text_display_effect.h:101
QSize minimumSizeHint() const override
Definition long_text_display_effect.cpp:37
void resizeEvent(QResizeEvent *event) override
Overridden resize event handler. Invalidates the processed text cache and triggers delayed text proce...
Definition long_text_display_effect.cpp:90
QFont font_
The font used for rendering text and calculating metrics.
Definition long_text_display_effect.h:105
void ProcessText()
Processes the original_text_ into wrapped lines based on the current widget width....
Definition long_text_display_effect.cpp:96
LongTextDisplayEffect(QString text, const QColor &text_color, QWidget *parent=nullptr)
Constructs a CyberLongTextDisplay widget. Initializes the widget with default size policies,...
Definition long_text_display_effect.cpp:5
void SetText(const QString &text)
Sets the text content to be displayed. Updates the internal original text, invalidates the processed ...
Definition long_text_display_effect.cpp:16
bool cached_text_valid_
Flag indicating if the processed_lines_ cache is up to date with the original_text_ and widget width.
Definition long_text_display_effect.h:111
QString original_text_
The original, unprocessed text content set via constructor or SetText().
Definition long_text_display_effect.h:99
int scroll_position_
Current vertical scroll position in pixels.
Definition long_text_display_effect.h:109
QTimer * update_timer_
Timer used to delay text processing after resize or text change events.
Definition long_text_display_effect.h:113
void SetTextColor(const QColor &color)
Sets the color for the displayed text. Updates the internal text color and schedules a repaint.
Definition long_text_display_effect.cpp:24
void paintEvent(QPaintEvent *event) override
Overridden paint event handler. Draws the widget's appearance. Ensures the text is processed,...
Definition long_text_display_effect.cpp:49
void SetScrollPosition(int position)
Sets the vertical scroll position. This determines which part of the processed text is rendered in th...
Definition long_text_display_effect.cpp:42
void contentHeightChanged(int new_height)
Emitted after ProcessText() finishes, indicating the total calculated height required to display all ...
QSize size_hint_
Cached size hint calculated based on processed text dimensions.
Definition long_text_display_effect.h:107
QColor text_color_
The color used to render the text.
Definition long_text_display_effect.h:103