MythTV  master
mythrect.h
Go to the documentation of this file.
1 #ifndef MYTHRECT_H_
2 #define MYTHRECT_H_
3 
4 #include <QRect>
5 #include <QPoint>
6 #include <QString>
7 
8 #include "mythuiexp.h"
9 
10 class MythPoint;
11 
17 class MUI_PUBLIC MythRect : public QRect
18 {
19 
20  public:
21  MythRect() = default;
22  MythRect(int x, int y, int width, int height)
23  : QRect(x, y, width, height) {}
24  MythRect(const QString &sX, const QString &sY, const QString &sWidth,
25  const QString &sHeight, const QString &baseRes = QString());
26  explicit MythRect(QRect rect)
27  : QRect(rect) {}
28  MythRect& operator= (const QRect& other);
29  bool operator== (const MythRect &other) const;
30 
31  void Reset(void);
32  void CalculateArea(const QRect & parentArea);
33  void CalculateArea(const MythRect & parentArea);
34 
35  void NormRect(void);
36 
37  void setRect(const QString &sX, const QString &sY, const QString &sWidth,
38  const QString &sHeight, const QString &baseRes = QString());
39  void setRect(int X, int Y, int w,int h) { QRect::setRect(X,Y,w,h); }
40  void setX(const QString &sX);
41  void setX(int X) { QRect::setX(X); }
42  void setY(const QString &sY);
43  void setY(int Y) { QRect::setY(Y); }
44  void setWidth(const QString &sWidth);
45  void setWidth(int width) { QRect::setWidth(width); }
46  void setHeight(const QString &sHeight);
47  void setHeight(int height) { QRect::setHeight(height); }
48 
49  QString getX(void) const;
50  QString getY(void) const;
51  QString getWidth(void) const;
52  QString getHeight(void) const;
53 
54  MythPoint topLeft(void) const;
55  void moveTopLeft(const QPoint &point);
56  void moveTopLeft(const MythPoint &point);
57  void moveLeft(const QString &sX);
58  void moveLeft(int X) { QRect::moveLeft(X); }
59  void moveTop(const QString &sY);
60  void moveTop(int Y) { QRect::moveTop(Y); }
61 
62  QString toString(bool details = false) const;
63  QRect toQRect(void) const;
64 
65  private:
66  static bool parsePosition(float &percent, int &offset, int &absolute,
67  const QString &value, bool is_size);
68 
69  float m_percentWidth {0.0F};
70  float m_percentHeight {0.0F};
71  float m_percentX {0.0F};
72  float m_percentY {0.0F};
73  int m_offsetWidth {0};
74  int m_offsetHeight {0};
75  int m_offsetX {0};
76  int m_offsetY {0};
77 
78  bool m_needsUpdate {true};
79 
80  QRect m_parentArea {0,0,0,0};
81 };
82 
88 class MUI_PUBLIC MythPoint : public QPoint
89 {
90 
91  public:
93  : QPoint(), m_valid(false) {};
94  MythPoint(int x, int y)
95  : QPoint(x, y) {}
96  MythPoint(const QString &sX, const QString &sY);
97  explicit MythPoint(QPoint point)
98  : QPoint(point) {}
99 
100  MythPoint& operator= (const QPoint& other);
101 
102  bool isValid(void) const { return m_valid; }
103  void CalculatePoint(const QRect & parentArea);
104  void CalculatePoint(const MythRect & parentArea);
105 
106  void NormPoint(void);
107 
108  void setX(const QString &sX);
109  void setX(int X) { QPoint::setX(X); }
110  void setY(const QString &sY);
111  void setY(int Y) { QPoint::setY(Y); }
112 
113  QString getX(void) const;
114  QString getY(void) const;
115 
116  QString toString(bool details = false) const;
117  QPoint toQPoint(void) const;
118 
119  private:
120  static bool parsePosition(float &percent, int &offset, int &absolute,
121  const QString &value);
122 
123  float m_percentX {0.0F};
124  float m_percentY {0.0F};
125  int m_offsetX {0};
126  int m_offsetY {0};
127 
128  bool m_needsUpdate {true};
129 
131 
132  bool m_valid {true};
133 };
134 
135 #endif
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
false
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
MythPoint::MythPoint
MythPoint(QPoint point)
Definition: mythrect.h:97
MythPoint::setX
void setX(int X)
Definition: mythrect.h:109
MythRect
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
MythPoint::MythPoint
MythPoint(int x, int y)
Definition: mythrect.h:94
toString
QString toString(MarkTypes type)
Definition: programtypes.cpp:26
MythRect::MythRect
MythRect(int x, int y, int width, int height)
Definition: mythrect.h:22
MythRect::MythRect
MythRect(QRect rect)
Definition: mythrect.h:26
operator==
bool operator==(MusicMetadata &a, MusicMetadata &b)
Definition: musicmetadata.cpp:49
MythPoint::setY
void setY(int Y)
Definition: mythrect.h:111
MythPoint::MythPoint
MythPoint()
Definition: mythrect.h:92
MythRect::setRect
void setRect(int X, int Y, int w, int h)
Definition: mythrect.h:39
MythRect::setHeight
void setHeight(int height)
Definition: mythrect.h:47
MythRect::moveTop
void moveTop(int Y)
Definition: mythrect.h:60
MythRect::setX
void setX(int X)
Definition: mythrect.h:41
MythRect::MythRect
MythRect()=default
MythPoint::isValid
bool isValid(void) const
Definition: mythrect.h:102
MythRect::setWidth
void setWidth(int width)
Definition: mythrect.h:45
MythPoint::m_parentArea
QRect m_parentArea
Definition: mythrect.h:130
MythRect::setY
void setY(int Y)
Definition: mythrect.h:43
mythuiexp.h
MythRect::moveLeft
void moveLeft(int X)
Definition: mythrect.h:58
MythPoint
Wrapper around QPoint allowing us to handle percentage and other relative values for positioning in m...
Definition: mythrect.h:89