MythTV  master
mythuiimage.h
Go to the documentation of this file.
1 #ifndef MYTHUI_IMAGE_H_
2 #define MYTHUI_IMAGE_H_
3 
4 #include <QDateTime>
5 #include <QHash>
6 #include <QMutex>
7 #include <QWaitCondition>
8 #include <QVector>
9 #include <QPair>
10 
11 #include "mythuitype.h"
12 #include "mythuihelper.h"
13 #include "mythimage.h"
14 
15 class MythUIImagePrivate;
16 class MythScreenType;
17 class ImageLoadThread;
18 
24 {
25  public:
26  ImageProperties() = default;
27  ImageProperties(const ImageProperties& other);
29 
31 
32  void SetMaskImage(MythImage *image);
33  void SetMaskImageFilename(const QString &filename)
34  {
35  m_maskImageFilename=filename;
36  }
38  {
39  return m_maskImageFilename;
40  }
41  QRect GetMaskImageRect(void)
42  {
43  QRect rect;
44  if (m_maskImage)
45  rect = m_maskImage->rect();
46  return rect;
47  }
48  QImage GetMaskImageSubset(const QRect &imageArea)
49  {
50  if (m_maskImage)
51  return m_maskImage->copy(imageArea);
52 
53  QImage img(imageArea.size(), QImage::Format_ARGB32);
54  img.fill(0xFFFFFFFF);
55  return img;
56  }
57 
58  QString m_filename;
59 
60  MythRect m_cropRect {0,0,0,0};
61  QSize m_forceSize {0,0};
62 
63  bool m_preserveAspect {false};
64  bool m_isGreyscale {false};
65  bool m_isReflected {false};
66  bool m_isMasked {false};
67  bool m_isOriented {false};
68 
70  int m_reflectScale {100};
71  int m_reflectLength {100};
72  int m_reflectShear {0};
74 
75  int m_orientation {1};
76 
77  bool m_isThemeImage {false};
78 
79  private:
80  void Init(void);
81  void Copy(const ImageProperties &other);
82 
83  MythImage *m_maskImage {nullptr};
85 };
86 
87 typedef QPair<MythImage *, int> AnimationFrame;
88 typedef QVector<AnimationFrame> AnimationFrames;
89 
98 {
99  Q_OBJECT
100 
101  public:
102  MythUIImage(const QString &filepattern, int low, int high, int delayms,
103  MythUIType *parent, const QString &name);
104  MythUIImage(const QString &filename, MythUIType *parent, const QString &name);
105  MythUIImage(MythUIType *parent, const QString &name);
106  ~MythUIImage();
107 
108  QString GetFilename(void) { return m_Filename; }
109 
111  void SetFilename(const QString &filename);
112 
114  void SetFilepattern(const QString &filepattern, int low, int high);
115 
116  void SetImageCount(int low, int high);
117 
121  void SetImage(MythImage *img);
122 
126  void SetImages(QVector<MythImage *> *images);
127 
128  void SetDelay(int delayms);
129  void SetDelays(QVector<int> delays);
130 
131  void Reset(void) override; // MythUIType
132  bool Load(bool allowLoadInBackground = true, bool forceStat = false);
133 
134  void Pulse(void) override; // MythUIType
135 
136  void LoadNow(void) override; // MythUIType
137 
138  void SetOrientation(int orientation);
139 
140  signals:
141  void LoadComplete();
142 
143  protected:
144  void DrawSelf(MythPainter *p, int xoffset, int yoffset,
145  int alphaMod, QRect clipRect) override; // MythUIType
146 
147  void Clear(void);
148 
149  void SetAnimationFrames(AnimationFrames frames);
150  void customEvent(QEvent *event) override; // MythUIType
151 
152  bool ParseElement(const QString &filename, QDomElement &element,
153  bool showWarnings) override; // MythUIType
154  void CopyFrom(MythUIType *base) override; // MythUIType
155  void CreateCopy(MythUIType *parent) override; // MythUIType
156  void Finalize(void) override; // MythUIType
157 
158  void SetSize(int width, int height);
159  void SetSize(const QSize &size) override; // MythUIType
160  void ForceSize(const QSize &size);
161 
162  void SetCropRect(int x, int y, int width, int height);
163  void SetCropRect(const MythRect &rect);
164 
165  void FindRandomImage(void);
166 
167  QString m_Filename;
168  QString m_OrigFilename;
169 
170  QHash<int, MythImage *> m_Images;
171  QHash<int, int> m_Delays;
172  QMutex m_ImagesLock;
173 
174  int m_Delay;
175  int m_LowNum;
177 
178  unsigned int m_CurPos {0};
179  QTime m_LastDisplay {QTime::currentTime()};
180 
181  bool m_NeedLoad {false};
182 
184 
185  int m_runningThreads {0};
186 
187  bool m_showingRandomImage {false};
189 
190  MythUIImagePrivate *d {nullptr};
191 
192  enum AnimationCycle {kCycleStart, kCycleReverse};
193  AnimationCycle m_animationCycle {kCycleStart};
194  bool m_animationReverse {false};
195  bool m_animatedImage {false};
196 
197  friend class MythUIImagePrivate;
198  friend class MythThemeBase;
199  friend class MythUIButtonListItem;
200  friend class MythUIProgressBar;
201  friend class MythUIEditBar;
202  friend class MythUITextEdit;
203  friend class ImageLoadThread;
204  friend class MythUIGuideGrid;
205 
206  private:
207  Q_DISABLE_COPY(MythUIImage)
208 };
209 
210 #endif
A narrow purpose widget used to show television programs and the timeslots they occupy on channels.
QString m_OrigFilename
Definition: mythuiimage.h:168
QString GetFilename(void)
Definition: mythuiimage.h:108
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:977
ImageProperties m_imageProperties
Definition: mythuiimage.h:183
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
QString m_filename
Definition: mythuiimage.h:58
ImageProperties & operator=(const ImageProperties &other)
Definition: mythuiimage.cpp:44
QString GetMaskImageFilename()
Definition: mythuiimage.h:37
void SetMaskImageFilename(const QString &filename)
Definition: mythuiimage.h:33
ReflectAxis
Definition: mythimage.h:14
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
ReflectAxis m_reflectAxis
Definition: mythuiimage.h:69
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
void Copy(const ImageProperties &other)
Definition: mythuiimage.cpp:57
QString m_maskImageFilename
Definition: mythuiimage.h:84
static const uint16_t * d
void SetMaskImage(MythImage *image)
Definition: mythuiimage.cpp:83
A text entry and edit widget.
virtual void SetSize(const QSize &size)
Definition: mythuitype.cpp:550
QHash< int, int > m_Delays
Definition: mythuiimage.h:171
QString m_Filename
Definition: mythuiimage.h:167
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:442
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
ImageProperties()=default
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:465
const char * name
Definition: ParseText.cpp:328
virtual void LoadNow(void)
Cause images in this and child widgets to be loaded.
MythRect m_cropRect
Definition: mythuiimage.h:60
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:69
QString m_imageDirectory
Definition: mythuiimage.h:188
QImage GetMaskImageSubset(const QRect &imageArea)
Definition: mythuiimage.h:48
bool m_preserveAspect
Definition: mythuiimage.h:63
#define MUI_PUBLIC
Definition: mythuiexp.h:9
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
QHash< int, MythImage * > m_Images
Definition: mythuiimage.h:170
const char * frames[3]
Definition: element.c:46
QMutex m_ImagesLock
Definition: mythuiimage.h:172
Screen in which all other widgets are contained and rendered.
Progress bar widget.
QRect GetMaskImageRect(void)
Definition: mythuiimage.h:41
MythImage * m_maskImage
Definition: mythuiimage.h:83
#define Clear(a)
A narrow purpose widget used to represent cut positions and regions when editing a video.
Definition: mythuieditbar.h:16
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
QVector< AnimationFrame > AnimationFrames
Definition: mythuiimage.h:88
QPair< MythImage *, int > AnimationFrame
Definition: mythuiimage.h:87
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.
void Init(void)