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