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