MythTV  master
galleryslide.h
Go to the documentation of this file.
1 
10 #ifndef GALLERYSLIDE_H
11 #define GALLERYSLIDE_H
12 
13 #include <QQueue>
14 
15 #include "mythuiimage.h"
16 #include "imagetypes.h"
17 
18 
19 // Min/max zoom extents available in slideshow
20 #define MIN_ZOOM (0.1F)
21 #define MAX_ZOOM (20.0F)
22 
23 class Slide;
24 
27 class AbstractAnimation : public QObject
28 {
29  Q_OBJECT
30 public:
31  AbstractAnimation() = default;
32  virtual void Start(bool forwards, float speed = 1.0);
33  virtual void Stop() { m_running = false; }
34  virtual void SetSpeed(float speed) { m_speed = speed; }
35  virtual void Pulse(int interval) = 0;
36  virtual void Clear() {}
37 
38 protected slots:
40  virtual void Finished() { m_running = false; emit finished(); }
41 
42 signals:
44  void finished();
45 
46 protected:
47  bool m_forwards {true};
48  bool m_running {false};
49  float m_speed {0.0F};
50 };
51 
52 
55 class Animation : public AbstractAnimation, public QVariantAnimation
56 {
57 public:
60 
66  explicit Animation(Slide *image, Type type = Alpha)
67  : m_parent(image), m_type(type) {}
68  void Start(bool forwards = true, float speed = 1.0) override; // AbstractAnimation
69  void Pulse(int interval) override; // AbstractAnimation
70  void Set(const QVariant& from, const QVariant& to,
71  int duration = 500,
72  const QEasingCurve& curve = QEasingCurve::InOutCubic,
74  void updateCurrentValue(const QVariant &value) override; // QVariantAnimation
75 
76 protected:
78  // Should be MythUItype but that impacts elsewhere: SetZoom must become
79  // virtual, which causes compiler (fn hiding) warnings in subtitles
80  Slide *m_parent {nullptr};
85  int m_elapsed {0};
86 };
87 
88 
91 {
92 public:
93  GroupAnimation() = default;
95  void Pulse(int interval) override = 0; // AbstractAnimation
96  void Start(bool forwards, float speed = 1.0) override // AbstractAnimation
97  { AbstractAnimation::Start(forwards, speed); }
98  void SetSpeed(float speed) override // AbstractAnimation
99  { AbstractAnimation::SetSpeed(speed); }
100  virtual void Add(AbstractAnimation *child);
101  void Clear() override; // AbstractAnimation
102 
103 protected:
104  QList<AbstractAnimation *> m_group;
105 };
106 
107 
111 {
112  Q_OBJECT
113 public:
114  SequentialAnimation() = default;
115  void Pulse(int interval) override; // GroupAnimation
116  void Start(bool forwards, float speed = 1.0) override; // GroupAnimation
117  void SetSpeed(float speed) override; // GroupAnimation
118 
119 protected slots:
120  void Finished() override; // AbstractAnimation
121 
122 protected:
123  int m_current {-1};
124 };
125 
126 
129 {
130  Q_OBJECT
131 public:
132  ParallelAnimation() = default;
133  void Pulse(int interval) override; // GroupAnimation
134  void Start(bool forwards, float speed = 1.0) override; // GroupAnimation
135  void SetSpeed(float speed) override; // GroupAnimation
136 
137 protected slots:
138  void Finished() override; // AbstractAnimation
139 
140 protected:
141  int m_finished {0};
142 };
143 
144 
147 class PanAnimation : public Animation
148 {
149 public:
150  explicit PanAnimation(Slide *image) : Animation(image) {}
151  void updateCurrentValue(const QVariant &value) override; // Animation
152 };
153 
154 
156 class Slide : public MythUIImage
157 {
158  Q_OBJECT
159 public:
160  Slide(MythUIType *parent, const QString& name, MythUIImage *image);
161  ~Slide() override;
162 
163  void Clear();
164  bool LoadSlide(const ImagePtrK& im, int direction = 0, bool notifyCompletion = false);
165  ImagePtrK GetImageData() const { return m_data; }
166  void Zoom(int percentage);
167  void SetZoom(float zoom);
168  void Pan(QPoint offset);
169  void SetPan(QPoint pos);
170  bool CanZoomIn() const { return m_zoom < MAX_ZOOM; }
171  bool CanZoomOut() const { return m_zoom > MIN_ZOOM; }
172  bool IsEmpty() const { return m_state == kEmpty || !m_waitingFor; }
173  bool IsLoaded() const { return m_state >= kLoaded && m_waitingFor; }
174  bool FailedLoad() const { return m_state == kFailed; }
175  int GetDirection() const { return m_direction; }
176  void Pulse() override; // MythUIImage
177 
178  QChar GetDebugState() const;
179 
180 public slots:
181  void SlideLoaded();
182 
183 signals:
185  void ImageLoaded(Slide*);
186 
187 private:
188  enum SlideState { kEmpty, kLoading, kLoaded, kFailed }; // Order is significant
189 
191  ImagePtrK m_data {nullptr};
192  ImagePtrK m_waitingFor {nullptr};
194  float m_zoom {1.0F};
195  int m_direction {0};
199  QPoint m_pan {0,0};
200 };
201 
202 
215 class SlideBuffer : public QObject
216 {
217  Q_OBJECT
218 public:
219  SlideBuffer() = default;
220  ~SlideBuffer() override;
221 
222  void Initialise(MythUIImage &image);
223  void Teardown();
224  bool Load(const ImagePtrK& im, int direction);
225  void Preload(const ImagePtrK& im);
226  void ReleaseCurrent();
228  {
229  QMutexLocker lock(&m_mutexQ);
230  return *(m_queue.head());
231  }
232 
234  {
235  QMutexLocker lock(&m_mutexQ);
236  return *(m_queue.at(1));
237  }
238 
239 signals:
241  void SlideReady(int count);
242 
243 private slots:
244  void Flush(Slide *slide, const QString& reason = "Loaded");
245 
246 protected:
247  QString BufferState();
248 
249  // Must be recursive to enable Flush->signal->Get whilst retaining lock
250  QMutex m_mutexQ {QMutex::Recursive};
251  QQueue<Slide*> m_queue;
252  int m_nextLoad {0};
253 };
254 
255 #endif // GALLERYSLIDE_H
void SetSpeed(float speed) override
Change speed of group and all child animations.
Slide & GetNext()
Definition: galleryslide.h:233
QPoint m_pan
Pan position (0,0) = no pan.
Definition: galleryslide.h:199
void SetZoom(float zoom)
Sets slide zoom.
PanAnimation * m_panAnimation
Dedicated animation for panning, if supported.
Definition: galleryslide.h:198
unsigned int slots[4]
Definition: element.c:38
ParallelAnimation()=default
int m_elapsed
Current millisec position within animation, 0..duration.
Definition: galleryslide.h:85
void finished()
Signals animation has finished.
AbstractAnimation()=default
bool CanZoomIn() const
Definition: galleryslide.h:170
void Pulse() override
Update pan & zoom animations.
void SlideLoaded()
An image has completed loading.
virtual void Finished()
To be called when animation completes.
Definition: galleryslide.h:40
virtual void Add(AbstractAnimation *child)
Add child animation to group.
GroupAnimation()=default
Animation(Slide *image, Type type=Alpha)
Create simple animation.
Definition: galleryslide.h:66
Slide(MythUIType *parent, const QString &name, MythUIImage *image)
Clone slide from a theme MythUIImage.
Specialised animation for panning slideshow images (MythUI doesn't support panning)
Definition: galleryslide.h:147
bool m_forwards
Play direction.
Definition: galleryslide.h:47
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
A group of animations to be played simultaneously.
Definition: galleryslide.h:128
void Start(bool forwards, float speed=1.0) override
Start sequential animation.
void Finished() override
A child animation has completed.
virtual void Pulse(int interval)=0
Base animation class that is driven by a Myth pulse and implements variable speed.
Definition: galleryslide.h:27
#define MAX_ZOOM
Definition: galleryslide.h:21
int m_nextLoad
Index of first spare slide, (or last slide if none spare)
Definition: galleryslide.h:252
bool Load(const ImagePtrK &im, int direction)
Assign an image to next available slide, start loading and signal when done.
A group of animations to be played sequentially.
Definition: galleryslide.h:110
ImagePtrK m_data
The image currently loading/loaded.
Definition: galleryslide.h:191
virtual void Clear()
Definition: galleryslide.h:36
SlideBuffer()=default
void updateCurrentValue(const QVariant &value) override
Update pan value.
void Pulse(int interval) override=0
bool CanZoomOut() const
Definition: galleryslide.h:171
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
void ReleaseCurrent()
Move head slide to back of queue and flush waiting slides.
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:172
virtual void Start(bool forwards, float speed=1.0)
Initialise & start base animation.
~GroupAnimation() override
Definition: galleryslide.h:94
Provides a queue/pool of slides.
Definition: galleryslide.h:215
float m_zoom
Current zoom, 1.0 = fullsize.
Definition: galleryslide.h:194
ImagePtrK GetImageData() const
Definition: galleryslide.h:165
void Flush(Slide *slide, const QString &reason="Loaded")
Signal if any slides are waiting to be displayed.
void Pulse(int interval) override
Progress sequential animation.
bool m_running
True whilst animation is active.
Definition: galleryslide.h:48
void Finished() override
A child animation has completed.
void Initialise(MythUIImage &image)
Construct buffer.
void updateCurrentValue(const QVariant &value) override
Update animated value.
void Preload(const ImagePtrK &im)
Load an image in next available slide.
void SetSpeed(float speed) override
Definition: galleryslide.h:98
QMutex m_mutexQ
Queue protection.
Definition: galleryslide.h:250
void Pan(QPoint offset)
Initiate pan.
virtual void SetSpeed(float speed)
Definition: galleryslide.h:34
SlideState m_state
Slide validity.
Definition: galleryslide.h:190
bool LoadSlide(const ImagePtrK &im, int direction=0, bool notifyCompletion=false)
Load slide with an image.
Type
Supported effects.
Definition: galleryslide.h:59
float m_speed
Real-time = 1.0, Double-speed = 2.0.
Definition: galleryslide.h:49
bool IsLoaded() const
Definition: galleryslide.h:173
QList< AbstractAnimation * > m_group
Definition: galleryslide.h:104
QChar GetDebugState() const
Return debug status.
void SetSpeed(float speed) override
Change speed of current child animation and all subsequent ones.
void Clear()
Reset slide to unused state.
PanAnimation(Slide *image)
Definition: galleryslide.h:150
void SetPan(QPoint pos)
Sets slide pan.
void ImageLoaded(Slide *)
Generated when the last requested image has loaded.
Common types used by Gallery.
#define MIN_ZOOM
Definition: galleryslide.h:20
SequentialAnimation()=default
Slide * m_parent
Image to be animated.
Definition: galleryslide.h:80
void Start(bool forwards, float speed=1.0) override
Initialise & start base animation.
Definition: galleryslide.h:96
bool FailedLoad() const
Definition: galleryslide.h:174
void Zoom(int percentage)
Initiate slide zoom.
A specialised image for slideshows.
Definition: galleryslide.h:156
int m_direction
Navigation that created this image, -1 = Prev, 0 = Update, 1 = Next.
Definition: galleryslide.h:196
QQueue< Slide * > m_queue
Queue of slides.
Definition: galleryslide.h:251
ImagePtrK m_waitingFor
The most recently requested image. Null for preloads. Differs from m_data when skipping.
Definition: galleryslide.h:193
A single animation controlling alpha, zoom, rotation and position.
Definition: galleryslide.h:55
virtual void Stop()
Definition: galleryslide.h:33
~SlideBuffer() override
Animation * m_zoomAnimation
Dedicated animation for zoom, if supported.
Definition: galleryslide.h:197
void Set(const QVariant &from, const QVariant &to, int duration=500, const QEasingCurve &curve=QEasingCurve::InOutCubic, UIEffects::Centre centre=UIEffects::Middle)
Initialises an animation.
void Start(bool forwards, float speed=1.0) override
Start parallel group. All children play simultaneously.
int m_current
Index of child currently playing.
Definition: galleryslide.h:123
int GetDirection() const
Definition: galleryslide.h:175
Slide & GetCurrent()
Definition: galleryslide.h:227
void Pulse(int interval) override
Progress parallel animations.
bool IsEmpty() const
Definition: galleryslide.h:172
void Pulse(int interval) override
Progress single animation.
QString BufferState()
Determines buffer state for debug logging.
void Clear() override
Delete all child animations.
int m_finished
Count of child animations that have finished.
Definition: galleryslide.h:141
UIEffects::Centre m_centre
Definition: galleryslide.h:82
~Slide() override
Destructor.
void Start(bool forwards=true, float speed=1.0) override
Start a single animation.
Abstract class for groups of animations.
Definition: galleryslide.h:90
void SlideReady(int count)
Signals that buffer has (count) loaded slides awaiting display.
Type m_type
Definition: galleryslide.h:81