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
74protected:
75 void updateCurrentValue(const QVariant &value) override; // QVariantAnimation
76
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 std::chrono::milliseconds m_elapsed {0ms};
87};
88
89
92{
93public:
94 GroupAnimation() = default;
96 void Pulse() override = 0; // AbstractAnimation
97 void Start(bool forwards, float speed = 1.0) override // AbstractAnimation
98 { AbstractAnimation::Start(forwards, speed); }
99 void SetSpeed(float speed) override // AbstractAnimation
101 virtual void Add(AbstractAnimation *child);
102 void Clear() override; // AbstractAnimation
103
104protected:
105 QList<AbstractAnimation *> m_group;
106};
107
108
112{
113 Q_OBJECT
114public:
116 void Pulse() override; // GroupAnimation
117 void Start(bool forwards, float speed = 1.0) override; // GroupAnimation
118 void SetSpeed(float speed) override; // GroupAnimation
119
120protected slots:
121 void Finished() override; // AbstractAnimation
122
123protected:
124 int m_current {-1};
125};
126
127
130{
131 Q_OBJECT
132public:
133 ParallelAnimation() = default;
134 void Pulse() override; // GroupAnimation
135 void Start(bool forwards, float speed = 1.0) override; // GroupAnimation
136 void SetSpeed(float speed) override; // GroupAnimation
137
138protected slots:
139 void Finished() override; // AbstractAnimation
140
141protected:
142 int m_finished {0};
143};
144
145
149{
150public:
151 explicit PanAnimation(Slide *image) : Animation(image) {}
152protected:
153 void updateCurrentValue(const QVariant &value) override; // Animation
154};
155
156
158class Slide : public MythUIImage
159{
160 Q_OBJECT
161public:
162 Slide(MythUIType *parent, const QString& name, MythUIImage *image);
163 ~Slide() override;
164
165 void Clear();
166 bool LoadSlide(const ImagePtrK& im, int direction = 0, bool notifyCompletion = false);
167 ImagePtrK GetImageData() const { return m_data; }
168 void Zoom(int percentage);
169 void SetZoom(float zoom);
170 void Pan(QPoint offset);
171 void SetPan(QPoint pos);
172 bool CanZoomIn() const { return m_zoom < MAX_ZOOM; }
173 bool CanZoomOut() const { return m_zoom > MIN_ZOOM; }
174 bool IsEmpty() const { return m_state == kEmpty || !m_waitingFor; }
175 bool IsLoaded() const { return m_state >= kLoaded && m_waitingFor; }
176 bool FailedLoad() const { return m_state == kFailed; }
177 int GetDirection() const { return m_direction; }
178 void Pulse() override; // MythUIImage
179
180 QChar GetDebugState() const;
181
182public slots:
183 void SlideLoaded();
184
185signals:
188
189private:
190 enum SlideState : std::uint8_t { kEmpty, kLoading, kLoaded, kFailed }; // Order is significant
191
193 ImagePtrK m_data {nullptr};
196 float m_zoom {1.0F};
198 int m_direction {0};
201 QPoint m_pan {0,0};
202};
203
204
217class SlideBuffer : public QObject
218{
219 Q_OBJECT
220public:
221 SlideBuffer() = default;
222 ~SlideBuffer() override;
223
224 void Initialise(MythUIImage &image);
225 void Teardown();
226 bool Load(const ImagePtrK& im, int direction);
227 void Preload(const ImagePtrK& im);
228 void ReleaseCurrent();
230 {
231 QMutexLocker lock(&m_mutexQ);
232 return *(m_queue.head());
233 }
234
236 {
237 QMutexLocker lock(&m_mutexQ);
238 return *(m_queue.at(1));
239 }
240
241signals:
243 void SlideReady(int count);
244
245private slots:
246 void Flush(Slide *slide, const QString& reason);
247 void Flush(Slide *slide);
248
249protected:
250 QString BufferState();
251
252 // Must be recursive to enable Flush->signal->Get whilst retaining lock
253 QRecursiveMutex m_mutexQ;
254 QQueue<Slide*> m_queue;
255 int m_nextLoad {0};
256};
257
258#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:86
UIEffects::Centre m_centre
Definition: galleryslide.h:82
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:80
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:81
std::chrono::milliseconds m_elapsed
Current millisec position within animation, 0..duration.
Definition: galleryslide.h:85
Abstract class for groups of animations.
Definition: galleryslide.h:92
void Pulse() override=0
GroupAnimation()=default
void SetSpeed(float speed) override
Definition: galleryslide.h:99
~GroupAnimation() override
Definition: galleryslide.h:95
QList< AbstractAnimation * > m_group
Definition: galleryslide.h:105
void Clear() override
Delete all child animations.
void Start(bool forwards, float speed=1.0) override
Initialise & start base animation.
Definition: galleryslide.h:97
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:97
Specialised animation for panning slideshow images (MythUI doesn't support panning)
Definition: galleryslide.h:149
void updateCurrentValue(const QVariant &value) override
Update pan value.
PanAnimation(Slide *image)
Definition: galleryslide.h:151
A group of animations to be played simultaneously.
Definition: galleryslide.h:130
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:142
void Pulse() override
Progress parallel animations.
ParallelAnimation()=default
A group of animations to be played sequentially.
Definition: galleryslide.h:112
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:124
void SetSpeed(float speed) override
Change speed of current child animation and all subsequent ones.
Provides a queue/pool of slides.
Definition: galleryslide.h:218
Slide & GetNext()
Definition: galleryslide.h:235
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:229
int m_nextLoad
Index of first spare slide, (or last slide if none spare)
Definition: galleryslide.h:255
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:253
QQueue< Slide * > m_queue
Queue of slides.
Definition: galleryslide.h:254
void SlideReady(int count)
Signals that buffer has (count) loaded slides awaiting display.
~SlideBuffer() override
A specialised image for slideshows.
Definition: galleryslide.h:159
bool IsEmpty() const
Definition: galleryslide.h:174
int m_direction
Navigation that created this image, -1 = Prev, 0 = Update, 1 = Next.
Definition: galleryslide.h:198
QChar GetDebugState() const
Return debug status.
float m_zoom
Current zoom, 1.0 = fullsize.
Definition: galleryslide.h:196
void Pan(QPoint offset)
Initiate pan.
QPoint m_pan
Pan position (0,0) = no pan.
Definition: galleryslide.h:201
void ImageLoaded(Slide *)
Generated when the last requested image has loaded.
PanAnimation * m_panAnimation
Dedicated animation for panning, if supported.
Definition: galleryslide.h:200
bool IsLoaded() const
Definition: galleryslide.h:175
bool FailedLoad() const
Definition: galleryslide.h:176
void Zoom(int percentage)
Initiate slide zoom.
Animation * m_zoomAnimation
Dedicated animation for zoom, if supported.
Definition: galleryslide.h:199
bool CanZoomOut() const
Definition: galleryslide.h:173
int GetDirection() const
Definition: galleryslide.h:177
ImagePtrK GetImageData() const
Definition: galleryslide.h:167
ImagePtrK m_data
The image currently loading/loaded.
Definition: galleryslide.h:193
SlideState m_state
Slide validity.
Definition: galleryslide.h:192
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:190
void SlideLoaded()
An image has completed loading.
void Clear()
Reset slide to unused state.
bool CanZoomIn() const
Definition: galleryslide.h:172
~Slide() override
Destructor.
ImagePtrK m_waitingFor
The most recently requested image. Null for preloads. Differs from m_data when skipping.
Definition: galleryslide.h:195
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