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 
40 // For non-class, static class, or lambda function callbacks.
41 using MythUICallbackNMF = std::function<void(void)>;
42 // For class member function callbacks.
43 using MythUICallbackMF = void (QObject::*)(void);
44 using MythUICallbackMFc = void (QObject::*)(void) const;
45 
49 
50 // Templates for determining if an argument is a "Pointer to a
51 // Member Function"
52 template<typename Func> struct FunctionPointerTest
53 { enum {MemberFunction = false, MemberConstFunction = false}; };
54 template<class Obj, typename Ret, typename... Args> struct FunctionPointerTest<Ret (Obj::*) (Args...)>
55 { enum {MemberFunction = true, MemberConstFunction = false}; };
56 template<class Obj, typename Ret, typename... Args> struct FunctionPointerTest<Ret (Obj::*) (Args...) const>
57 { enum {MemberFunction = false, MemberConstFunction = true}; };
58 
84 class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
85 {
86  Q_OBJECT
87 
88  public:
89  MythUIType(QObject *parent, const QString &name);
90 
91  virtual void Reset(void);
92 
93  void AddChild(MythUIType *child);
94  MythUIType *GetChild(const QString &name) const;
95  MythUIType *GetChildAt(QPoint p, bool recursive=true,
96  bool focusable=true) const;
97  QList<MythUIType *> *GetAllChildren(void);
98 
99  void DeleteChild(const QString &name);
100  void DeleteChild(MythUIType *child);
101  void DeleteAllChildren(void);
102 
103  // Check set dirty status
104  bool NeedsRedraw(void) const;
105  void ResetNeedsRedraw(void);
106  void SetRedraw(void);
107 
108  void SetChildNeedsRedraw(MythUIType *child);
109 
110  // Check set if this can take focus
111  bool CanTakeFocus(void) const;
112  void SetCanTakeFocus(bool set = true);
113  void SetFocusOrder(int order);
114 
115  bool IsEnabled(void) const { return m_enabled; }
116  void SetEnabled(bool enable);
117 
118  bool MoveToTop(void);
119  bool MoveChildToTop(MythUIType *child);
120 
121  void ActivateAnimations(MythUIAnimation::Trigger trigger);
122  QList<MythUIAnimation*>* GetAnimations(void) { return &m_animations; }
123 
124  // Called each draw pulse. Will redraw automatically if dirty afterwards
125  virtual void Pulse(void);
126 
127  void Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod = 255,
128  QRect clipRect = QRect());
129 
132  void SetPosition(int x, int y);
133  void SetPosition(QPoint point);
134  virtual void SetPosition(const MythPoint &point);
135  virtual MythPoint GetPosition(void) const;
136  virtual void SetSize(QSize size);
137  virtual void SetMinSize(const MythPoint &size);
138  virtual QSize GetMinSize(void) const;
139  virtual void SetArea(const MythRect &rect);
140  virtual void AdjustMinArea(int delta_x, int delta_y,
141  int delta_w, int delta_h);
142  virtual void VanishSibling(void);
143  virtual void SetMinAreaParent(MythRect actual_area, MythRect allowed_area,
144  MythUIType *child);
145  virtual void SetMinArea(const MythRect & rect);
146  virtual MythRect GetArea(void) const;
147  virtual MythRect GetFullArea(void) const;
148  virtual void RecalculateArea(bool recurse = true);
149  void ExpandArea(QRect rect);
150 
151  virtual QRegion GetDirtyArea(void) const;
152 
153  bool IsVisible(bool recurse = false) const;
154  virtual void SetVisible(bool visible);
155 
156  void MoveTo(QPoint destXY, QPoint speedXY);
157  //FIXME: make mode enum
158  void AdjustAlpha(int mode, int alphachange, int minalpha = 0,
159  int maxalpha = 255);
160  void SetAlpha(int newalpha);
161  int GetAlpha(void) const;
162 
163  // This class is not based on QWidget, so this is a new function
164  // and not an override of QWidget::keyPressEvent.
165  virtual bool keyPressEvent(QKeyEvent *event);
166  virtual bool gestureEvent(MythGestureEvent *event);
167  virtual void mediaEvent(MythMediaEvent *event);
168 
169  MythFontProperties *GetFont(const QString &text) const;
170  bool AddFont(const QString &text, MythFontProperties *fontProp);
171 
172  void SetHelpText(const QString &text) { m_helptext = text; }
173  QString GetHelpText(void) const { return m_helptext; }
174 
175  void SetXMLLocation(const QString &filename, int where)
176  { m_xmlLocation = QString("%1:%2").arg(filename).arg(where); }
177  QString GetXMLLocation(void) const { return m_xmlLocation; }
178 
179  void SetXMLName(const QString &name) { m_xmlName = name; }
180  QString GetXMLName(void) const { return m_xmlName; }
181 
182  bool IsDeferredLoading(bool recurse = false) const;
183  void SetDeferLoad(bool defer) { m_deferload = defer; }
184  virtual void LoadNow(void);
185 
186  bool ContainsPoint(QPoint point) const;
187 
188  virtual MythPainter *GetPainter(void);
189  void SetPainter(MythPainter *painter) { m_painter = painter; }
190 
191  void SetCentre(UIEffects::Centre centre);
192  void SetZoom(float zoom);
193  void SetHorizontalZoom(float zoom);
194  void SetVerticalZoom(float zoom);
195  void SetAngle(float angle);
196  void SetDependIsDefault(bool isDefault);
197  void SetReverseDependence(MythUIType *dependee, bool reverse);
198  void SetDependsMap(QMap<QString, QString> dependsMap);
199  QMap<QString, QString> GetDependsMap() const { return m_dependsMap; }
200 
201  protected:
202  ~MythUIType() override;
203  void customEvent(QEvent *event) override; // QObject
204 
205  public slots:
206  void LoseFocus();
207  bool TakeFocus();
208  void Activate();
209  void Hide(void);
210  void Show(void);
211  void Refresh(void);
212  void UpdateDependState(bool isDefault);
213  void UpdateDependState(MythUIType *dependee, bool isDefault);
214 
215  signals:
217  void RequestRegionUpdate(const QRect &);
218  void TakingFocus();
219  void LosingFocus();
221  void Showing();
222  void Hiding();
223  void Enabling();
224  void Disabling();
227  void DependChanged(bool isDefault);
228 
229  protected:
230  virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
231  int alphaMod, QRect clipRect);
232 
233  void AddFocusableChildrenToList(FocusInfoType &focusList);
234  void HandleAlphaPulse();
235  void HandleMovementPulse();
236 
237  int CalcAlpha(int alphamod) const;
238 
239  static int NormX(int width);
240  static int NormY(int height);
241 
242  void ConnectDependants(bool recurse = false);
243 
244  virtual bool ParseElement(
245  const QString &filename, QDomElement &element, bool showWarnings);
246  virtual void CopyFrom(MythUIType *base);
247  virtual void CreateCopy(MythUIType *parent);
248  virtual void Finalize(void);
249 
250  QList<MythUIType *> m_childrenList;
251  QMap<QString, QString> m_dependsMap;
252  // the number of dependencies is assumed to be small (1 or 2 elements on average)
253  // so we use a QList as we want the element ordered in the order they were defined
254  // and speed isn't going to be a factor
255  QList< QPair<MythUIType *, bool> >m_dependsValue;
256  QList<int> m_dependOperator;
257 
258  bool m_visible {true};
259  bool m_hasFocus {false};
260  bool m_canHaveFocus {false};
261  bool m_enabled {true};
262  bool m_enableInitiator {false};
263  bool m_initiator {false};
264  bool m_vanish {false};
265  bool m_vanished {false};
266  bool m_isDependDefault {false};
267  QMap<MythUIType *, bool> m_reverseDepend;
268 
269  int m_focusOrder {0};
270 
271  MythRect m_area {0,0,0,0};
272  MythRect m_minArea {0,0,0,0};
274 
275  QRegion m_dirtyRegion {0,0,0,0};
276  bool m_needsRedraw {false};
277 
279 
280  int m_alphaChangeMode {0}; // 0 - none, 1 - once, 2 - cycle
281  int m_alphaChange {0};
282  int m_alphaMin {0};
283  int m_alphaMax {255};
284 
285  bool m_moving {false};
286  QPoint m_xyDestination {0,0};
287  QPoint m_xySpeed {0,0};
288 
289  FontMap *m_fonts {nullptr};
290 
291  MythUIType *m_parent {nullptr};
292  MythPainter *m_painter {nullptr};
293 
294  QList<MythUIAnimation*> m_animations;
295  QString m_helptext;
296 
297  QString m_xmlName;
298  QString m_xmlLocation;
299 
300  bool m_deferload {false};
301 
302  QColor m_borderColor {Qt::black};
303 
304  friend class XMLParseBase;
305 };
306 
307 
308 #endif
FunctionPointerTest::MemberFunction
@ MemberFunction
Definition: mythuitype.h:53
MythUIType::SetXMLLocation
void SetXMLLocation(const QString &filename, int where)
Definition: mythuitype.h:175
mythrect.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
MythUIType::m_helptext
QString m_helptext
Definition: mythuitype.h:295
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
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:294
FunctionPointerTest::MemberConstFunction
@ MemberConstFunction
Definition: mythuitype.h:53
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:180
MythUICallbackNMF
std::function< void(void)> MythUICallbackNMF
Definition: mythuitype.h:41
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()
Visible
Definition: channelsettings.cpp:392
FontMap
Definition: mythfontproperties.h:87
MythUIType::TakingFocus
void TakingFocus()
MythUIType::m_effects
UIEffects m_effects
Definition: mythuitype.h:278
MythUIButtonListItem
Definition: mythuibuttonlist.h:28
MythUICallbackMF
void(QObject::*)(void) MythUICallbackMF
Definition: mythuitype.h:43
XMLParseBase::ConnectDependants
static void ConnectDependants(MythUIType *parent, QMap< QString, QString > &dependsMap)
MythUIType::GetDependsMap
QMap< QString, QString > GetDependsMap() const
Definition: mythuitype.h:199
MythUIType::GetXMLLocation
QString GetXMLLocation(void) const
Definition: mythuitype.h:177
MythUIType::DependChanged
void DependChanged(bool isDefault)
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:13
MythUIType::IsEnabled
bool IsEnabled(void) const
Definition: mythuitype.h:115
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:172
MythMediaEvent
Definition: mythmedia.h:184
MythUIType::SetPainter
void SetPainter(MythPainter *painter)
Definition: mythuitype.h:189
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:250
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:637
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:85
MythUIType::FinishedMoving
void FinishedMoving()
MythUIType::m_dependOperator
QList< int > m_dependOperator
Definition: mythuitype.h:256
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
MythUIType::m_dependsMap
QMap< QString, QString > m_dependsMap
Definition: mythuitype.h:251
MythPainter
Definition: mythpainter.h:33
MythImage
Definition: mythimage.h:37
MythUIType::SetXMLName
void SetXMLName(const QString &name)
Definition: mythuitype.h:179
FocusInfoType
QMultiMap< int, MythUIType * > FocusInfoType
Definition: mythuitype.h:38
MythUIType::SetDeferLoad
void SetDeferLoad(bool defer)
Definition: mythuitype.h:183
MythUIType::m_minSize
MythPoint m_minSize
Definition: mythuitype.h:273
MythUIType::m_dependsValue
QList< QPair< MythUIType *, bool > > m_dependsValue
Definition: mythuitype.h:255
UIEffects::Centre
Centre
Definition: mythuianimation.h:12
UIEffects
Definition: mythuianimation.h:10
MythUIType::m_reverseDepend
QMap< MythUIType *, bool > m_reverseDepend
Definition: mythuitype.h:267
MythUISpinBox
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:17
FunctionPointerTest
Definition: mythuitype.h:53
MythUIType::m_xmlName
QString m_xmlName
Definition: mythuitype.h:297
MythGestureEvent
A custom event that represents a mouse gesture.
Definition: mythgesture.h:40
MythUICallbackMFc
void(QObject::*)(void) const MythUICallbackMFc
Definition: mythuitype.h:44
MythUIType::GetAnimations
QList< MythUIAnimation * > * GetAnimations(void)
Definition: mythuitype.h:122
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:152
MythUIType::VisibilityChanged
void VisibilityChanged(bool Visible)
MythUIType::RequestRegionUpdate
void RequestRegionUpdate(const QRect &)
MythUIType::m_xmlLocation
QString m_xmlLocation
Definition: mythuitype.h:298
MythUIType::GetHelpText
QString GetHelpText(void) const
Definition: mythuitype.h:173
MythPoint
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:89