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