MythTV  master
mythuitype.h
Go to the documentation of this file.
1 #ifndef MYTHUI_TYPES_H_
2 #define MYTHUI_TYPES_H_
3 
4 #include <QObject>
5 #include <QRegion>
6 #include <QMap>
7 #include <QList>
8 #include <QPair>
9 #include <QFont>
10 #include <QColor>
11 
12 #include "xmlparsebase.h"
13 #include "mythuianimation.h"
14 #include "mythrect.h"
15 
16 class MythPainter; // TODO: Should be an include but we first need to sort out the video scanner UI dependency mess
17 
18 class MythImage;
19 class MythGestureEvent;
20 class FontMap;
21 class MythFontProperties;
22 
23 class QEvent;
24 class QKeyEvent;
25 class MythGestureEvent;
26 class MythMediaEvent;
27 
28 class MythUIText;
29 class MythUIButton;
30 class MythUIButtonList;
32 class MythUIImage;
33 class MythUICheckBox;
34 class MythUISpinBox;
35 class MythUITextEdit;
36 class MythUIProgressBar;
37 
38 using FocusInfoType = QMultiMap<int, MythUIType *>;
39 
65 class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
66 {
67  Q_OBJECT
68 
69  public:
70  MythUIType(QObject *parent, const QString &name);
71 
72  virtual void Reset(void);
73 
74  void AddChild(MythUIType *child);
75  MythUIType *GetChild(const QString &name) const;
76  MythUIType *GetChildAt(const QPoint &p, bool recursive=true,
77  bool focusable=true) const;
78  QList<MythUIType *> *GetAllChildren(void);
79 
80  void DeleteChild(const QString &name);
81  void DeleteChild(MythUIType *child);
82  void DeleteAllChildren(void);
83 
84  // Check set dirty status
85  bool NeedsRedraw(void) const;
86  void ResetNeedsRedraw(void);
87  void SetRedraw(void);
88 
89  void SetChildNeedsRedraw(MythUIType *child);
90 
91  // Check set if this can take focus
92  bool CanTakeFocus(void) const;
93  void SetCanTakeFocus(bool set = true);
94  void SetFocusOrder(int order);
95 
96  bool IsEnabled(void) const { return m_enabled; }
97  void SetEnabled(bool enable);
98 
99  bool MoveToTop(void);
100  bool MoveChildToTop(MythUIType *child);
101 
102  void ActivateAnimations(MythUIAnimation::Trigger trigger);
103  QList<MythUIAnimation*>* GetAnimations(void) { return &m_animations; }
104 
105  // Called each draw pulse. Will redraw automatically if dirty afterwards
106  virtual void Pulse(void);
107 
108  void Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod = 255,
109  QRect clipRect = QRect());
110 
113  void SetPosition(int x, int y);
114  void SetPosition(QPoint point);
115  virtual void SetPosition(const MythPoint &point);
116  virtual MythPoint GetPosition(void) const;
117  virtual void SetSize(const QSize &size);
118  virtual void SetMinSize(const MythPoint &size);
119  virtual QSize GetMinSize(void) const;
120  virtual void SetArea(const MythRect &rect);
121  virtual void AdjustMinArea(int delta_x, int delta_y,
122  int delta_w, int delta_h);
123  virtual void VanishSibling(void);
124  virtual void SetMinAreaParent(MythRect actual_area, MythRect allowed_area,
125  MythUIType *child);
126  virtual void SetMinArea(const MythRect & rect);
127  virtual MythRect GetArea(void) const;
128  virtual MythRect GetFullArea(void) const;
129  virtual void RecalculateArea(bool recurse = true);
130  void ExpandArea(const QRect &rect);
131 
132  virtual QRegion GetDirtyArea(void) const;
133 
134  bool IsVisible(bool recurse = false) const;
135  virtual void SetVisible(bool visible);
136 
137  void MoveTo(QPoint destXY, QPoint speedXY);
138  //FIXME: make mode enum
139  void AdjustAlpha(int mode, int alphachange, int minalpha = 0,
140  int maxalpha = 255);
141  void SetAlpha(int newalpha);
142  int GetAlpha(void) const;
143 
144  // This class is not based on QWidget, so this is a new function
145  // and not an override of QWidget::keyPressEvent.
146  virtual bool keyPressEvent(QKeyEvent *event);
147  virtual bool gestureEvent(MythGestureEvent *event);
148  virtual void mediaEvent(MythMediaEvent *event);
149 
150  MythFontProperties *GetFont(const QString &text) const;
151  bool AddFont(const QString &text, MythFontProperties *fontProp);
152 
153  void SetHelpText(const QString &text) { m_helptext = text; }
154  QString GetHelpText(void) const { return m_helptext; }
155 
156  void SetXMLLocation(const QString &filename, int where)
157  { m_xmlLocation = QString("%1:%2").arg(filename).arg(where); }
158  QString GetXMLLocation(void) const { return m_xmlLocation; }
159 
160  void SetXMLName(const QString &name) { m_xmlName = name; }
161  QString GetXMLName(void) const { return m_xmlName; }
162 
163  bool IsDeferredLoading(bool recurse = false) const;
164  void SetDeferLoad(bool defer) { m_deferload = defer; }
165  virtual void LoadNow(void);
166 
167  bool ContainsPoint(const QPoint &point) const;
168 
169  virtual MythPainter *GetPainter(void);
170  void SetPainter(MythPainter *painter) { m_painter = painter; }
171 
172  void SetCentre(UIEffects::Centre centre);
173  void SetZoom(float zoom);
174  void SetHorizontalZoom(float zoom);
175  void SetVerticalZoom(float zoom);
176  void SetAngle(float angle);
177  void SetDependIsDefault(bool isDefault);
178  void SetReverseDependence(MythUIType *dependee, bool reverse);
179  void SetDependsMap(QMap<QString, QString> dependsMap);
180  QMap<QString, QString> GetDependsMap() const { return m_dependsMap; }
181 
182  protected:
183  ~MythUIType() override;
184  void customEvent(QEvent *event) override; // QObject
185 
186  public slots:
187  void LoseFocus();
188  bool TakeFocus();
189  void Activate();
190  void Hide(void);
191  void Show(void);
192  void Refresh(void);
193  void UpdateDependState(bool isDefault);
194  void UpdateDependState(MythUIType *dependee, bool isDefault);
195 
196  signals:
198  void RequestRegionUpdate(const QRect &);
199  void TakingFocus();
200  void LosingFocus();
201  void Showing();
202  void Hiding();
203  void Enabling();
204  void Disabling();
207  void DependChanged(bool isDefault);
208 
209  protected:
210  virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
211  int alphaMod, QRect clipRect);
212 
213  void AddFocusableChildrenToList(FocusInfoType &focusList);
214  void HandleAlphaPulse();
215  void HandleMovementPulse();
216 
217  int CalcAlpha(int alphamod) const;
218 
219  static int NormX(int width);
220  static int NormY(int height);
221 
222  void ConnectDependants(bool recurse = false);
223 
224  virtual bool ParseElement(
225  const QString &filename, QDomElement &element, bool showWarnings);
226  virtual void CopyFrom(MythUIType *base);
227  virtual void CreateCopy(MythUIType *parent);
228  virtual void Finalize(void);
229 
230  QList<MythUIType *> m_childrenList;
231  QMap<QString, QString> m_dependsMap;
232  // the number of dependencies is assumed to be small (1 or 2 elements on average)
233  // so we use a QList as we want the element ordered in the order they were defined
234  // and speed isn't going to be a factor
235  QList< QPair<MythUIType *, bool> >m_dependsValue;
236  QList<int> m_dependOperator;
237 
238  bool m_visible {true};
239  bool m_hasFocus {false};
240  bool m_canHaveFocus {false};
241  bool m_enabled {true};
242  bool m_enableInitiator {false};
243  bool m_initiator {false};
244  bool m_vanish {false};
245  bool m_vanished {false};
246  bool m_isDependDefault {false};
247  QMap<MythUIType *, bool> m_reverseDepend;
248 
249  int m_focusOrder {0};
250 
251  MythRect m_area {0,0,0,0};
252  MythRect m_minArea {0,0,0,0};
254 
255  QRegion m_dirtyRegion {0,0,0,0};
256  bool m_needsRedraw {false};
257 
259 
260  int m_alphaChangeMode {0}; // 0 - none, 1 - once, 2 - cycle
261  int m_alphaChange {0};
262  int m_alphaMin {0};
263  int m_alphaMax {255};
264 
265  bool m_moving {false};
266  QPoint m_xyDestination {0,0};
267  QPoint m_xySpeed {0,0};
268 
269  FontMap *m_fonts {nullptr};
270 
271  MythUIType *m_parent {nullptr};
272  MythPainter *m_painter {nullptr};
273 
274  QList<MythUIAnimation*> m_animations;
275  QString m_helptext;
276 
277  QString m_xmlName;
278  QString m_xmlLocation;
279 
280  bool m_deferload {false};
281 
282  QColor m_borderColor {Qt::black};
283 
284  friend class XMLParseBase;
285 };
286 
287 
288 #endif
MythUIType::SetXMLLocation
void SetXMLLocation(const QString &filename, int where)
Definition: mythuitype.h:156
mythrect.h
MythUIType::m_helptext
QString m_helptext
Definition: mythuitype.h:275
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
slots
std::array< unsigned int, 4 > slots
Definition: element.cpp:38
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
MythUIType::Enabling
void Enabling()
XMLParseBase
Definition: xmlparsebase.h:23
MythUIType::m_animations
QList< MythUIAnimation * > m_animations
Definition: mythuitype.h:274
MythUITextEdit
A text entry and edit widget.
Definition: mythuitextedit.h:33
MythUIAnimation::Trigger
Trigger
Definition: mythuianimation.h:46
MythUIType::GetXMLName
QString GetXMLName(void) const
Definition: mythuitype.h:161
MythRect
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
MythUIType::FinishedFading
void FinishedFading()
FontMap
Definition: mythfontproperties.h:87
MythUIType::TakingFocus
void TakingFocus()
MythUIType::m_effects
UIEffects m_effects
Definition: mythuitype.h:258
MythUIButtonListItem
Definition: mythuibuttonlist.h:28
XMLParseBase::ConnectDependants
static void ConnectDependants(MythUIType *parent, QMap< QString, QString > &dependsMap)
MythUIType::GetDependsMap
QMap< QString, QString > GetDependsMap() const
Definition: mythuitype.h:180
MythUIType::GetXMLLocation
QString GetXMLLocation(void) const
Definition: mythuitype.h:158
MythUIType::DependChanged
void DependChanged(bool isDefault)
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:13
MythUIType::IsEnabled
bool IsEnabled(void) const
Definition: mythuitype.h:96
hardwareprofile.config.p
p
Definition: config.py:33
MythUIType::Showing
void Showing()
MythUIType::Disabling
void Disabling()
MythFontProperties
Definition: mythfontproperties.h:14
MythUIType::SetHelpText
void SetHelpText(const QString &text)
Definition: mythuitype.h:153
MythMediaEvent
Definition: mythmedia.h:184
MythUIType::SetPainter
void SetPainter(MythPainter *painter)
Definition: mythuitype.h:170
MythUIType::RequestUpdate
void RequestUpdate()
MythUIButton
A single button widget.
Definition: mythuibutton.h:22
fontProp
Definition: mythfontproperties.h:108
MythUIType::m_childrenList
QList< MythUIType * > m_childrenList
Definition: mythuitype.h:230
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:640
xmlparsebase.h
MythUIType::Hiding
void Hiding()
MythUICheckBox
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
Definition: mythuicheckbox.h:16
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:66
MythUIType::FinishedMoving
void FinishedMoving()
MythUIType::m_dependOperator
QList< int > m_dependOperator
Definition: mythuitype.h:236
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
MythUIType::m_dependsMap
QMap< QString, QString > m_dependsMap
Definition: mythuitype.h:231
MythPainter
Definition: mythpainter.h:33
MythImage
Definition: mythimage.h:37
MythUIType::SetXMLName
void SetXMLName(const QString &name)
Definition: mythuitype.h:160
FocusInfoType
QMultiMap< int, MythUIType * > FocusInfoType
Definition: mythuitype.h:38
MythUIType::SetDeferLoad
void SetDeferLoad(bool defer)
Definition: mythuitype.h:164
MythUIType::m_minSize
MythPoint m_minSize
Definition: mythuitype.h:253
MythUIType::m_dependsValue
QList< QPair< MythUIType *, bool > > m_dependsValue
Definition: mythuitype.h:235
UIEffects::Centre
Centre
Definition: mythuianimation.h:12
UIEffects
Definition: mythuianimation.h:10
MythUIType::m_reverseDepend
QMap< MythUIType *, bool > m_reverseDepend
Definition: mythuitype.h:247
MythUISpinBox
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:17
MythUIType::m_xmlName
QString m_xmlName
Definition: mythuitype.h:277
MythGestureEvent
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
MythUIType::GetAnimations
QList< MythUIAnimation * > * GetAnimations(void)
Definition: mythuitype.h:103
mythuianimation.h
MythUIType::LosingFocus
void LosingFocus()
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:144
MythUIType::RequestRegionUpdate
void RequestRegionUpdate(const QRect &)
MythUIType::m_xmlLocation
QString m_xmlLocation
Definition: mythuitype.h:278
MythUIType::GetHelpText
QString GetHelpText(void) const
Definition: mythuitype.h:154
MythPoint
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:89