MythTV master
gallerytransitions.cpp
Go to the documentation of this file.
2
3#include <utility>
4
8
9#define LOC QString("Transition: ")
10
11
12Transition::Transition(const QString& name)
13 : m_duration(gCoreContext->GetDurSetting<std::chrono::milliseconds>("GalleryTransitionTime", 1s))
14{
15 setObjectName(name);
16}
17
18
26{
27 // Guard against garbage
28 int value = (setting >= kNoTransition && setting < kLastTransSentinel)
29 ? setting : kNoTransition;
30
31 // If chosen transition isn't viable for painter then use previous ones.
32 // First transition must always be useable by all painters
33 Transition *result = nullptr;
34 while (value >= kNoTransition && !result)
35 result = m_map.value(value--, nullptr);
36
37 if (result)
38 return *result;
39
40 LOG(VB_GENERAL, LOG_CRIT,
41 LOC + QString("No transitions found for setting %1").arg(setting));
42
43 return m_immediate;
44}
45
46
52{
53 // Create all non-animated transitions to be used by Random
56
57 // Create all animated transitions to be used by Random
58 if (includeAnimations)
59 {
63 }
64
65 // Create random set from those already defined
66 m_map.insert(kRandomTransition, new TransitionRandom(m_map.values()));
67
68 // Create other transitions that aren't to be used by Random
69 m_map.insert(kNoTransition, new TransitionNone());
70}
71
72
81 bool forwards, float speed)
82{
83 LOG(VB_FILE, LOG_DEBUG, LOC +
84 QString("Starting transition %1 -> %2 (forwards= %3, speed= %4)")
85 .arg(from.objectName(), to.objectName()).arg(forwards).arg(speed));
86
87 m_old = &from;
88 m_new = &to;
89
90 // When playing forwards next image replaces prev image
91 // When playing backwards prev image replaces next image
92 m_prev = forwards ? m_old : m_new;
93 m_next = forwards ? m_new : m_old;
94
95 // Set up transition
96 Initialise();
97
98 // Make new image visible
99 m_new->SetVisible(true);
100}
101
102
107{
108 // Hide old image before it is reset
109 m_old->SetVisible(false);
110
111 // Undo transition effects
112 Finalise();
113
114 LOG(VB_FILE, LOG_DEBUG, LOC +
115 QString("Finished transition to %1").arg(m_new->objectName()));
116
117 emit finished();
118}
119
120
129 bool forwards, float speed)
130{
131 Transition::Start(from, to, forwards, speed);
132
133 // Finish immediately
134 Finished();
135}
136
137
144GroupTransition::GroupTransition(GroupAnimation *animation, const QString& name)
145 : Transition(name), m_animation(animation)
146{
147 // Complete transition when the group finishes
149}
150
151
156{
157 // Group owns animation
158 delete m_animation;
159}
160
161
170 bool forwards, float speed)
171{
172 // Clear previous transition
174
175 Transition::Start(from, to, forwards, speed);
176
177 // Start group
178 m_animation->Start(forwards, speed);
179}
180
181
187{
188 if (m_animation)
189 m_animation->SetSpeed(speed);
190}
191
192
196{
197 if (m_animation)
199}
200
201
206{
207 // Fade out prev image
208 auto *oldPic = new Animation(m_prev, Animation::Alpha);
209 oldPic->Set(255, 0, m_duration, QEasingCurve::InOutQuad);
210 m_animation->Add(oldPic);
211
212 // Fade in next image
213 auto *newPic = new Animation(m_next, Animation::Alpha);
214 newPic->Set(0, 255, m_duration, QEasingCurve::InOutQuad);
215 m_animation->Add(newPic);
216
217 // Hide new image until it's needed
218 m_new->SetAlpha(0);
219}
220
221
226{
227 // Undo effects of the transition
228 m_old->SetAlpha(255);
229}
230
231
236{
237 // Reduce hzoom of left image to nothing
238 auto *oldPic = new Animation(m_prev, Animation::HorizontalZoom);
239 oldPic->Set(1.0, 0.0, m_duration / 2, QEasingCurve::InQuart);
240 m_animation->Add(oldPic);
241
242 // Increase hzoom of right image from nothing to full
243 auto *newPic = new Animation(m_next, Animation::HorizontalZoom);
244 newPic->Set(0.0, 1.0, m_duration / 2, QEasingCurve::OutQuart);
245 m_animation->Add(newPic);
246
247 // Hide new image until it's needed
249}
250
251
256{
257 // Undo effects of the transition
259}
260
261
266{
267 // Both images are same size
268 int width = m_old->GetArea().width();
269
270 // Slide off to left
271 auto *oldPic = new Animation(m_prev, Animation::Position);
272 oldPic->Set(QPoint(0, 0), QPoint(-width, 0), m_duration, QEasingCurve::InOutQuart);
273 m_animation->Add(oldPic);
274
275 // Slide in from right
276 auto *newPic = new Animation(m_next, Animation::Position);
277 newPic->Set(QPoint(width, 0), QPoint(0, 0), m_duration, QEasingCurve::InOutQuart);
278 m_animation->Add(newPic);
279
280 // Hide new image until it's needed
281 m_new->SetPosition(width, 0);
282}
283
284
289{
290 // Undo effects of the transition
291 m_old->SetPosition(0,0);
292}
293
294
299{
300 // Both images are same size
301 int width = m_old->GetArea().width();
302
303 // Zoom away to left
304 auto *oldZoom = new Animation(m_prev, Animation::Zoom);
305 oldZoom->Set(1.0, 0.0, m_duration, QEasingCurve::OutQuad);
306 m_animation->Add(oldZoom);
307
308 auto *oldMove = new Animation(m_prev, Animation::Position);
309 oldMove->Set(QPoint(0, 0), QPoint(-width / 2, 0), m_duration,
310 QEasingCurve::InQuad);
311 m_animation->Add(oldMove);
312
313 // Zoom in from right
314 auto *newZoom = new Animation(m_next, Animation::Zoom);
315 newZoom->Set(0.0, 1.0, m_duration, QEasingCurve::InQuad);
316 m_animation->Add(newZoom);
317
318 auto *newMove = new Animation(m_next, Animation::Position);
319 newMove->Set(QPoint(width / 2, 0), QPoint(0, 0), m_duration,
320 QEasingCurve::OutQuad);
321 m_animation->Add(newMove);
322
323 // Hide new image until it's needed
324 m_new->SetZoom(0.0);
325}
326
327
333{
334 // Undo effects of the transition
335 m_old->SetZoom(1.0);
336 m_old->SetPosition(0, 0);
337}
338
339
344{
345 // Set up blend
347
348 // Add simultaneous spin
349 auto *an = new Animation(m_prev, Animation::Angle);
350 an->Set(0.0, 360.1, m_duration, QEasingCurve::InOutQuad);
351 m_animation->Add(an);
352
354 an->Set(0.0, 360.1, m_duration, QEasingCurve::InOutQuad);
355 m_animation->Add(an);
356
357 // Zoom prev away, then back
358 auto *seq = new SequentialAnimation();
359 m_animation->Add(seq);
360
362 an->Set(1.0, 0.5, m_duration / 2, QEasingCurve::InOutQuad);
363 seq->Add(an);
364
366 an->Set(0.5, 1.0, m_duration / 2, QEasingCurve::InOutQuad);
367 seq->Add(an);
368
369 // Zoom next away, then back
370 seq = new SequentialAnimation();
371 m_animation->Add(seq);
372
374 an->Set(1.0, 0.5, m_duration / 2, QEasingCurve::InOutQuad);
375 seq->Add(an);
376
378 an->Set(0.5, 1.0, m_duration / 2, QEasingCurve::InOutQuad);
379 seq->Add(an);
380}
381
382
388{
389 // Undo blend
391
392 // Undo effects of the transition
393 m_old->SetZoom(1.0);
394 m_old->SetAngle(0.0);
395}
396
397
405void TransitionRandom::Start(Slide &from, Slide &to, bool forwards, float speed)
406{
407 // Select a random peer.
408 int rand = MythRandom(0, m_peers.size() - 1);
409 m_current = m_peers[rand];
410 // Invoke peer
412 m_current->Start(from, to, forwards, speed);
413}
414
415
420{
421 // Clean up
422 disconnect(m_current, nullptr, nullptr, nullptr);
423 m_current = nullptr;
424 emit finished();
425}
426
427
void finished()
Signals animation has finished.
A single animation controlling alpha, zoom, rotation and position.
Definition: galleryslide.h:55
@ HorizontalZoom
Definition: galleryslide.h:58
Abstract class for groups of animations.
Definition: galleryslide.h:91
void Pulse() override=0
void SetSpeed(float speed) override
Definition: galleryslide.h:98
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.
void Start(Slide &from, Slide &to, bool forwards, float speed=1.0) override
Start group transition.
void Pulse() override
Update group transition.
void SetSpeed(float speed) override
Change transition speed.
GroupTransition(GroupAnimation *animation, const QString &name)
Create group transition.
~GroupTransition() override
Destroy group transition.
GroupAnimation * m_animation
virtual void SetVisible(bool visible)
void SetAngle(float angle)
Definition: mythuitype.cpp:979
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
Definition: mythuitype.cpp:885
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:533
void SetAlpha(int newalpha)
Definition: mythuitype.cpp:942
void SetHorizontalZoom(float zoom)
Definition: mythuitype.cpp:967
A group of animations to be played sequentially.
Definition: galleryslide.h:111
A specialised image for slideshows.
Definition: galleryslide.h:157
void SetZoom(float zoom)
Sets slide zoom.
Image blends into the next by fading.
void Finalise() override
Reset Blend transition.
void Initialise() override
Set up Blend transition.
Switches images instantly with no effects.
void Start(Slide &from, Slide &to, bool forwards, float speed=1.0) override
Switch images.
Invokes random transitions.
void Finished() override
Invoked when peer transition completes.
Transition * m_current
Selected transition.
void Start(Slide &from, Slide &to, bool forwards, float speed=1.0) override
Starts a random transition from a set of its peer transitions,.
QList< Transition * > m_peers
Set of distinct transitions.
Transition & Select(int setting)
Returns the requested transition or an alternative if it is not suitable for the painter.
TransitionRegistry(bool includeAnimations)
Constructor.
TransitionNone m_immediate
A transition that updates instantly.
TransitionMap m_map
All possible transitions.
Slide on from right, then off to left.
void Initialise() override
Set up Slide transition.
void Finalise() override
Reset Slide transition.
Images blend whilst rotating.
void Initialise() override
Set up Spin transition.
void Finalise() override
Reset Spin transition.
Image twists into the next.
void Finalise() override
Reset Twist transition.
void Initialise() override
Set up Twist transition.
Zooms from right, then away to left.
void Finalise() override
Reset Zoom transition.
void Initialise() override
Set up Zoom transition.
Base class of an animated transition that can be accelerated & reversed.
virtual void Finished()
Transition has completed.
virtual void Finalise()
virtual void Start(Slide &from, Slide &to, bool forwards, float speed=1.0)
Start base transition.
void finished()
virtual void Initialise()
Transition(const QString &name)
Slide * m_next
The image occurring later in the slideshow sequence.
Slide * m_prev
The image occurring earlier in the slideshow sequence.
std::chrono::milliseconds m_duration
Seconds transition will last.
Slide * m_new
The new image that will replace the current one (whatever the transition direction)
Slide * m_old
The image currently displayed, which will be replaced (whatever the transition direction)
#define LOC
Provides transitions for slideshows.
@ kSpinTransition
@ kNoTransition
@ kSlideTransition
@ kLastTransSentinel
@ kRandomTransition
@ kZoomTransition
@ kTwistTransition
@ kBlendTransition
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
Convenience inline random number generator functions.
uint32_t MythRandom()
generate 32 random bits
Definition: mythrandom.h:20
STL namespace.