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();
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&);
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);
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
QString GetDefaultText(void) const
Definition: mythuitext.h:44
QColor m_endColor
Definition: mythuitext.h:143
QString GetDBValue(void) const override
Definition: mythuitext.h:62
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
void SetTemplateText(const QString &text)
Definition: mythuitext.h:48
MythRect m_drawRect
Definition: mythuitext.h:113
void SetDBValue(const QString &text) override
Definition: mythuitext.h:60
QString m_TemplateText
Definition: mythuitext.h:119
MythRect m_Canvas
Definition: mythuitext.h:112
QString m_Message
Definition: mythuitext.h:116
QColor m_startColor
Definition: mythuitext.h:142
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:519
QVector< QTextLayout * > m_Layouts
Definition: mythuitext.h:136
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
QString GetText(void) const
Definition: mythuitext.h:43
QString m_DefaultMessage
Definition: mythuitext.h:118
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
QMap< QString, MythFontProperties > FontStates
Definition: mythuitext.h:30
A text entry and edit widget.
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:442
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:465
const char * name
Definition: ParseText.cpp:328
A single button widget.
Definition: mythuibutton.h:21
QString m_CutMessage
Definition: mythuitext.h:117
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:591
Themed menu class, used for main menus in MythTV frontend.
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:69
#define MUI_PUBLIC
Definition: mythuiexp.h:9
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
QString GetTemplateText(void) const
Definition: mythuitext.h:49
bool GetMultiLine(void) const
Definition: mythuitext.h:88
MythRect GetDrawRect(void)
Definition: mythuitext.h:92
FontStates m_FontStates
Definition: mythuitext.h:139
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:86
MythRect m_OrigDisplayRect
Definition: mythuitext.h:110
const MythFontProperties * GetFontProperties()
Definition: mythuitext.h:79
MythRect m_AltDisplayRect
Definition: mythuitext.h:111
Qt::TextElideMode GetCutDown(void) const
Definition: mythuitext.h:86
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.