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// std::is_member_function_pointer_v is true for both const and
52// non-const member functions. Need a way to distinguish between
53// these two cases.
54
55// Base template
56template <typename T>
57struct is_const_member_func : std::false_type {};
58// Specialization for const member functions
59template <typename Return, typename Class, typename... Args>
60struct is_const_member_func<Return (Class::*)(Args...) const> : std::true_type {};
61
62// Helpers for convenience
63template <typename T>
64constexpr bool is_const_member_func_v =
65 std::is_member_function_pointer_v<T> && is_const_member_func<T>::value;
66template <typename T>
68 std::is_member_function_pointer_v<T> && !is_const_member_func<T>::value;
69
70
96class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
97{
98 Q_OBJECT
99
100 public:
101 MythUIType(QObject *parent, const QString &name);
102
103 virtual void Reset(void);
104
105 void AddChild(MythUIType *child);
106 MythUIType *GetChild(const QString &name) const;
107 MythUIType *GetChildAt(QPoint p, bool recursive=true,
108 bool focusable=true) const;
109 QList<MythUIType *> *GetAllChildren(void);
110 QList<MythUIType *> GetAllDescendants(void);
111
112 void DeleteChild(const QString &name);
113 void DeleteChild(MythUIType *child);
114 void DeleteAllChildren(void);
115
116 // Check set dirty status
117 bool NeedsRedraw(void) const;
118 void ResetNeedsRedraw(void);
119 void SetRedraw(void);
120
121 void SetChildNeedsRedraw(MythUIType *child);
122
123 // Check set if this can take focus
124 bool CanTakeFocus(void) const;
125 void SetCanTakeFocus(bool set = true);
126 void SetFocusOrder(int order);
127 void SetFocusedName(const QString & widgetname);
128 QString GetFocusedName(void) const { return m_focusedName; }
129
130 bool IsEnabled(void) const { return m_enabled; }
131 void SetEnabled(bool enable);
132
133 bool MoveToTop(void);
134 bool MoveChildToTop(MythUIType *child);
135
136 void ActivateAnimations(MythUIAnimation::Trigger trigger);
137 QList<MythUIAnimation*>* GetAnimations(void) { return &m_animations; }
138
139 // Called each draw pulse. Will redraw automatically if dirty afterwards
140 virtual void Pulse(void);
141
142 void Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod = 255,
143 QRect clipRect = QRect());
144
147 void SetPosition(int x, int y);
148 void SetPosition(QPoint point);
149 virtual void SetPosition(const MythPoint &point);
150 virtual MythPoint GetPosition(void) const;
151 virtual void SetSize(QSize size);
152 virtual void SetMinSize(const MythPoint &size);
153 virtual QSize GetMinSize(void) const;
154 virtual void SetArea(const MythRect &rect);
155 virtual void AdjustMinArea(int delta_x, int delta_y,
156 int delta_w, int delta_h);
157 virtual void VanishSibling(void);
158 virtual void SetMinAreaParent(MythRect actual_area, MythRect allowed_area,
159 MythUIType *child);
160 virtual void SetMinArea(const MythRect & rect);
161 virtual MythRect GetArea(void) const;
162 virtual MythRect GetFullArea(void) const;
163 virtual void RecalculateArea(bool recurse = true);
164 void ExpandArea(QRect rect);
165
166 virtual QRegion GetDirtyArea(void) const;
167
168 bool IsVisible(bool recurse = false) const;
169 virtual void SetVisible(bool visible);
170
171 void MoveTo(QPoint destXY, QPoint speedXY);
172 //FIXME: make mode enum
173 void AdjustAlpha(int mode, int alphachange, int minalpha = 0,
174 int maxalpha = 255);
175 void SetAlpha(int newalpha);
176 int GetAlpha(void) const;
177
178 // This class is not based on QWidget, so this is a new function
179 // and not an override of QWidget::keyPressEvent.
180 virtual bool keyPressEvent(QKeyEvent *event);
181 virtual bool inputMethodEvent(QInputMethodEvent *event);
182 virtual bool gestureEvent(MythGestureEvent *event);
183 virtual void mediaEvent(MythMediaEvent *event);
184
185 MythFontProperties *GetFont(const QString &text) const;
186 bool AddFont(const QString &text, MythFontProperties *fontProp);
187
188 void SetHelpText(const QString &text) { m_helptext = text; }
189 QString GetHelpText(void) const { return m_helptext; }
190
191 void SetXMLLocation(const QString &filename, int where)
192 { m_xmlLocation = QString("%1:%2").arg(filename).arg(where); }
193 QString GetXMLLocation(void) const { return m_xmlLocation; }
194
195 void SetXMLName(const QString &name) { m_xmlName = name; }
196 QString GetXMLName(void) const { return m_xmlName; }
197
198 bool IsDeferredLoading(bool recurse = false) const;
199 void SetDeferLoad(bool defer) { m_deferload = defer; }
200 virtual void LoadNow(void);
201
202 bool ContainsPoint(QPoint point) const;
203
204 virtual MythPainter *GetPainter(void);
205 void SetPainter(MythPainter *painter) { m_painter = painter; }
206
207 void SetCentre(UIEffects::Centre centre);
208 void SetZoom(float zoom);
209 void SetHorizontalZoom(float zoom);
210 void SetVerticalZoom(float zoom);
211 void SetAngle(float angle);
212 void SetDependIsDefault(bool isDefault);
213 void SetReverseDependence(MythUIType *dependee, bool reverse);
214 void SetDependsMap(QMap<QString, QString> dependsMap);
215 QMap<QString, QString> GetDependsMap() const { return m_dependsMap; }
216
217 protected:
218 ~MythUIType() override;
219 void customEvent(QEvent *event) override; // QObject
220
221 public slots:
222 void LoseFocus(void);
223 bool TakeFocus(void);
224 void Activate(void);
225 void Hide(void);
226 void Show(void);
227 void Refresh(void);
228 void UpdateDependState(bool isDefault);
229 void UpdateDependState(MythUIType *dependee, bool isDefault);
230
231 signals:
232 void RequestUpdate(void);
233 void RequestRegionUpdate(const QRect &);
234 void TakingFocus(void);
235 void LosingFocus(void);
237 void Showing(void);
238 void Hiding(void);
239 void Enabling(void);
240 void Disabling(void);
241 void FinishedMoving(void);
242 void FinishedFading(void);
243 void DependChanged(bool isDefault);
244
245 protected:
246 virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
247 int alphaMod, QRect clipRect);
248
249 void AddFocusableChildrenToList(FocusInfoType &focusList);
250 void HandleAlphaPulse();
251 void HandleMovementPulse();
252
253 int CalcAlpha(int alphamod) const;
254
255 static int NormX(int width);
256 static int NormY(int height);
257
258 void ConnectDependants(bool recurse = false);
259
260 virtual bool ParseElement(
261 const QString &filename, QDomElement &element, bool showWarnings);
262 virtual void CopyFrom(MythUIType *base);
263 virtual void CreateCopy(MythUIType *parent);
264 virtual void Finalize(void);
265
266 QList<MythUIType *> m_childrenList;
267 QMap<QString, QString> m_dependsMap;
268 // the number of dependencies is assumed to be small (1 or 2 elements on average)
269 // so we use a QList as we want the element ordered in the order they were defined
270 // and speed isn't going to be a factor
271 QList< QPair<MythUIType *, bool> >m_dependsValue;
273
274 bool m_visible {true};
275 bool m_hasFocus {false};
276 bool m_canHaveFocus {false};
277 bool m_enabled {true};
278 bool m_enableInitiator {false};
279 bool m_initiator {false};
280 bool m_vanish {false};
281 bool m_vanished {false};
282 bool m_isDependDefault {false};
283 QMap<MythUIType *, bool> m_reverseDepend;
284
286 int m_focusOrder {0};
287
288 MythRect m_area {0,0,0,0};
289 MythRect m_minArea {0,0,0,0};
291
292 QRegion m_dirtyRegion {0,0,0,0};
293 bool m_needsRedraw {false};
294
296
297 int m_alphaChangeMode {0}; // 0 - none, 1 - once, 2 - cycle
298 int m_alphaChange {0};
299 int m_alphaMin {0};
300 int m_alphaMax {255};
301
302 bool m_moving {false};
303 QPoint m_xyDestination {0,0};
304 QPoint m_xySpeed {0,0};
305
306 FontMap *m_fonts {nullptr};
307
308 MythUIType *m_parent {nullptr};
309 MythPainter *m_painter {nullptr};
310
311 QList<MythUIAnimation*> m_animations;
312 QString m_helptext;
313
314 QString m_xmlName;
316
317 bool m_deferload {false};
318
319 QColor m_borderColor {Qt::black};
320
321 friend class MythScreenType;
322 friend class XMLParseBase;
323};
324
325
326#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:19
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:97
bool IsEnabled(void) const
Definition: mythuitype.h:130
QString GetFocusedName(void) const
Definition: mythuitype.h:128
void VisibilityChanged(bool Visible)
void TakingFocus(void)
void Hiding(void)
void RequestUpdate(void)
UIEffects m_effects
Definition: mythuitype.h:295
void RequestRegionUpdate(const QRect &)
QString GetXMLLocation(void) const
Definition: mythuitype.h:193
QString m_xmlName
Definition: mythuitype.h:314
void Disabling(void)
void SetPainter(MythPainter *painter)
Definition: mythuitype.h:205
QList< int > m_dependOperator
Definition: mythuitype.h:272
MythPoint m_minSize
Definition: mythuitype.h:290
QMap< MythUIType *, bool > m_reverseDepend
Definition: mythuitype.h:283
void Enabling(void)
void SetXMLName(const QString &name)
Definition: mythuitype.h:195
void SetHelpText(const QString &text)
Definition: mythuitype.h:188
QString m_xmlLocation
Definition: mythuitype.h:315
QMap< QString, QString > m_dependsMap
Definition: mythuitype.h:267
QString m_focusedName
Definition: mythuitype.h:285
QMap< QString, QString > GetDependsMap() const
Definition: mythuitype.h:215
QString GetHelpText(void) const
Definition: mythuitype.h:189
QList< MythUIAnimation * > * GetAnimations(void)
Definition: mythuitype.h:137
QList< MythUIAnimation * > m_animations
Definition: mythuitype.h:311
QString GetXMLName(void) const
Definition: mythuitype.h:196
void DependChanged(bool isDefault)
void FinishedMoving(void)
void Showing(void)
QList< MythUIType * > m_childrenList
Definition: mythuitype.h:266
void FinishedFading(void)
void SetDeferLoad(bool defer)
Definition: mythuitype.h:199
QList< QPair< MythUIType *, bool > > m_dependsValue
Definition: mythuitype.h:271
QString m_helptext
Definition: mythuitype.h:312
void LosingFocus(void)
void SetXMLLocation(const QString &filename, int where)
Definition: mythuitype.h:191
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
constexpr bool is_nonconst_member_func_v
Definition: mythuitype.h:67
constexpr bool is_const_member_func_v
Definition: mythuitype.h:64
std::function< void(void)> MythUICallbackNMF
Definition: mythuitype.h:42