MythTV  master
Text.h
Go to the documentation of this file.
1 /* Text.h
2 
3  Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  Or, point your browser to http://www.gnu.org/copyleft/gpl.html
19 
20 */
21 
22 
23 #if !defined(TEXT_H)
24 #define TEXT_H
25 
26 #include "Visible.h"
27 #include "BaseActions.h"
28 // Dependencies
29 #include "Presentable.h"
30 #include "Ingredients.h"
31 #include "Root.h"
32 #include "BaseClasses.h"
33 
34 class MHEngine;
35 class MHTextDisplay;
36 
37 class MHText : public MHVisible
38 {
39  public:
40  MHText() = default;
41  MHText(const MHText &ref);
42  ~MHText() override;
43  const char *ClassName() override // MHRoot
44  { return "Text"; }
45  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHVisible
46  void PrintMe(FILE *fd, int nTabs) const override; // MHVisible
47 
48  void Preparation(MHEngine *engine) override; // MHVisible
49  void ContentPreparation(MHEngine *engine) override; // MHIngredient
50  void ContentArrived(const unsigned char *data, int length, MHEngine *engine) override; // MHIngredient
51 
52  // Actions.
53  // Extract the text from an object. This can be used to load content from a file.
54  void GetTextData(MHRoot *pDestination, MHEngine */*engine*/) override // MHRoot
55  { pDestination->SetVariableValue(m_content); }
56  MHIngredient *Clone(MHEngine */*engine*/) override // MHRoot
57  { return new MHText(*this); } // Create a clone of this ingredient.
58  void SetBackgroundColour(const MHColour &colour, MHEngine *engine) override; // MHRoot
59  void SetTextColour(const MHColour &colour, MHEngine *engine) override; // MHRoot
60  void SetFontAttributes(const MHOctetString &fontAttrs, MHEngine *engine) override; // MHRoot
61 
62  // Enumerated type lookup functions for the text parser.
63  static int GetJustification(const QString& str);
64  static int GetLineOrientation(const QString& str);
65  static int GetStartCorner(const QString& str);
66 
67  // Display function.
68  void Display(MHEngine *engine) override; // MHVisible
69  QRegion GetOpaqueArea() override; // MHVisible
70 
71  protected:
72  void Redraw();
73 
77  int m_nCharSet {-1};
78 
79  enum Justification : std::uint8_t { Start = 1, End, Centre, Justified };
80  enum LineOrientation : std::uint8_t { Vertical = 1, Horizontal };
81  enum StartCorner : std::uint8_t { UpperLeft = 1, UpperRight, LowerLeft, LowerRight };
86  bool m_fTextWrap {false};
87  // Internal attributes. The font colour, background colour and font attributes are
88  // internal attributes in UK MHEG.
89 // MHFontBody m_font;
92  MHOctetString m_content; // The content as an octet string
93 
94  MHTextDisplay *m_pDisplay {nullptr}; // Pointer to the display object.
95  bool m_fNeedsRedraw {false};
96 
97  // Create the Unicode content from the character input.
98  void CreateContent(const unsigned char *p, int s, MHEngine *engine);
99 };
100 
101 class MHHyperText : public MHText, public MHInteractible
102 {
103  public:
105  const char *ClassName() override // MHText
106  { return "HyperText"; }
107  ~MHHyperText() override = default;
108  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHText
109  void PrintMe(FILE *fd, int nTabs) const override; // MHText
110 
111  // Implement the actions in the main inheritance line.
112  void SetInteractionStatus(bool newStatus, MHEngine *engine) override // MHRoot
113  { InteractSetInteractionStatus(newStatus, engine); }
114  bool GetInteractionStatus(void) override // MHRoot
115  { return InteractGetInteractionStatus(); }
116  void SetHighlightStatus(bool newStatus, MHEngine *engine) override // MHRoot
117  { InteractSetHighlightStatus(newStatus, engine); }
118  bool GetHighlightStatus(void) override // MHRoot
119  { return InteractGetHighlightStatus(); }
120  void Deactivation(MHEngine */*engine*/) override // MHVisible
121  { InteractDeactivation(); }
122 };
123 
124 // Get Text Data - get the data out of a text object.
126 {
127  public:
128  MHGetTextData(): MHActionObjectRef(":GetTextData") {}
129  void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) override // MHActionObjectRef
130  { pTarget->GetTextData(pArg, engine); }
131 };
132 
133 // Actions added in UK MHEG profile.
135  public:
136  MHSetBackgroundColour(): MHSetColour(":SetBackgroundColour") { }
137  protected:
138  void SetColour(const MHColour &colour, MHEngine *engine) override // MHSetColour
139  { Target(engine)->SetBackgroundColour(colour, engine); }
140 };
141 
143  public:
144  MHSetTextColour(): MHSetColour(":SetTextColour") { }
145  protected:
146  void SetColour(const MHColour &colour, MHEngine *engine) override // MHSetColour
147  { Target(engine)->SetTextColour(colour, engine); }
148 };
149 
151 {
152  public:
153  MHSetFontAttributes(): MHElemAction(":SetFontAttributes") {}
154  void Initialise(MHParseNode *p, MHEngine *engine) override; // MHElemAction
155  void Perform(MHEngine *engine) override; // MHElemAction
156  protected:
157  void PrintArgs(FILE *fd, int /*nTabs*/) const override // MHElemAction
158  { m_fontAttrs.PrintMe(fd, 0); }
159  MHGenericOctetString m_fontAttrs; // New font attributes.
160 };
161 
162 
163 
164 #endif
MHText::LineOrientation
LineOrientation
Definition: Text.h:80
MHHyperText::ClassName
const char * ClassName() override
Definition: Text.h:105
MHActionObjectRef
Definition: BaseActions.h:119
MHHyperText::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Text.cpp:903
MHSetFontAttributes
Definition: Text.h:150
MHGenericOctetString
Definition: BaseClasses.h:224
Presentable.h
MHInteractible::InteractSetHighlightStatus
void InteractSetHighlightStatus(bool newStatus, MHEngine *engine)
Definition: Visible.cpp:579
MHHyperText::MHHyperText
MHHyperText()
Definition: Text.h:104
MHHyperText::GetInteractionStatus
bool GetInteractionStatus(void) override
Definition: Text.h:114
MHText::Start
@ Start
Definition: Text.h:79
MHGetTextData::MHGetTextData
MHGetTextData()
Definition: Text.h:128
MHInteractible::InteractSetInteractionStatus
void InteractSetInteractionStatus(bool newStatus, MHEngine *engine)
Definition: Visible.cpp:558
MHEngine
Definition: Engine.h:72
MHSetBackgroundColour::MHSetBackgroundColour
MHSetBackgroundColour()
Definition: Text.h:136
MHText
Definition: Text.h:37
MHText::ContentPreparation
void ContentPreparation(MHEngine *engine) override
Definition: Text.cpp:339
MHRoot::SetTextColour
virtual void SetTextColour(const MHColour &, MHEngine *)
Definition: Root.h:117
MHSetFontAttributes::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Text.cpp:915
MHText::m_content
MHOctetString m_content
Definition: Text.h:92
MHText::LowerRight
@ LowerRight
Definition: Text.h:81
MHText::m_pDisplay
MHTextDisplay * m_pDisplay
Definition: Text.h:94
Visible.h
MHSetBackgroundColour
Definition: Text.h:134
MHHyperText::Deactivation
void Deactivation(MHEngine *) override
Definition: Text.h:120
MHText::m_originalBgColour
MHColour m_originalBgColour
Definition: Text.h:76
MHOctetString
Definition: BaseClasses.h:107
MHGetTextData
Definition: Text.h:125
MHText::Vertical
@ Vertical
Definition: Text.h:80
MHText::Horizontal
@ Horizontal
Definition: Text.h:80
MHText::CreateContent
void CreateContent(const unsigned char *p, int s, MHEngine *engine)
Definition: Text.cpp:366
MHGetTextData::CallAction
void CallAction(MHEngine *engine, MHRoot *pTarget, MHRoot *pArg) override
Definition: Text.h:129
mythburn.FILE
int FILE
Definition: mythburn.py:139
MHHyperText::~MHHyperText
~MHHyperText() override=default
MHText::m_textColour
MHColour m_textColour
Definition: Text.h:90
MHText::UpperLeft
@ UpperLeft
Definition: Text.h:81
MHText::GetJustification
static int GetJustification(const QString &str)
Definition: Text.cpp:159
MHHyperText::GetHighlightStatus
bool GetHighlightStatus(void) override
Definition: Text.h:118
MHText::~MHText
~MHText() override
Definition: Text.cpp:60
MHText::m_startCorner
StartCorner m_startCorner
Definition: Text.h:85
MHSetBackgroundColour::SetColour
void SetColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.h:138
hardwareprofile.config.p
p
Definition: config.py:33
MHSetTextColour::SetColour
void SetColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.h:146
MHText::SetFontAttributes
void SetFontAttributes(const MHOctetString &fontAttrs, MHEngine *engine) override
Definition: Text.cpp:389
MHSetFontAttributes::MHSetFontAttributes
MHSetFontAttributes()
Definition: Text.h:153
MHText::GetOpaqueArea
QRegion GetOpaqueArea() override
Definition: Text.cpp:886
MHText::MHText
MHText()=default
MHText::m_fontAttrs
MHOctetString m_fontAttrs
Definition: Text.h:91
MHText::m_horizJ
Justification m_horizJ
Definition: Text.h:82
MHHyperText
Definition: Text.h:101
MHSetTextColour
Definition: Text.h:142
MHColour
Definition: BaseClasses.h:139
MHGenericOctetString::PrintMe
void PrintMe(FILE *fd, int nTabs) const
Definition: BaseClasses.cpp:476
MHHyperText::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Text.cpp:896
MHText::m_nCharSet
int m_nCharSet
Definition: Text.h:77
MHText::GetStartCorner
static int GetStartCorner(const QString &str)
Definition: Text.cpp:199
MHSetFontAttributes::m_fontAttrs
MHGenericOctetString m_fontAttrs
Definition: Text.h:159
Ingredients.h
MHHyperText::SetHighlightStatus
void SetHighlightStatus(bool newStatus, MHEngine *engine) override
Definition: Text.h:116
MHText::m_originalFontAttrs
MHOctetString m_originalFontAttrs
Definition: Text.h:75
MHIngredient
Definition: Ingredients.h:33
MHHyperText::SetInteractionStatus
void SetInteractionStatus(bool newStatus, MHEngine *engine) override
Definition: Text.h:112
MHText::Display
void Display(MHEngine *engine) override
Definition: Text.cpp:866
MHElemAction::Target
MHRoot * Target(MHEngine *engine)
Definition: BaseActions.cpp:46
MHRoot::SetBackgroundColour
virtual void SetBackgroundColour(const MHColour &, MHEngine *)
Definition: Root.h:115
MHText::End
@ End
Definition: Text.h:79
MHFontBody
Definition: BaseClasses.h:309
Root.h
MHText::StartCorner
StartCorner
Definition: Text.h:81
MHSetFontAttributes::PrintArgs
void PrintArgs(FILE *fd, int) const override
Definition: Text.h:157
MHText::m_fNeedsRedraw
bool m_fNeedsRedraw
Definition: Text.h:95
MHSetTextColour::MHSetTextColour
MHSetTextColour()
Definition: Text.h:144
MHInteractible::InteractGetHighlightStatus
bool InteractGetHighlightStatus(void) const
Definition: Visible.h:157
MHText::GetTextData
void GetTextData(MHRoot *pDestination, MHEngine *) override
Definition: Text.h:54
MHText::m_fTextWrap
bool m_fTextWrap
Definition: Text.h:86
MHVisible
Definition: Visible.h:35
MHText::Centre
@ Centre
Definition: Text.h:79
MHText::m_vertJ
Justification m_vertJ
Definition: Text.h:83
MHText::Justified
@ Justified
Definition: Text.h:79
BaseClasses.h
MHParseNode
Definition: ParseNode.h:38
MHText::m_origFont
MHFontBody m_origFont
Definition: Text.h:74
MHText::ClassName
const char * ClassName() override
Definition: Text.h:43
MHText::PrintMe
void PrintMe(FILE *fd, int nTabs) const override
Definition: Text.cpp:212
MHInteractible::InteractDeactivation
void InteractDeactivation(void)
Definition: Visible.h:160
MHText::Redraw
void Redraw()
Definition: Text.cpp:545
MHText::m_bgColour
MHColour m_bgColour
Definition: Text.h:90
MHText::SetTextColour
void SetTextColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.cpp:374
MHElemAction
Definition: BaseActions.h:34
MHSetColour
Definition: Visible.h:321
MHText::Initialise
void Initialise(MHParseNode *p, MHEngine *engine) override
Definition: Text.cpp:66
MHText::Clone
MHIngredient * Clone(MHEngine *) override
Definition: Text.h:56
MHText::GetLineOrientation
static int GetLineOrientation(const QString &str)
Definition: Text.cpp:178
MHTextDisplay
Definition: freemheg.h:195
MHText::UpperRight
@ UpperRight
Definition: Text.h:81
MHText::LowerLeft
@ LowerLeft
Definition: Text.h:81
MHText::Preparation
void Preparation(MHEngine *engine) override
Definition: Text.cpp:290
MHText::m_lineOrientation
LineOrientation m_lineOrientation
Definition: Text.h:84
MHInteractible::InteractGetInteractionStatus
bool InteractGetInteractionStatus(void) const
Definition: Visible.h:155
BaseActions.h
MHText::Justification
Justification
Definition: Text.h:79
MHText::SetBackgroundColour
void SetBackgroundColour(const MHColour &colour, MHEngine *engine) override
Definition: Text.cpp:381
MHInteractible
Definition: Visible.h:138
MHText::m_originalTextColour
MHColour m_originalTextColour
Definition: Text.h:76
MHRoot
Definition: Root.h:44
MHText::ContentArrived
void ContentArrived(const unsigned char *data, int length, MHEngine *engine) override
Definition: Text.cpp:355
MHSetFontAttributes::Perform
void Perform(MHEngine *engine) override
Definition: Text.cpp:921