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 class MythFontProperties;
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;
117  QString m_cutMessage;
119  QString m_templateText;
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};
142  QColor m_startColor;
143  QColor m_endColor;
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 {ScrollBounceDelay = MythMainWindow::drawRefresh * 3};
155  enum ScrollDir {ScrollNone, ScrollLeft, ScrollRight, ScrollUp, ScrollDown,
156  ScrollHorizontal, ScrollVertical};
157 
158  int m_scrollStartDelay {ScrollBounceDelay};
159  int m_scrollReturnDelay {ScrollBounceDelay};
160  int m_scrollPause {0};
161  float m_scrollForwardRate {70.0 / MythMainWindow::drawRefresh};
162  float m_scrollReturnRate {70.0 / MythMainWindow::drawRefresh};
163  bool m_scrollBounce {false};
164  int m_scrollOffset {0};
165  float m_scrollPos {0};
166  int m_scrollPosWhole {0};
167  ScrollDir m_scrollDirection {ScrollNone};
168  bool m_scrolling {false};
169 
170  enum TextCase {CaseNormal, CaseUpper, CaseLower, CaseCapitaliseFirst,
171  CaseCapitaliseAll};
172 
173  TextCase m_textCase {CaseNormal};
174 
175  friend class MythUITextEdit;
176  friend class MythUIButton;
177  friend class MythThemedMenu;
178  friend class MythThemedMenuPrivate;
179 };
180 
181 #endif
force
bool force
Definition: mythtv/programs/mythcommflag/main.cpp:75
MythUIText::m_origDisplayRect
MythRect m_origDisplayRect
Definition: mythuitext.h:110
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythUIText::m_layouts
QVector< QTextLayout * > m_layouts
Definition: mythuitext.h:136
MythUITextEdit
A text entry and edit widget.
Definition: mythuitextedit.h:33
MythUIType::SetArea
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:594
MythUIText::GetDrawRect
MythRect GetDrawRect(void)
Definition: mythuitext.h:92
MythRect
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
MythUIText::m_defaultMessage
QString m_defaultMessage
Definition: mythuitext.h:118
MythUIType::Pulse
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:440
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:116
MythUIText::GetFontProperties
const MythFontProperties * GetFontProperties()
Definition: mythuitext.h:79
MythUIType::DrawSelf
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:463
MythUIText::GetMultiLine
bool GetMultiLine(void) const
Definition: mythuitext.h:88
MythUIText::GetCutDown
Qt::TextElideMode GetCutDown(void) const
Definition: mythuitext.h:86
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MythUIText::Constants
Constants
Definition: mythuitext.h:154
MythUIText::GetTemplateText
QString GetTemplateText(void) const
Definition: mythuitext.h:49
MythUIText::m_altDisplayRect
MythRect m_altDisplayRect
Definition: mythuitext.h:111
MythUIType::SetPosition
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:517
hardwareprofile.config.p
p
Definition: config.py:33
MythFontProperties
Definition: mythfontproperties.h:14
MythUIText::GetDefaultText
QString GetDefaultText(void) const
Definition: mythuitext.h:44
MythUIButton
A single button widget.
Definition: mythuibutton.h:22
mythtypes.h
MythUIText::m_endColor
QColor m_endColor
Definition: mythuitext.h:143
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
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:117
MythUIText::m_fontStates
FontStates m_fontStates
Definition: mythuitext.h:139
MythUIText::m_canvas
MythRect m_canvas
Definition: mythuitext.h:112
MythUIText::SetTemplateText
void SetTemplateText(const QString &text)
Definition: mythuitext.h:48
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:69
MythUIText::GetDBValue
QString GetDBValue(void) const override
Definition: mythuitext.h:62
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:64
MythUIText::ScrollUp
@ ScrollUp
Definition: mythuitext.h:155
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
MythUIText::m_drawRect
MythRect m_drawRect
Definition: mythuitext.h:113
MythUIText::m_startColor
QColor m_startColor
Definition: mythuitext.h:142
MythUIText::SetDBValue
void SetDBValue(const QString &text) override
Definition: mythuitext.h:60
MythUIText::TextCase
TextCase
Definition: mythuitext.h:170
MythPainter
Definition: mythpainter.h:33
MythUIText::ScrollDir
ScrollDir
Definition: mythuitext.h:155
MythMainWindow::drawRefresh
@ drawRefresh
Definition: mythmainwindow.h:40
MythThemedMenu
Themed menu class, used for main menus in MythTV frontend.
Definition: myththemedmenu.h:57
MythUIText::m_templateText
QString m_templateText
Definition: mythuitext.h:119
MythUIText::GetText
QString GetText(void) const
Definition: mythuitext.h:43
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:30
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:89
StorageUser
Definition: mythstorage.h:16