MythTV master
galleryslide.h
Go to the documentation of this file.
1
9
10#ifndef GALLERYSLIDE_H
11#define GALLERYSLIDE_H
12
13#include <QQueue>
14
17
18// Min/max zoom extents available in slideshow
19#define MIN_ZOOM (0.1F)
20#define MAX_ZOOM (20.0F)
21
22class Slide;
23
26class AbstractAnimation : public QObject
27{
28 Q_OBJECT
29public:
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
37protected slots:
39 virtual void Finished() { m_running = false; emit finished(); }
40
41signals:
43 void finished();
44
45protected:
46 bool m_forwards {true};
47 bool m_running {false};
48 float m_speed {0.0F};
49};
50
51
54class Animation : public AbstractAnimation, public QVariantAnimation
55{
56public:
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
75protected:
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{
92public:
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
100 virtual void Add(AbstractAnimation *child);
101 void Clear() override; // AbstractAnimation
102
103protected:
104 QList<AbstractAnimation *> m_group;
105};
106
107
111{
112 Q_OBJECT
113public:
115 void Pulse() override; // GroupAnimation
116 void Start(bool forwards, float speed = 1.0) override; // GroupAnimation
117 void SetSpeed(float speed) override; // GroupAnimation
118
119protected slots:
120 void Finished() override; // AbstractAnimation
121
122protected:
123 int m_current {-1};
124};
125
126
129{
130 Q_OBJECT
131public:
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
137protected slots:
138 void Finished() override; // AbstractAnimation
139
140protected:
141 int m_finished {0};
142};
143
144
148{
149public:
150 explicit PanAnimation(Slide *image) : Animation(image) {}
151 void updateCurrentValue(const QVariant &value) override; // Animation
152};
153
154
156class Slide : public MythUIImage
157{
158 Q_OBJECT
159public:
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
180public slots:
181 void SlideLoaded();
182
183signals:
186
187private:
188 enum SlideState : std::uint8_t { kEmpty, kLoading, kLoaded, kFailed }; // Order is significant
189
191 ImagePtrK m_data {nullptr};
194 float m_zoom {1.0F};
196 int m_direction {0};
199 QPoint m_pan {0,0};
200};
201
202
215class SlideBuffer : public QObject
216{
217 Q_OBJECT
218public:
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
239signals:
241 void SlideReady(int count);
242
243private slots:
244 void Flush(Slide *slide, const QString& reason);
245 void Flush(Slide *slide);
246
247protected:
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
Base animation class that is driven by a Myth pulse and implements variable speed.
Definition: galleryslide.h:27
virtual void Finished()
To be called when animation completes.
Definition: galleryslide.h:39
virtual void Pulse()=0
virtual void Stop()
Definition: galleryslide.h:32
void finished()
Signals animation has finished.
virtual void Clear()
Definition: galleryslide.h:35
virtual void SetSpeed(float speed)
Definition: galleryslide.h:33
virtual void Start(bool forwards, float speed=1.0)
Initialise & start base animation.
float m_speed
Real-time = 1.0, Double-speed = 2.0.
Definition: galleryslide.h:48
AbstractAnimation()=default
bool m_forwards
Play direction.
Definition: galleryslide.h:46
bool m_running
True whilst animation is active.
Definition: galleryslide.h:47
A single animation controlling alpha, zoom, rotation and position.
Definition: galleryslide.h:55
Type
Supported effects.
Definition: galleryslide.h:58
@ HorizontalZoom
Definition: galleryslide.h:58
std::chrono::milliseconds m_lastUpdate
Definition: galleryslide.h:85
UIEffects::Centre m_centre
Definition: galleryslide.h:81
void updateCurrentValue(const QVariant &value) override
Update animated value.
Animation(Slide *image, Type type=Alpha)
Create simple animation.
Definition: galleryslide.h:65
void Start(bool forwards=true, float speed=1.0) override
Start a single animation.
Slide * m_parent
Image to be animated.
Definition: galleryslide.h:79
void Pulse() override
Progress single animation.
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.
Type m_type
Definition: galleryslide.h:80
std::chrono::milliseconds m_elapsed
Current millisec position within animation, 0..duration.
Definition: galleryslide.h:84
Abstract class for groups of animations.
Definition: galleryslide.h:91
void Pulse() override=0
GroupAnimation()=default
void SetSpeed(float speed) override
Definition: galleryslide.h:98
~GroupAnimation() override
Definition: galleryslide.h:94
QList< AbstractAnimation * > m_group
Definition: galleryslide.h:104
void Clear() override
Delete all child animations.
void Start(bool forwards, float speed=1.0) override
Initialise & start base animation.
Definition: galleryslide.h:96
virtual void Add(AbstractAnimation *child)
Add child animation to group.
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
Specialised animation for panning slideshow images (MythUI doesn't support panning)
Definition: galleryslide.h:148
void updateCurrentValue(const QVariant &value) override
Update pan value.
PanAnimation(Slide *image)
Definition: galleryslide.h:150
A group of animations to be played simultaneously.
Definition: galleryslide.h:129
void SetSpeed(float speed) override
Change speed of group and all child animations.
void Finished() override
A child animation has completed.
void Start(bool forwards, float speed=1.0) override
Start parallel group. All children play simultaneously.
int m_finished
Count of child animations that have finished.
Definition: galleryslide.h:141
void Pulse() override
Progress parallel animations.
ParallelAnimation()=default
A group of animations to be played sequentially.
Definition: galleryslide.h:111
void Start(bool forwards, float speed=1.0) override
Start sequential animation.
void Finished() override
A child animation has completed.
SequentialAnimation()=default
void Pulse() override
Progress sequential animation.
int m_current
Index of child currently playing.
Definition: galleryslide.h:123
void SetSpeed(float speed) override
Change speed of current child animation and all subsequent ones.
Provides a queue/pool of slides.
Definition: galleryslide.h:216
Slide & GetNext()
Definition: galleryslide.h:233
QString BufferState()
Determines buffer state for debug logging.
void Flush(Slide *slide, const QString &reason)
Signal if any slides are waiting to be displayed.
void ReleaseCurrent()
Move head slide to back of queue and flush waiting slides.
void Initialise(MythUIImage &image)
Construct buffer.
Slide & GetCurrent()
Definition: galleryslide.h:227
int m_nextLoad
Index of first spare slide, (or last slide if none spare)
Definition: galleryslide.h:253
bool Load(const ImagePtrK &im, int direction)
Assign an image to next available slide, start loading and signal when done.
void Preload(const ImagePtrK &im)
Load an image in next available slide.
SlideBuffer()=default
QRecursiveMutex m_mutexQ
Queue protection.
Definition: galleryslide.h:251
QQueue< Slide * > m_queue
Queue of slides.
Definition: galleryslide.h:252
void SlideReady(int count)
Signals that buffer has (count) loaded slides awaiting display.
~SlideBuffer() override
A specialised image for slideshows.
Definition: galleryslide.h:157
bool IsEmpty() const
Definition: galleryslide.h:172
int m_direction
Navigation that created this image, -1 = Prev, 0 = Update, 1 = Next.
Definition: galleryslide.h:196
QChar GetDebugState() const
Return debug status.
float m_zoom
Current zoom, 1.0 = fullsize.
Definition: galleryslide.h:194
void Pan(QPoint offset)
Initiate pan.
QPoint m_pan
Pan position (0,0) = no pan.
Definition: galleryslide.h:199
void ImageLoaded(Slide *)
Generated when the last requested image has loaded.
PanAnimation * m_panAnimation
Dedicated animation for panning, if supported.
Definition: galleryslide.h:198
bool IsLoaded() const
Definition: galleryslide.h:173
bool FailedLoad() const
Definition: galleryslide.h:174
void Zoom(int percentage)
Initiate slide zoom.
Animation * m_zoomAnimation
Dedicated animation for zoom, if supported.
Definition: galleryslide.h:197
bool CanZoomOut() const
Definition: galleryslide.h:171
int GetDirection() const
Definition: galleryslide.h:175
ImagePtrK GetImageData() const
Definition: galleryslide.h:165
ImagePtrK m_data
The image currently loading/loaded.
Definition: galleryslide.h:191
SlideState m_state
Slide validity.
Definition: galleryslide.h:190
void SetZoom(float zoom)
Sets slide zoom.
bool LoadSlide(const ImagePtrK &im, int direction=0, bool notifyCompletion=false)
Load slide with an image.
void SetPan(QPoint pos)
Sets slide pan.
void Pulse() override
Update pan & zoom animations.
@ kLoading
Definition: galleryslide.h:188
void SlideLoaded()
An image has completed loading.
void Clear()
Reset slide to unused state.
bool CanZoomIn() const
Definition: galleryslide.h:170
~Slide() override
Destructor.
ImagePtrK m_waitingFor
The most recently requested image. Null for preloads. Differs from m_data when skipping.
Definition: galleryslide.h:193
Slide(MythUIType *parent, const QString &name, MythUIImage *image)
Clone slide from a theme MythUIImage.
#define MAX_ZOOM
Definition: galleryslide.h:20
#define MIN_ZOOM
Definition: galleryslide.h:19
Common types used by Gallery.
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
std::chrono::milliseconds currentMSecsSinceEpochAsDuration(void)
Definition: mythdate.cpp:207