MythTV master
mythuitext.h
Go to the documentation of this file.
1#ifndef MYTHUI_TEXT_H_
2#define MYTHUI_TEXT_H_
3
4// QT headers
5#include <QTextLayout>
6#include <QColor>
7
8// MythTV
12#include "libmythui/mythmainwindow.h" // for MythMainWindow::drawRefresh
13
14static constexpr uint8_t DEFAULT_REFRESH_RATE { 70 }; // Hz
15
17
29{
30 using FontStates = QMap<QString, MythFontProperties>;
31
32 public:
33 MythUIText(MythUIType *parent, const QString &name);
34 MythUIText(const QString &text, const MythFontProperties &font,
35 QRect displayRect, QRect altDisplayRect,
36 MythUIType *parent, const QString &name);
37 ~MythUIText() override;
38
39 void Reset(void) override; // MythUIType
40 void ResetMap(const InfoMap &map);
41
42 virtual void SetText(const QString &text);
43 QString GetText(void) const { return m_message; }
44 QString GetDefaultText(void) const { return m_defaultMessage; }
45
46 void SetTextFromMap(const InfoMap &map);
47
48 void SetTemplateText(const QString &text) { m_templateText = text; }
49 QString GetTemplateText(void) const { return m_templateText; }
50
51#if 0 // Not currently used
52 void UseAlternateArea(bool useAlt);
53#endif
54
55 void Pulse(void) override; // MythUIType
56 QPoint CursorPosition(int text_offset);
57 int MoveCursor(int lines);
58
59 // StorageUser
60 void SetDBValue(const QString &text) override // StorageUser
61 { SetText(text); }
62 QString GetDBValue(void) const override // StorageUser
63 { return GetText(); }
64
65 void SetFontState(const QString &state);
66 void SetJustification(int just);
67
68 protected:
69 void DrawSelf(MythPainter *p, int xoffset, int yoffset,
70 int alphaMod, QRect clipRect) override; // MythUIType
71
72 bool ParseElement(const QString &filename, QDomElement &element,
73 bool showWarnings) override; // MythUIType
74 void CopyFrom(MythUIType *base) override; // MythUIType
75 void CreateCopy(MythUIType *parent) override; // MythUIType
76 void Finalize(void) override; // MythUIType
77
78 void SetFontProperties(const MythFontProperties &fontProps);
79 const MythFontProperties* GetFontProperties() { return m_font; }
80
81 void CycleColor(const QColor& startColor, const QColor& endColor, int numSteps);
82 void StopCycling();
83
84 int GetJustification(void) const;
85 void SetCutDown(Qt::TextElideMode mode);
86 Qt::TextElideMode GetCutDown(void) const { return m_cutdown; }
87 void SetMultiLine(bool multiline);
88 bool GetMultiLine(void) const { return m_multiLine; }
89
90 void SetArea(const MythRect &rect) override; // MythUIType
91 void SetPosition(const MythPoint &pos) override; // MythUIType
92 MythRect GetDrawRect(void) { return m_drawRect; }
93
94 void SetCanvasPosition(int x, int y);
95 void ShiftCanvas(int x, int y);
96
97 bool FormatTemplate(QString & paragraph, QTextLayout *layout);
98 bool Layout(QString & paragraph, QTextLayout *layout, bool final,
99 bool & overflow, qreal width, qreal & height, bool force,
100 qreal & last_line_width, QRectF & min_rect, int & num_lines);
101 bool LayoutParagraphs(const QStringList & paragraphs,
102 const QTextOption & textoption,
103 qreal width, qreal & height, QRectF & min_rect,
104 qreal & last_line_width, int & num_lines, bool final);
105 bool GetNarrowWidth(const QStringList & paragraphs,
106 const QTextOption & textoption, qreal & width);
107 void FillCutMessage(void);
108
109 int m_justification {Qt::AlignLeft | Qt::AlignTop};
114 QPoint m_cursorPos {-1,-1};
115
116 QString m_message;
120
121#if 0 // Not currently used
122 bool m_usingAltArea {false};
123#endif
124 bool m_shrinkNarrow {true};
125 Qt::TextElideMode m_cutdown {Qt::ElideRight};
126 bool m_multiLine {false};
127 int m_ascent {0};
128 int m_descent {0};
129 int m_leftBearing {0};
130 int m_rightBearing {0};
131 int m_leading {1};
132 int m_extraLeading {0};
133 int m_lineHeight {0};
134 int m_textCursor {-1};
135
136 QVector<QTextLayout *> m_layouts;
137
138 MythFontProperties* m_font {nullptr};
140
141 bool m_colorCycling {false};
144 int m_numSteps {0};
145 int m_curStep {0};
146 float m_curR {0.0};
147 float m_curG {0.0};
148 float m_curB {0.0};
149 float m_incR {0.0};
150 float m_incG {0.0};
151 float m_incB {0.0};
152
153 // Default delay of 3 seconds before 'bouncing' the scrolling text
154 enum Constants : std::uint8_t
155 {ScrollBounceDelay = DEFAULT_REFRESH_RATE * 3};
156 enum ScrollDir : std::uint8_t
157 {ScrollNone, ScrollLeft, ScrollRight, ScrollUp, ScrollDown,
158 ScrollHorizontal, ScrollVertical};
159
160 int m_scrollStartDelay {ScrollBounceDelay};
161 int m_scrollReturnDelay {ScrollBounceDelay};
162 float m_scrollPause {0.0};
163 float m_scrollForwardRate {1.0};
164 float m_scrollReturnRate {1.0};
165 bool m_scrollBounce {false};
166 int m_scrollOffset {0};
167 float m_scrollPos {0};
168 int m_scrollPosWhole {0};
169 ScrollDir m_scrollDirection {ScrollNone};
170 bool m_scrolling {false};
171 int64_t m_lastUpdate {QDateTime::currentMSecsSinceEpoch()};
172
173 enum TextCase : std::uint8_t
174 {CaseNormal, CaseUpper, CaseLower, CaseCapitaliseFirst,
175 CaseCapitaliseAll};
176
177 TextCase m_textCase {CaseNormal};
178
179 friend class MythUITextEdit;
180 friend class MythUIButton;
181 friend class MythThemedMenu;
182 friend class MythThemedMenuPrivate;
183};
184
185#endif
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:89
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
Themed menu class, used for main menus in MythTV frontend.
A single button widget.
Definition: mythuibutton.h:22
A text entry and edit widget.
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
QString GetDBValue(void) const override
Definition: mythuitext.h:62
QString m_templateText
Definition: mythuitext.h:119
QString GetText(void) const
Definition: mythuitext.h:43
void SetDBValue(const QString &text) override
Definition: mythuitext.h:60
@ CaseCapitaliseFirst
Definition: mythuitext.h:174
@ ScrollHorizontal
Definition: mythuitext.h:158
FontStates m_fontStates
Definition: mythuitext.h:139
QString m_message
Definition: mythuitext.h:116
MythRect m_drawRect
Definition: mythuitext.h:113
Qt::TextElideMode GetCutDown(void) const
Definition: mythuitext.h:86
MythRect GetDrawRect(void)
Definition: mythuitext.h:92
QString m_defaultMessage
Definition: mythuitext.h:118
MythRect m_altDisplayRect
Definition: mythuitext.h:111
QString GetTemplateText(void) const
Definition: mythuitext.h:49
QColor m_startColor
Definition: mythuitext.h:142
QColor m_endColor
Definition: mythuitext.h:143
MythRect m_origDisplayRect
Definition: mythuitext.h:110
void SetTemplateText(const QString &text)
Definition: mythuitext.h:48
MythRect m_canvas
Definition: mythuitext.h:112
QString m_cutMessage
Definition: mythuitext.h:117
const MythFontProperties * GetFontProperties()
Definition: mythuitext.h:79
QString GetDefaultText(void) const
Definition: mythuitext.h:44
QVector< QTextLayout * > m_layouts
Definition: mythuitext.h:136
bool GetMultiLine(void) const
Definition: mythuitext.h:88
QMap< QString, MythFontProperties > FontStates
Definition: mythuitext.h:30
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:479
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:610
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:456
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:533
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:73
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
bool force
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
#define MUI_PUBLIC
Definition: mythuiexp.h:9
static constexpr uint8_t DEFAULT_REFRESH_RATE
Definition: mythuitext.h:14