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 
16 #include "libmythui/mythuiimage.h"
17 
18 // Min/max zoom extents available in slideshow
19 #define MIN_ZOOM (0.1F)
20 #define MAX_ZOOM (20.0F)
21 
22 class Slide;
23 
26 class AbstractAnimation : public QObject
27 {
28  Q_OBJECT
29 public:
30  AbstractAnimation() = default;
31  virtual void Start(bool forwards, float speed = 1.0);
32  virtual void Stop() { m_running = false; }
33  virtual void SetSpeed(float speed) { m_speed = speed; }
34  virtual void Pulse() = 0;
35  virtual void Clear() {}
36 
37 protected slots:
39  virtual void Finished() { m_running = false; emit finished(); }
40 
41 signals:
43  void finished();
44 
45 protected:
46  bool m_forwards {true};
47  bool m_running {false};
48  float m_speed {0.0F};
49 };
50 
51 
54 class Animation : public AbstractAnimation, public QVariantAnimation
55 {
56 public:
59 
65  explicit Animation(Slide *image, Type type = Alpha)
66  : m_parent(image), m_type(type) {}
67  void Start(bool forwards = true, float speed = 1.0) override; // AbstractAnimation
68  void Pulse() override; // AbstractAnimation
69  void Set(const QVariant& from, const QVariant& to,
70  std::chrono::milliseconds duration = 500ms,
71  const QEasingCurve& curve = QEasingCurve::InOutCubic,
73  void updateCurrentValue(const QVariant &value) override; // QVariantAnimation
74 
75 protected:
77  // Should be MythUItype but that impacts elsewhere: SetZoom must become
78  // virtual, which causes compiler (fn hiding) warnings in subtitles
79  Slide *m_parent {nullptr};
84  std::chrono::milliseconds m_elapsed {0ms};
86 };
87 
88 
91 {
92 public:
93  GroupAnimation() = default;
95  void Pulse() 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() 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() 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);
245  void Flush(Slide *slide);
246 
247 protected:
248  QString BufferState();
249 
250  // Must be recursive to enable Flush->signal->Get whilst retaining lock
251  QRecursiveMutex m_mutexQ;
252  QQueue<Slide*> m_queue;
253  int m_nextLoad {0};
254 };
255 
256 #endif // GALLERYSLIDE_H
Slide::kFailed
@ kFailed
Definition: galleryslide.h:188
SlideBuffer::GetNext
Slide & GetNext()
Definition: galleryslide.h:233
ParallelAnimation::ParallelAnimation
ParallelAnimation()=default
Slide::~Slide
~Slide() override
Destructor.
Definition: galleryslide.cpp:314
Animation::m_elapsed
std::chrono::milliseconds m_elapsed
Current millisec position within animation, 0..duration.
Definition: galleryslide.h:84
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
Slide
A specialised image for slideshows.
Definition: galleryslide.h:156
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:242
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:97
MIN_ZOOM
#define MIN_ZOOM
Definition: galleryslide.h:19
AbstractAnimation::Finished
virtual void Finished()
To be called when animation completes.
Definition: galleryslide.h:39
Animation::m_centre
UIEffects::Centre m_centre
Definition: galleryslide.h:81
GroupAnimation::GroupAnimation
GroupAnimation()=default
Animation::HorizontalZoom
@ HorizontalZoom
Definition: galleryslide.h:58
SequentialAnimation::Finished
void Finished() override
A child animation has completed.
Definition: galleryslide.cpp:194
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:254
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:282
PanAnimation::PanAnimation
PanAnimation(Slide *image)
Definition: galleryslide.h:150
Slide::SlideLoaded
void SlideLoaded()
An image has completed loading.
Definition: galleryslide.cpp:423
SequentialAnimation::m_current
int m_current
Index of child currently playing.
Definition: galleryslide.h:123
Animation::m_lastUpdate
std::chrono::milliseconds m_lastUpdate
Definition: galleryslide.h:85
AbstractAnimation::Clear
virtual void Clear()
Definition: galleryslide.h:35
AbstractAnimation::m_forwards
bool m_forwards
Play direction.
Definition: galleryslide.h:46
SlideBuffer::SlideBuffer
SlideBuffer()=default
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:65
mythuiimage.h
AbstractAnimation
Base animation class that is driven by a Myth pulse and implements variable speed.
Definition: galleryslide.h:26
MAX_ZOOM
#define MAX_ZOOM
Definition: galleryslide.h:20
Animation::Angle
@ Angle
Definition: galleryslide.h:58
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
Animation::m_type
Type m_type
Definition: galleryslide.h:80
Animation::Pulse
void Pulse() override
Progress single animation.
Definition: galleryslide.cpp:81
Animation::Set
void Set(const QVariant &from, const QVariant &to, std::chrono::milliseconds duration=500ms, const QEasingCurve &curve=QEasingCurve::InOutCubic, UIEffects::Centre centre=UIEffects::Middle)
Initialises an animation.
Definition: galleryslide.cpp:49
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:253
AbstractAnimation::Start
virtual void Start(bool forwards, float speed=1.0)
Initialise & start base animation.
Definition: galleryslide.cpp:33
AbstractAnimation::m_speed
float m_speed
Real-time = 1.0, Double-speed = 2.0.
Definition: galleryslide.h:48
SlideBuffer::Teardown
void Teardown()
Definition: galleryslide.cpp:579
PanAnimation::updateCurrentValue
void updateCurrentValue(const QVariant &value) override
Update pan value.
Definition: galleryslide.cpp:266
Slide::CanZoomOut
bool CanZoomOut() const
Definition: galleryslide.h:171
GroupAnimation
Abstract class for groups of animations.
Definition: galleryslide.h:90
SlideBuffer::Flush
void Flush(Slide *slide, const QString &reason)
Signal if any slides are waiting to be displayed.
Definition: galleryslide.cpp:729
UIEffects::Middle
@ Middle
Definition: mythuianimation.h:17
imagetypes.h
Common types used by Gallery.
Slide::Clear
void Clear()
Reset slide to unused state.
Definition: galleryslide.cpp:325
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:128
Slide::LoadSlide
bool LoadSlide(const ImagePtrK &im, int direction=0, bool notifyCompletion=false)
Load slide with an image.
Definition: galleryslide.cpp:364
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
SlideBuffer
Provides a queue/pool of slides.
Definition: galleryslide.h:215
Animation::m_parent
Slide * m_parent
Image to be animated.
Definition: galleryslide.h:79
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:47
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:110
Slide::GetDebugState
QChar GetDebugState() const
Return debug status.
Definition: galleryslide.cpp:339
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:85
SlideBuffer::Initialise
void Initialise(MythUIImage &image)
Construct buffer.
Definition: galleryslide.cpp:593
Animation::Zoom
@ Zoom
Definition: galleryslide.h:58
Animation
A single animation controlling alpha, zoom, rotation and position.
Definition: galleryslide.h:54
GroupAnimation::Pulse
void Pulse() override=0
Animation::Position
@ Position
Definition: galleryslide.h:58
MythDate::currentMSecsSinceEpochAsDuration
std::chrono::milliseconds currentMSecsSinceEpochAsDuration(void)
Definition: mythdate.cpp:198
Slide::Zoom
void Zoom(int percentage)
Initiate slide zoom.
Definition: galleryslide.cpp:452
SlideBuffer::m_mutexQ
QRecursiveMutex m_mutexQ
Queue protection.
Definition: galleryslide.h:251
SequentialAnimation::Start
void Start(bool forwards, float speed=1.0) override
Start sequential animation.
Definition: galleryslide.cpp:161
AbstractAnimation::SetSpeed
virtual void SetSpeed(float speed)
Definition: galleryslide.h:33
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:224
GroupAnimation::SetSpeed
void SetSpeed(float speed) override
Definition: galleryslide.h:98
AbstractAnimation::Pulse
virtual void Pulse()=0
SequentialAnimation::Pulse
void Pulse() override
Progress sequential animation.
Definition: galleryslide.cpp:146
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:126
SequentialAnimation::SetSpeed
void SetSpeed(float speed) override
Change speed of current child animation and all subsequent ones.
Definition: galleryslide.cpp:178
UIEffects::Centre
Centre
Definition: mythuianimation.h:16
ParallelAnimation::m_finished
int m_finished
Count of child animations that have finished.
Definition: galleryslide.h:141
ParallelAnimation::Pulse
void Pulse() override
Progress parallel animations.
Definition: galleryslide.cpp:208
Slide::m_direction
int m_direction
Navigation that created this image, -1 = Prev, 0 = Update, 1 = Next.
Definition: galleryslide.h:196
Animation::VerticalZoom
@ VerticalZoom
Definition: galleryslide.h:58
GroupAnimation::Clear
void Clear() override
Delete all child animations.
Definition: galleryslide.cpp:137
AbstractAnimation::Stop
virtual void Stop()
Definition: galleryslide.h:32
PanAnimation
Specialised animation for panning slideshow images (MythUI doesn't support panning)
Definition: galleryslide.h:147
SlideBuffer::m_queue
QQueue< Slide * > m_queue
Queue of slides.
Definition: galleryslide.h:252
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:66
Animation::Type
Type
Supported effects.
Definition: galleryslide.h:58
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:58
Animation::Alpha
@ Alpha
Definition: galleryslide.h:58
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:102