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 
63 class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase
64 {
65  Q_OBJECT
66 
67  public:
68  MythUIType(QObject *parent, const QString &name);
69 
70  virtual void Reset(void);
71 
72  void AddChild(MythUIType *child);
73  MythUIType *GetChild(const QString &name) const;
74  MythUIType *GetChildAt(const QPoint &p, bool recursive=true,
75  bool focusable=true) const;
76  QList<MythUIType *> *GetAllChildren(void);
77 
78  void DeleteChild(const QString &name);
79  void DeleteChild(MythUIType *child);
80  void DeleteAllChildren(void);
81 
82  // Check set dirty status
83  bool NeedsRedraw(void) const;
84  void ResetNeedsRedraw(void);
85  void SetRedraw(void);
86 
87  void SetChildNeedsRedraw(MythUIType *child);
88 
89  // Check set if this can take focus
90  bool CanTakeFocus(void) const;
91  void SetCanTakeFocus(bool set = true);
92  void SetFocusOrder(int);
93 
94  bool IsEnabled(void) const { return m_Enabled; }
95  void SetEnabled(bool enable);
96 
97  bool MoveToTop(void);
98  bool MoveChildToTop(MythUIType *child);
99 
100  void ActivateAnimations(MythUIAnimation::Trigger trigger);
101  QList<MythUIAnimation*>* GetAnimations(void) { return &m_animations; }
102 
103  // Called each draw pulse. Will redraw automatically if dirty afterwards
104  virtual void Pulse(void);
105 
106  void Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod = 255,
107  QRect clipRect = QRect());
108 
111  void SetPosition(int x, int y);
112  virtual void SetPosition(const MythPoint &point);
113  virtual MythPoint GetPosition(void) const;
114  virtual void SetSize(const QSize &size);
115  virtual void SetMinSize(const MythPoint &size);
116  virtual QSize GetMinSize(void) const;
117  virtual void SetArea(const MythRect &rect);
118  virtual void AdjustMinArea(int delta_x, int delta_y,
119  int delta_w, int delta_h);
120  virtual void VanishSibling(void);
121  virtual void SetMinAreaParent(MythRect actual_area, MythRect allowed_area,
122  MythUIType *child);
123  virtual void SetMinArea(const MythRect & rect);
124  virtual MythRect GetArea(void) const;
125  virtual MythRect GetFullArea(void) const;
126  virtual void RecalculateArea(bool recurse = true);
127  void ExpandArea(const MythRect &rect);
128 
129  virtual QRegion GetDirtyArea(void) const;
130 
131  bool IsVisible(bool recurse = false) const;
132  virtual void SetVisible(bool visible);
133 
134  void MoveTo(QPoint destXY, QPoint speedXY);
135  //FIXME: make mode enum
136  void AdjustAlpha(int mode, int alphachange, int minalpha = 0,
137  int maxalpha = 255);
138  void SetAlpha(int newalpha);
139  int GetAlpha(void) const;
140 
141  // This class is not based on QWidget, so this is a new function
142  // and not an override of QWidget::keyPressEvent.
143  virtual bool keyPressEvent(QKeyEvent *event);
144  virtual bool gestureEvent(MythGestureEvent *event);
145  virtual void mediaEvent(MythMediaEvent *event);
146 
147  MythFontProperties *GetFont(const QString &text) const;
148  bool AddFont(const QString &text, MythFontProperties *fontProp);
149 
150  void SetHelpText(const QString &text) { m_helptext = text; }
151  QString GetHelpText(void) const { return m_helptext; }
152 
153  void SetXMLLocation(const QString &filename, int where)
154  { m_xmlLocation = QString("%1:%2").arg(filename).arg(where); }
155  QString GetXMLLocation(void) const { return m_xmlLocation; }
156 
157  void SetXMLName(const QString &name) { m_xmlName = name; }
158  QString GetXMLName(void) const { return m_xmlName; }
159 
160  bool IsDeferredLoading(bool recurse = false) const;
161  void SetDeferLoad(bool defer) { m_deferload = defer; }
162  virtual void LoadNow(void);
163 
164  bool ContainsPoint(const QPoint &point) const;
165 
166  virtual MythPainter *GetPainter(void);
167  void SetPainter(MythPainter *painter) { m_Painter = painter; }
168 
169  void SetCentre(UIEffects::Centre centre);
170  void SetZoom(float zoom);
171  void SetHorizontalZoom(float zoom);
172  void SetVerticalZoom(float zoom);
173  void SetAngle(float angle);
174  void SetDependIsDefault(bool isDefault);
175  void SetReverseDependence(MythUIType *dependee, bool reverse);
176  void SetDependsMap(QMap<QString, QString> dependsMap);
177  QMap<QString, QString> GetDependsMap() const { return m_dependsMap; }
178 
179  protected:
180  virtual ~MythUIType();
181  void customEvent(QEvent *event) override; // QObject
182 
183  public slots:
184  void LoseFocus();
185  bool TakeFocus();
186  void Activate();
187  void Hide(void);
188  void Show(void);
189  void Refresh(void);
190  void UpdateDependState(bool isDefault);
191  void UpdateDependState(MythUIType *dependee, bool isDefault);
192 
193  signals:
194  void RequestUpdate();
195  void RequestUpdate(const QRect &);
196  void RequestRegionUpdate(const QRect &);
197  void TakingFocus();
198  void LosingFocus();
199  void Showing();
200  void Hiding();
201  void Enabling();
202  void Disabling();
203  void FinishedMoving();
204  void FinishedFading();
205  void DependChanged(bool isDefault);
206 
207  protected:
208  virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
209  int alphaMod, QRect clipRect);
210 
211  void AddFocusableChildrenToList(QMap<int, MythUIType *> &focusList);
212  void HandleAlphaPulse();
213  void HandleMovementPulse();
214 
215  int CalcAlpha(int alphamod);
216 
217  int NormX(const int width);
218  int NormY(const int height);
219 
220  void ConnectDependants(bool recurse = false);
221 
222  virtual bool ParseElement(
223  const QString &filename, QDomElement &element, bool showWarnings);
224  virtual void CopyFrom(MythUIType *base);
225  virtual void CreateCopy(MythUIType *parent);
226  virtual void Finalize(void);
227 
228  QList<MythUIType *> m_ChildrenList;
229  QMap<QString, QString> m_dependsMap;
230  // the number of dependencies is assumed to be small (1 or 2 elements on average)
231  // so we use a QList as we want the element ordered in the order they were defined
232  // and speed isn't going to be a factor
233  QList< QPair<MythUIType *, bool> >m_dependsValue;
234  QList<int> m_dependOperator;
235 
236  bool m_Visible {true};
237  bool m_HasFocus {false};
238  bool m_CanHaveFocus {false};
239  bool m_Enabled {true};
240  bool m_EnableInitiator {false};
241  bool m_Initiator {false};
242  bool m_Vanish {false};
243  bool m_Vanished {false};
244  bool m_IsDependDefault {false};
245  QMap<MythUIType *, bool> m_ReverseDepend;
246 
247  int m_focusOrder {0};
248 
249  MythRect m_Area {0,0,0,0};
250  MythRect m_MinArea {0,0,0,0};
252 // QSize m_NormalSize;
253 
254  QRegion m_DirtyRegion {0,0,0,0};
255  bool m_NeedsRedraw {false};
256 
258 
259  int m_AlphaChangeMode {0}; // 0 - none, 1 - once, 2 - cycle
260  int m_AlphaChange {0};
261  int m_AlphaMin {0};
262  int m_AlphaMax {255};
263 
264  bool m_Moving {false};
265  QPoint m_XYDestination {0,0};
266  QPoint m_XYSpeed {0,0};
267 
268  FontMap *m_Fonts {nullptr};
269 
270  MythUIType *m_Parent {nullptr};
271  MythPainter *m_Painter {nullptr};
272 
273  QList<MythUIAnimation*> m_animations;
274  QString m_helptext;
275 
276  QString m_xmlName;
277  QString m_xmlLocation;
278 
279  bool m_deferload {false};
280 
281  QColor m_BorderColor {Qt::black};
282 
283  friend class XMLParseBase;
284 };
285 
286 
287 #endif
QList< QPair< MythUIType *, bool > > m_dependsValue
Definition: mythuitype.h:233
QString m_helptext
Definition: mythuitype.h:274
QString GetHelpText(void) const
Definition: mythuitype.h:151
QMap< QString, QString > m_dependsMap
Definition: mythuitype.h:229
unsigned int slots[4]
Definition: element.c:38
static void ConnectDependants(MythUIType *parent, QMap< QString, QString > &dependsMap)
A widget for offering a range of numerical values where only the the bounding values and interval are...
Definition: mythuispinbox.h:16
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
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:97
void SetXMLLocation(const QString &filename, int where)
Definition: mythuitype.h:153
UIEffects m_Effects
Definition: mythuitype.h:257
void SetPainter(MythPainter *painter)
Definition: mythuitype.h:167
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
QString GetXMLLocation(void) const
Definition: mythuitype.h:155
QList< MythUIAnimation * > m_animations
Definition: mythuitype.h:273
QString GetXMLName(void) const
Definition: mythuitype.h:158
void SetHelpText(const QString &text)
Definition: mythuitype.h:150
void SetXMLName(const QString &name)
Definition: mythuitype.h:157
A text entry and edit widget.
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
QMap< QString, QString > GetDependsMap() const
Definition: mythuitype.h:177
A custom event that represents a mouse gesture.
Definition: mythgesture.h:39
const char * name
Definition: ParseText.cpp:328
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
A single button widget.
Definition: mythuibutton.h:21
void SetDeferLoad(bool defer)
Definition: mythuitype.h:161
MythPoint m_MinSize
Definition: mythuitype.h:251
QMap< MythUIType *, bool > m_ReverseDepend
Definition: mythuitype.h:245
#define MUI_PUBLIC
Definition: mythuiexp.h:9
bool IsEnabled(void) const
Definition: mythuitype.h:94
QList< MythUIAnimation * > * GetAnimations(void)
Definition: mythuitype.h:101
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:86
Progress bar widget.
QList< int > m_dependOperator
Definition: mythuitype.h:234
QList< MythUIType * > m_ChildrenList
Definition: mythuitype.h:228
QString m_xmlLocation
Definition: mythuitype.h:277
QString m_xmlName
Definition: mythuitype.h:276