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:
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
Slide::kFailed
@ kFailed
Definition: galleryslide.h:188
SlideBuffer::GetNext
Slide & GetNext()
Definition: galleryslide.h:233
SequentialAnimation::Pulse
void Pulse(int interval) override
Progress sequential animation.
Definition: galleryslide.cpp:143
ParallelAnimation::ParallelAnimation
ParallelAnimation()=default
Slide::~Slide
~Slide() override
Destructor.
Definition: galleryslide.cpp:313
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:164
Slide
A specialised image for slideshows.
Definition: galleryslide.h:157
Slide::SetZoom
void SetZoom(float zoom)
Sets slide zoom.
Definition: galleryslide.cpp:477
SequentialAnimation::SequentialAnimation
SequentialAnimation()=default
ParallelAnimation::SetSpeed
void SetSpeed(float speed) override
Change speed of group and all child animations.
Definition: galleryslide.cpp:241
Slide::m_pan
QPoint m_pan
Pan position (0,0) = no pan.
Definition: galleryslide.h:199
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
slots
std::array< unsigned int, 4 > slots
Definition: element.cpp:38
MIN_ZOOM
#define MIN_ZOOM
Definition: galleryslide.h:20
AbstractAnimation::Finished
virtual void Finished()
To be called when animation completes.
Definition: galleryslide.h:40
Animation::m_centre
UIEffects::Centre m_centre
Definition: galleryslide.h:82
GroupAnimation::GroupAnimation
GroupAnimation()=default
Animation::HorizontalZoom
@ HorizontalZoom
Definition: galleryslide.h:59
SequentialAnimation::Finished
void Finished() override
A child animation has completed.
Definition: galleryslide.cpp:191
Slide::Pulse
void Pulse() override
Update pan & zoom animations.
Definition: galleryslide.cpp:562
SlideBuffer::SlideReady
void SlideReady(int count)
Signals that buffer has (count) loaded slides awaiting display.
ParallelAnimation::Finished
void Finished() override
A child animation has completed.
Definition: galleryslide.cpp:253
Slide::m_panAnimation
PanAnimation * m_panAnimation
Dedicated animation for panning, if supported.
Definition: galleryslide.h:198
Slide::Slide
Slide(MythUIType *parent, const QString &name, MythUIImage *image)
Clone slide from a theme MythUIImage.
Definition: galleryslide.cpp:281
PanAnimation::PanAnimation
PanAnimation(Slide *image)
Definition: galleryslide.h:150
Slide::SlideLoaded
void SlideLoaded()
An image has completed loading.
Definition: galleryslide.cpp:422
SequentialAnimation::m_current
int m_current
Index of child currently playing.
Definition: galleryslide.h:123
AbstractAnimation::Clear
virtual void Clear()
Definition: galleryslide.h:36
AbstractAnimation::m_forwards
bool m_forwards
Play direction.
Definition: galleryslide.h:47
SlideBuffer::SlideBuffer
SlideBuffer()=default
Animation::m_elapsed
int m_elapsed
Current millisec position within animation, 0..duration.
Definition: galleryslide.h:85
GroupAnimation::m_group
QList< AbstractAnimation * > m_group
Definition: galleryslide.h:104
Slide::kLoading
@ kLoading
Definition: galleryslide.h:188
Slide::CanZoomIn
bool CanZoomIn() const
Definition: galleryslide.h:170
Animation::Animation
Animation(Slide *image, Type type=Alpha)
Create simple animation.
Definition: galleryslide.h:66
mythuiimage.h
AbstractAnimation
Base animation class that is driven by a Myth pulse and implements variable speed.
Definition: galleryslide.h:28
MAX_ZOOM
#define MAX_ZOOM
Definition: galleryslide.h:21
Animation::Angle
@ Angle
Definition: galleryslide.h:59
AbstractAnimation::Pulse
virtual void Pulse(int interval)=0
SlideBuffer::ReleaseCurrent
void ReleaseCurrent()
Move head slide to back of queue and flush waiting slides.
Definition: galleryslide.cpp:701
Slide::m_data
ImagePtrK m_data
The image currently loading/loaded.
Definition: galleryslide.h:191
SlideBuffer::Flush
void Flush(Slide *slide, const QString &reason="Loaded")
Signal if any slides are waiting to be displayed.
Definition: galleryslide.cpp:729
Animation::m_type
Type m_type
Definition: galleryslide.h:81
Animation::Set
void Set(const QVariant &from, const QVariant &to, int duration=500, const QEasingCurve &curve=QEasingCurve::InOutCubic, UIEffects::Centre centre=UIEffects::Middle)
Initialises an animation.
Definition: galleryslide.cpp:45
Slide::kEmpty
@ kEmpty
Definition: galleryslide.h:188
SlideBuffer::Load
bool Load(const ImagePtrK &im, int direction)
Assign an image to next available slide, start loading and signal when done.
Definition: galleryslide.cpp:654
SlideBuffer::m_nextLoad
int m_nextLoad
Index of first spare slide, (or last slide if none spare)
Definition: galleryslide.h:252
AbstractAnimation::Start
virtual void Start(bool forwards, float speed=1.0)
Initialise & start base animation.
Definition: galleryslide.cpp:29
Animation::Pulse
void Pulse(int interval) override
Progress single animation.
Definition: galleryslide.cpp:77
AbstractAnimation::m_speed
float m_speed
Real-time = 1.0, Double-speed = 2.0.
Definition: galleryslide.h:49
SlideBuffer::Teardown
void Teardown()
Definition: galleryslide.cpp:579
PanAnimation::updateCurrentValue
void updateCurrentValue(const QVariant &value) override
Update pan value.
Definition: galleryslide.cpp:265
Slide::CanZoomOut
bool CanZoomOut() const
Definition: galleryslide.h:171
GroupAnimation
Abstract class for groups of animations.
Definition: galleryslide.h:91
UIEffects::Middle
@ Middle
Definition: mythuianimation.h:13
imagetypes.h
Common types used by Gallery.
Slide::Clear
void Clear()
Reset slide to unused state.
Definition: galleryslide.cpp:324
Slide::m_zoom
float m_zoom
Current zoom, 1.0 = fullsize.
Definition: galleryslide.h:194
Slide::IsLoaded
bool IsLoaded() const
Definition: galleryslide.h:173
GroupAnimation::Start
void Start(bool forwards, float speed=1.0) override
Initialise & start base animation.
Definition: galleryslide.h:96
Slide::SlideState
SlideState
Definition: galleryslide.h:188
Slide::Pan
void Pan(QPoint offset)
Initiate pan.
Definition: galleryslide.cpp:495
ParallelAnimation
A group of animations to be played simultaneously.
Definition: galleryslide.h:129
Slide::LoadSlide
bool LoadSlide(const ImagePtrK &im, int direction=0, bool notifyCompletion=false)
Load slide with an image.
Definition: galleryslide.cpp:363
Slide::SetPan
void SetPan(QPoint pos)
Sets slide pan.
Definition: galleryslide.cpp:525
Slide::ImageLoaded
void ImageLoaded(Slide *)
Generated when the last requested image has loaded.
Slide::GetImageData
ImagePtrK GetImageData() const
Definition: galleryslide.h:165
GroupAnimation::Pulse
void Pulse(int interval) override=0
SlideBuffer
Provides a queue/pool of slides.
Definition: galleryslide.h:216
Animation::m_parent
Slide * m_parent
Image to be animated.
Definition: galleryslide.h:80
Slide::m_state
SlideState m_state
Slide validity.
Definition: galleryslide.h:190
AbstractAnimation::m_running
bool m_running
True whilst animation is active.
Definition: galleryslide.h:48
SlideBuffer::Preload
void Preload(const ImagePtrK &im)
Load an image in next available slide.
Definition: galleryslide.cpp:679
SequentialAnimation
A group of animations to be played sequentially.
Definition: galleryslide.h:111
Slide::GetDebugState
QChar GetDebugState() const
Return debug status.
Definition: galleryslide.cpp:338
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:66
SlideBuffer::Initialise
void Initialise(MythUIImage &image)
Construct buffer.
Definition: galleryslide.cpp:593
Animation::Zoom
@ Zoom
Definition: galleryslide.h:59
Animation
A single animation controlling alpha, zoom, rotation and position.
Definition: galleryslide.h:56
Animation::Position
@ Position
Definition: galleryslide.h:59
Slide::Zoom
void Zoom(int percentage)
Initiate slide zoom.
Definition: galleryslide.cpp:451
SlideBuffer::m_mutexQ
QMutex m_mutexQ
Queue protection.
Definition: galleryslide.h:250
SequentialAnimation::Start
void Start(bool forwards, float speed=1.0) override
Start sequential animation.
Definition: galleryslide.cpp:158
AbstractAnimation::SetSpeed
virtual void SetSpeed(float speed)
Definition: galleryslide.h:34
Slide::kLoaded
@ kLoaded
Definition: galleryslide.h:188
Slide::m_zoomAnimation
Animation * m_zoomAnimation
Dedicated animation for zoom, if supported.
Definition: galleryslide.h:197
ParallelAnimation::Start
void Start(bool forwards, float speed=1.0) override
Start parallel group. All children play simultaneously.
Definition: galleryslide.cpp:223
GroupAnimation::SetSpeed
void SetSpeed(float speed) override
Definition: galleryslide.h:98
SlideBuffer::BufferState
QString BufferState()
Determines buffer state for debug logging.
Definition: galleryslide.cpp:633
Slide::GetDirection
int GetDirection() const
Definition: galleryslide.h:175
GroupAnimation::Add
virtual void Add(AbstractAnimation *child)
Add child animation to group.
Definition: galleryslide.cpp:121
SequentialAnimation::SetSpeed
void SetSpeed(float speed) override
Change speed of current child animation and all subsequent ones.
Definition: galleryslide.cpp:175
UIEffects::Centre
Centre
Definition: mythuianimation.h:12
ParallelAnimation::m_finished
int m_finished
Count of child animations that have finished.
Definition: galleryslide.h:141
Slide::m_direction
int m_direction
Navigation that created this image, -1 = Prev, 0 = Update, 1 = Next.
Definition: galleryslide.h:196
ParallelAnimation::Pulse
void Pulse(int interval) override
Progress parallel animations.
Definition: galleryslide.cpp:207
Animation::VerticalZoom
@ VerticalZoom
Definition: galleryslide.h:59
GroupAnimation::Clear
void Clear() override
Delete all child animations.
Definition: galleryslide.cpp:132
AbstractAnimation::Stop
virtual void Stop()
Definition: galleryslide.h:33
PanAnimation
Specialised animation for panning slideshow images (MythUI doesn't support panning)
Definition: galleryslide.h:148
SlideBuffer::m_queue
QQueue< Slide * > m_queue
Queue of slides.
Definition: galleryslide.h:251
SlideBuffer::GetCurrent
Slide & GetCurrent()
Definition: galleryslide.h:227
Slide::m_waitingFor
ImagePtrK m_waitingFor
The most recently requested image. Null for preloads. Differs from m_data when skipping.
Definition: galleryslide.h:193
Slide::FailedLoad
bool FailedLoad() const
Definition: galleryslide.h:174
Animation::Start
void Start(bool forwards=true, float speed=1.0) override
Start a single animation.
Definition: galleryslide.cpp:61
Animation::Type
Type
Supported effects.
Definition: galleryslide.h:59
Slide::IsEmpty
bool IsEmpty() const
Definition: galleryslide.h:172
GroupAnimation::~GroupAnimation
~GroupAnimation() override
Definition: galleryslide.h:94
SlideBuffer::~SlideBuffer
~SlideBuffer() override
Definition: galleryslide.cpp:573
Animation::None
@ None
Definition: galleryslide.h:59
Animation::Alpha
@ Alpha
Definition: galleryslide.h:59
AbstractAnimation::finished
void finished()
Signals animation has finished.
AbstractAnimation::AbstractAnimation
AbstractAnimation()=default
Animation::updateCurrentValue
void updateCurrentValue(const QVariant &value) override
Update animated value.
Definition: galleryslide.cpp:97