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