• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • plasma
  • deprecated
deprecated/animator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2007 Aaron Seigo <aseigo@kde.org>
3  * 2007 Alexis Ménard <darktears31@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Library General Public License as
7  * published by the Free Software Foundation; either version 2, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "animator.h"
22 #include "private/animator_p.h"
23 
24 #include <QGraphicsItem>
25 #include <QTimeLine>
26 #include <QTimerEvent>
27 
28 #include <kconfig.h>
29 #include <kconfiggroup.h>
30 #include <kdebug.h>
31 #include <kservice.h>
32 #include <kservicetypetrader.h>
33 #include <kglobalsettings.h>
34 
35 #include "animationdriver.h"
36 #include "private/kineticscroll_p.h"
37 
38 namespace Plasma
39 {
40 
41 static const int MIN_TICK_RATE_INT = 10;
42 static const qreal MIN_TICK_RATE = 10;
43 
44 AnimatorPrivate::AnimatorPrivate(Animator *parent)
45  : q(parent),
46  driver(0),
47  animId(0),
48  timerId(0)
49 {
50 }
51 
52 AnimatorPrivate::~AnimatorPrivate()
53 {
54  cleanupStates();
55  qDeleteAll(animatedItems);
56  qDeleteAll(animatedElements);
57  qDeleteAll(movingItems);
58 
59  QMutableHashIterator<int, CustomAnimationState*> it(customAnims);
60  while (it.hasNext()) {
61  it.next();
62  delete[] it.value()->slot;
63  delete it.value();
64  it.remove();
65  }
66 
67  // Animator is a QObject
68  // and we don't own the items
69 }
70 
71 qreal AnimatorPrivate::calculateProgress(int time, int duration, Animator::CurveShape curve)
72 {
73  if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
74  return qreal(1.0);
75  }
76 
77  timeline.setCurveShape(static_cast<QTimeLine::CurveShape>(curve));
78  timeline.setDuration(duration);
79  qreal progress = timeline.valueForTime(time);
80  return progress;
81 }
82 
83 void AnimatorPrivate::performAnimation(qreal amount, const AnimationState *state)
84 {
85  /* TODO: write new animations to replace this.
86  */
87  switch (state->animation) {
88  case Animator::AppearAnimation:
89  driver->itemAppear(amount, state->item);
90  break;
91  case Animator::DisappearAnimation:
92  driver->itemDisappear(amount, state->item);
93  if (amount >= 1) {
94  state->item->hide();
95  }
96  break;
97  case Animator::ActivateAnimation:
98  driver->itemActivated(amount, state->item);
99  break;
100  default:
101  kDebug() << "Unsupported animation type.";
102 
103  }
104 }
105 
106 void AnimatorPrivate::performMovement(qreal amount, const MovementState *state)
107 {
108  switch (state->movement) {
109  case Animator::SlideInMovement:
110  case Animator::FastSlideInMovement:
111  //kDebug() << "performMovement, SlideInMovement";
112  driver->itemSlideIn(amount, state->item, state->start, state->destination);
113  break;
114  case Animator::SlideOutMovement:
115  case Animator::FastSlideOutMovement:
116  //kDebug() << "performMovement, SlideOutMovement";
117  driver->itemSlideOut(amount, state->item, state->start, state->destination);
118  break;
119  }
120 }
121 
122 void AnimatorPrivate::scrollStateChanged(QAbstractAnimation::State newState,
123  QAbstractAnimation::State oldState)
124 {
125  KineticScrolling *scroll = qobject_cast<KineticScrolling*>(q->sender());
126  if (!scroll) {
127  kDebug() << "Could not find KineticScrolling object";
128  return;
129  }
130 
131  emit q->scrollStateChanged(scrollingManagers.key(scroll), newState, oldState);
132 }
133 
134 class AnimatorSingleton
135 {
136  public:
137  Animator self;
138 };
139 
140 K_GLOBAL_STATIC(AnimatorSingleton, privateSelf)
141 
142 Animator *Animator::self()
143 {
144  return &privateSelf->self;
145 }
146 
147 Animator::Animator(QObject *parent)
148  : QObject(parent),
149  d(new AnimatorPrivate(this))
150 {
151  d->init(this);
152 }
153 
154 Animator::~Animator()
155 {
156  delete d;
157 }
158 
159 void AnimatorPrivate::animatedItemDestroyed(QObject *o)
160 {
161  //kDebug() << "testing for" << (void*)o;
162  QMutableHashIterator<QGraphicsItem*, AnimationState*> it(animatedItems);
163  while (it.hasNext()) {
164  it.next();
165  //kDebug() << "comparing against" << it.value()->qobj;
166  if (it.value()->qobj == o) {
167  kDebug() << "found deleted animated item";
168  if (timerId) {
169  animatedItemsToDelete.insert(it.value());
170  } else {
171  delete it.value();
172  }
173 
174  it.remove();
175  }
176  }
177 }
178 
179 void AnimatorPrivate::movingItemDestroyed(QObject *o)
180 {
181  QMutableHashIterator<QGraphicsItem*, MovementState*> it(movingItems);
182  while (it.hasNext()) {
183  it.next();
184  if (it.value()->qobj == o) {
185  if (timerId) {
186  movingItemsToDelete.insert(it.value());
187  } else {
188  delete it.value();
189  }
190 
191  it.remove();
192  }
193  }
194 }
195 
196 void AnimatorPrivate::animatedElementDestroyed(QObject *o)
197 {
198  QMutableHashIterator<int, ElementAnimationState*> it(animatedElements);
199  while (it.hasNext()) {
200  it.next();
201  if (it.value()->qobj == o) {
202  if (timerId) {
203  animatedElementsToDelete.insert(it.value());
204  } else {
205  delete it.value();
206  }
207 
208  it.remove();
209  }
210  }
211 }
212 
213 void AnimatorPrivate::customAnimReceiverDestroyed(QObject *o)
214 {
215  QMutableHashIterator<int, CustomAnimationState*> it(customAnims);
216  while (it.hasNext()) {
217  if (it.next().value()->receiver == o) {
218  if (timerId) {
219  customAnimsToDelete.insert(it.value());
220  } else {
221  delete[] it.value()->slot;
222  delete it.value();
223  }
224 
225  it.remove();
226  }
227  }
228 }
229 
230 int Animator::animateItem(QGraphicsItem *item, Animation animation)
231 {
232  //kDebug();
233  // get rid of any existing animations on this item.
234  QHash<QGraphicsItem*, AnimationState*>::iterator it = d->animatedItems.find(item);
235  if (it != d->animatedItems.end()) {
236  if (d->timerId) {
237  d->animatedItemsToDelete.insert(it.value());
238  } else {
239  delete it.value();
240  }
241 
242  d->animatedItems.erase(it);
243  }
244 
245  int frames = d->driver->animationFps(animation);
246 
247  if (frames < 1) {
248  // evidently this animator doesn't have an implementation
249  // for this Animation
250  return -1;
251  }
252 
253  int duration = d->driver->animationDuration(animation);
254 
255  AnimationState *state = new AnimationState;
256  state->id = ++d->animId;
257  state->item = item;
258  state->animation = animation;
259  state->curve = d->driver->animationCurve(animation);
260  state->frames = qMax(1.0, frames * (duration / 1000.0)); //krazy:exclude=qminmax
261  state->currentFrame = 0;
262  state->interval = d->driver->animationDuration(animation) / qreal(state->frames);
263  state->interval = qMax(MIN_TICK_RATE_INT, state->interval - (state->interval % MIN_TICK_RATE_INT));
264  state->currentInterval = state->interval;
265  state->qobj = dynamic_cast<QObject*>(item);
266 
267  if (state->qobj) {
268  //kDebug() << "!!!!!!!!!!!!!!!!!!!!!!!!! got us an object!";
269  disconnect(state->qobj, SIGNAL(destroyed(QObject*)),
270  this, SLOT(animatedItemDestroyed(QObject*)));
271  connect(state->qobj, SIGNAL(destroyed(QObject*)),
272  this, SLOT(animatedItemDestroyed(QObject*)));
273  }
274 
275  d->animatedItems[item] = state;
276  d->performAnimation(0, state);
277 
278  if (!d->timerId) {
279  d->timerId = startTimer(MIN_TICK_RATE);
280  d->time.restart();
281  }
282 
283  return state->id;
284 }
285 
286 int Animator::moveItem(QGraphicsItem *item, Movement movement, const QPoint &destination)
287 {
288  //kDebug();
289  QHash<QGraphicsItem*, MovementState*>::iterator it = d->movingItems.find(item);
290  if (it != d->movingItems.end()) {
291  if (d->timerId) {
292  d->movingItemsToDelete.insert(it.value());
293  } else {
294  delete it.value();
295  }
296 
297  d->movingItems.erase(it);
298  }
299 
300  int frames = d->driver->movementAnimationFps(movement);
301  if (frames <= 1) {
302  // evidently this animator doesn't have an implementation
303  // for this Animation
304  return -1;
305  }
306 
307  MovementState *state = new MovementState;
308  state->id = ++d->animId;
309  state->destination = destination;
310  state->start = item->pos().toPoint();
311  state->item = item;
312  state->movement = movement;
313  state->curve = d->driver->movementAnimationCurve(movement);
314  int duration = d->driver->movementAnimationDuration(movement);
315  state->frames = qMax(1.0, frames * (duration / 1000.0)); //krazy:exclude=qminmax
316  state->currentFrame = 0;
317  state->interval = duration / qreal(state->frames);
318  state->interval = qMax(MIN_TICK_RATE_INT, state->interval - (state->interval % MIN_TICK_RATE_INT));
319 // state->interval = (state->interval / MIN_TICK_RATE) * MIN_TICK_RATE;
320 // kDebug() << "interval of" << state->interval << state->frames << duration << frames;
321  state->currentInterval = state->interval;
322  state->qobj = dynamic_cast<QObject*>(item);
323 
324  if (state->qobj) {
325  disconnect(state->qobj, SIGNAL(destroyed(QObject*)), this, SLOT(movingItemDestroyed(QObject*)));
326  connect(state->qobj, SIGNAL(destroyed(QObject*)), this, SLOT(movingItemDestroyed(QObject*)));
327  }
328 
329  d->movingItems[item] = state;
330  d->performMovement(0, state);
331 
332  if (!d->timerId) {
333  d->timerId = startTimer(MIN_TICK_RATE);
334  d->time.restart();
335  }
336 
337  return state->id;
338 }
339 
340 int Animator::customAnimation(int frames, int duration, Animator::CurveShape curve,
341  QObject *receiver, const char *slot)
342 {
343  if (frames < 1 || duration < 1 || !receiver || !slot) {
344  return -1;
345  }
346 
347  CustomAnimationState *state = new CustomAnimationState;
348  state->id = ++d->animId;
349  state->frames = frames;
350  state->currentFrame = 0;
351  state->curve = curve;
352  state->frameInterval = qMax(qreal(1.0), duration / qreal(state->frames));
353  state->interval = qMax(MIN_TICK_RATE_INT, state->frameInterval - (state->frameInterval % MIN_TICK_RATE_INT));
354  state->currentInterval = state->interval;
355  state->receiver = receiver;
356  state->slot = qstrdup(slot);
357 
358  d->customAnims[state->id] = state;
359 
360  disconnect(receiver, SIGNAL(destroyed(QObject*)),
361  this, SLOT(customAnimReceiverDestroyed(QObject*)));
362  connect(receiver, SIGNAL(destroyed(QObject*)),
363  this, SLOT(customAnimReceiverDestroyed(QObject*)));
364 
365  // try with only progress as argument
366  if (!QMetaObject::invokeMethod(receiver, slot, Q_ARG(qreal, 0))) {
367  //try to pass also the animation id
368  QMetaObject::invokeMethod(receiver, slot, Q_ARG(qreal, 0), Q_ARG(int, state->id));
369  }
370 
371  if (!d->timerId) {
372  d->timerId = startTimer(MIN_TICK_RATE);
373  d->time.restart();
374  }
375 
376  return state->id;
377 }
378 
379 void Animator::stopCustomAnimation(int id)
380 {
381  QHash<int, CustomAnimationState*>::iterator it = d->customAnims.find(id);
382  if (it != d->customAnims.end()) {
383  if (d->timerId) {
384  d->customAnimsToDelete.insert(it.value());
385  } else {
386  delete[] it.value()->slot;
387  delete it.value();
388  }
389 
390  d->customAnims.erase(it);
391  }
392  //kDebug() << "stopCustomAnimation(AnimId " << id << ") done";
393 }
394 
395 void Animator::stopItemAnimation(int id)
396 {
397  QMutableHashIterator<QGraphicsItem*, AnimationState*> it(d->animatedItems);
398  while (it.hasNext()) {
399  it.next();
400  if (it.value()->id == id) {
401  if (d->timerId) {
402  d->animatedItemsToDelete.insert(it.value());
403  } else {
404  delete it.value();
405  }
406 
407  it.remove();
408  return;
409  }
410  }
411 }
412 
413 void Animator::stopItemMovement(int id)
414 {
415  QMutableHashIterator<QGraphicsItem*, MovementState*> it(d->movingItems);
416  while (it.hasNext()) {
417  it.next();
418  if (it.value()->id == id) {
419  if (d->timerId) {
420  d->movingItemsToDelete.insert(it.value());
421  } else {
422  delete it.value();
423  }
424 
425  it.remove();
426  return;
427  }
428  }
429 }
430 
431 int Animator::animateElement(QGraphicsItem *item, Animation animation)
432 {
433  //kDebug() << "startElementAnimation(AnimId " << animation << ")";
434  int frames = d->driver->elementAnimationFps(animation);
435  int duration = d->driver->animationDuration(animation);
436 
437  ElementAnimationState *state = new ElementAnimationState;
438  state->item = item;
439  state->curve = d->driver->elementAnimationCurve(animation);
440  state->animation = animation;
441  state->frames = qMax(1.0, frames * (duration / 1000.0)); //krazy:exclude=qminmax
442  state->currentFrame = 0;
443  state->interval = duration / qreal(state->frames);
444  state->interval = qMax(MIN_TICK_RATE_INT, state->interval - (state->interval % MIN_TICK_RATE_INT));
445  state->currentInterval = state->interval;
446  state->id = ++d->animId;
447  state->qobj = dynamic_cast<QObject*>(item);
448 
449  if (state->qobj) {
450  disconnect(state->qobj, SIGNAL(destroyed(QObject*)),
451  this, SLOT(animatedElementDestroyed(QObject*)));
452  connect(state->qobj, SIGNAL(destroyed(QObject*)),
453  this, SLOT(animatedElementDestroyed(QObject*)));
454  }
455 
456  //kDebug() << "animateElement " << animation << ", interval: "
457  // << state->interval << ", frames: " << state->frames;
458  bool needTimer = true;
459  if (state->frames < 1) {
460  state->frames = 1;
461  state->currentFrame = 1;
462  needTimer = false;
463  }
464 
465  d->animatedElements[state->id] = state;
466 
467  //kDebug() << "startElementAnimation(AnimId " << animation << ") returning " << state->id;
468  if (needTimer && !d->timerId) {
469  // start a 20fps timer;
470  d->timerId = startTimer(MIN_TICK_RATE);
471  d->time.restart();
472  }
473  return state->id;
474 }
475 
476 void Animator::stopElementAnimation(int id)
477 {
478  QHash<int, ElementAnimationState*>::iterator it = d->animatedElements.find(id);
479  if (it != d->animatedElements.end()) {
480  if (d->timerId) {
481  d->animatedElementsToDelete.insert(it.value());
482  } else {
483  delete it.value();
484  }
485 
486  d->animatedElements.erase(it);
487  }
488  //kDebug() << "stopElementAnimation(AnimId " << id << ") done";
489 }
490 
491 void Animator::setInitialPixmap(int id, const QPixmap &pixmap)
492 {
493  QHash<int, ElementAnimationState*>::iterator it = d->animatedElements.find(id);
494 
495  if (it == d->animatedElements.end()) {
496  kDebug() << "No entry found for id " << id;
497  return;
498  }
499 
500  it.value()->pixmap = pixmap;
501 }
502 
503 QPixmap Animator::currentPixmap(int id)
504 {
505  QHash<int, ElementAnimationState*>::const_iterator it = d->animatedElements.constFind(id);
506 
507  if (it == d->animatedElements.constEnd()) {
508  //kDebug() << "Animator::currentPixmap(" << id << ") found no entry for it!";
509  return QPixmap();
510  }
511 
512  ElementAnimationState *state = it.value();
513  qreal progress = d->calculateProgress(state->currentFrame * state->interval,
514  state->frames * state->interval,
515  state->curve);
516  //kDebug() << "Animator::currentPixmap(" << id << " at " << progress;
517 
518  switch (state->animation) {
519  case AppearAnimation:
520  return d->driver->elementAppear(progress, state->pixmap);
521  break;
522  case DisappearAnimation:
523  return d->driver->elementDisappear(progress, state->pixmap);
524  break;
525  case ActivateAnimation:
526  break;
527  default:
528  kDebug() << "Unsupported animation type.";
529 
530  }
531 
532  return state->pixmap;
533 }
534 
535 bool Animator::isAnimating() const
536 {
537  return (!d->animatedItems.isEmpty() ||
538  !d->movingItems.isEmpty() ||
539  !d->animatedElements.isEmpty() ||
540  !d->customAnims.isEmpty());
541 }
542 
543 void Animator::timerEvent(QTimerEvent *event)
544 {
545  if (event->timerId() != d->timerId) {
546  QObject::timerEvent(event);
547  return;
548  }
549 
550  Q_UNUSED(event)
551  bool animationsRemain = false;
552  int elapsed = MIN_TICK_RATE;
553  if (d->time.elapsed() > elapsed) {
554  elapsed = d->time.elapsed();
555  }
556  d->time.restart();
557  //kDebug() << "timeEvent, elapsed time: " << elapsed;
558 
559  foreach (AnimationState *state, d->animatedItems) {
560  if (d->animatedItemsToDelete.contains(state)) {
561  continue;
562  }
563 
564  if (state->currentInterval <= elapsed) {
565  // we need to step forward!
566  state->currentFrame +=
567  (KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects) ?
568  qMax(1, elapsed / state->interval) : state->frames - state->currentFrame;
569 
570  if (state->currentFrame < state->frames) {
571  qreal progress = d->calculateProgress(state->currentFrame * state->interval,
572  state->frames * state->interval,
573  state->curve);
574  d->performAnimation(progress, state);
575  state->currentInterval = state->interval;
576  animationsRemain = true;
577  } else {
578  d->performAnimation(1, state);
579  d->animatedItems.erase(d->animatedItems.find(state->item));
580  emit animationFinished(state->item, state->animation);
581  d->animatedItemsToDelete.insert(state);
582  }
583  } else {
584  state->currentInterval -= elapsed;
585  animationsRemain = true;
586  }
587  }
588 
589  foreach (MovementState *state, d->movingItems) {
590  if (d->movingItemsToDelete.contains(state)) {
591  continue;
592  }
593 
594  if (state->currentInterval <= elapsed) {
595  // we need to step forward!
596  state->currentFrame +=
597  (KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects) ?
598  qMax(1, elapsed / state->interval) : state->frames - state->currentFrame;
599 
600  if (state->currentFrame < state->frames) {
601  //kDebug() << "movement";
602  qreal progress = d->calculateProgress(state->currentFrame * state->interval,
603  state->frames * state->interval,
604  state->curve);
605  d->performMovement(progress, state);
606  animationsRemain = true;
607  } else {
608  //kDebug() << "movement";
609  d->performMovement(1, state);
610  d->movingItems.erase(d->movingItems.find(state->item));
611  emit movementFinished(state->item);
612  d->movingItemsToDelete.insert(state);
613  }
614  } else {
615  state->currentInterval -= elapsed;
616  animationsRemain = true;
617  }
618  }
619 
620  foreach (ElementAnimationState *state, d->animatedElements) {
621  if (d->animatedElementsToDelete.contains(state)) {
622  continue;
623  }
624 
625  if (state->currentFrame == state->frames) {
626  //kDebug() << "skipping" << state->id << "as it is already at frame"
627  // << state->currentFrame << "of" << state->frames;
628  // since we keep element animations around until they are
629  // removed, we will end up with finished animations in the queue;
630  // just skip them
631  continue;
632  }
633 
634  if (state->currentInterval <= elapsed) {
635  // we need to step forward!
636  /*kDebug() << "stepping forwards element anim " << state->id
637  << " from " << state->currentFrame
638  << " by " << qMax(1, elapsed / state->interval) << " to "
639  << state->currentFrame + qMax(1, elapsed / state->interval) << endl;*/
640  state->currentFrame +=
641  (KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects) ?
642  qMax(1, elapsed / state->interval) : state->frames - state->currentFrame;
643 
644  state->item->update();
645  if (state->currentFrame < state->frames) {
646  state->currentInterval = state->interval;
647  animationsRemain = true;
648  } else {
649  d->animatedElements.remove(state->id);
650  emit elementAnimationFinished(state->id);
651  d->animatedElementsToDelete.insert(state);
652  }
653  } else {
654  state->currentInterval -= elapsed;
655  animationsRemain = true;
656  }
657  }
658 
659  foreach (CustomAnimationState *state, d->customAnims) {
660  if (d->customAnimsToDelete.contains(state)) {
661  continue;
662  }
663 
664  if (state->currentInterval <= elapsed) {
665  // advance the frame
666  state->currentFrame +=
667  (KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects) ?
668  qMax(1, elapsed / state->frameInterval) : state->frames - state->currentFrame;
669  /*kDebug() << "custom anim for" << state->receiver
670  << "to slot" << state->slot
671  << "with interval of" << state->interval
672  << "at frame" << state->currentFrame;*/
673 
674  if (state->currentFrame < state->frames) {
675  //kDebug () << "not the final frame";
676  state->currentInterval = state->interval;
677  animationsRemain = true;
678  // signal the object
679  // try with only progress as argument
680  qreal progress = d->calculateProgress(state->currentFrame * state->interval,
681  state->frames * state->interval,
682  state->curve);
683  if (!QMetaObject::invokeMethod(state->receiver, state->slot, Q_ARG(qreal, progress))) {
684  //if fails try to add the animation id
685  QMetaObject::invokeMethod(state->receiver, state->slot, Q_ARG(qreal, progress),
686  Q_ARG(int, state->id));
687  }
688  } else {
689  if (!QMetaObject::invokeMethod(state->receiver, state->slot, Q_ARG(qreal, 1))) {
690  QMetaObject::invokeMethod(state->receiver, state->slot, Q_ARG(qreal, 1), Q_ARG(int, state->id));
691  }
692  d->customAnims.erase(d->customAnims.find(state->id));
693  emit customAnimationFinished(state->id);
694  d->customAnimsToDelete.insert(state);
695  }
696  } else {
697  state->currentInterval -= elapsed;
698  animationsRemain = true;
699  }
700  }
701 
702  if (!animationsRemain && d->timerId) {
703  killTimer(d->timerId);
704  d->timerId = 0;
705  }
706 
707  d->cleanupStates();
708 }
709 
710 void AnimatorPrivate::init(Animator *q)
711 {
712  //FIXME: usage between different applications?
713  KConfig c("plasmarc");
714  KConfigGroup cg(&c, "Animator");
715  QString pluginName = cg.readEntry("driver", "default");
716 
717  if (!pluginName.isEmpty()) {
718  QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(pluginName);
719  KService::List offers = KServiceTypeTrader::self()->query("Plasma/Animator", constraint);
720 
721  if (!offers.isEmpty()) {
722  QString error;
723 
724  KPluginLoader plugin(*offers.first());
725 
726  if (Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
727  driver = offers.first()->createInstance<Plasma::AnimationDriver>(q, QVariantList(), &error);
728  }
729 
730  if (!driver) {
731  kDebug() << "Could not load requested animator "
732  << offers.first() << ". Error given: " << error;
733  }
734  }
735  }
736 
737  if (!driver) {
738  driver = new AnimationDriver(q);
739  }
740 }
741 
742 void AnimatorPrivate::cleanupStates()
743 {
744  /*
745  kDebug() << animatedItemsToDelete.count() << animatedElementsToDelete.count()
746  << movingItemsToDelete.count() << customAnimsToDelete.count();
747  */
748  qDeleteAll(animatedItemsToDelete);
749  animatedItemsToDelete.clear();
750  qDeleteAll(animatedElementsToDelete);
751  animatedElementsToDelete.clear();
752  qDeleteAll(movingItemsToDelete);
753  movingItemsToDelete.clear();
754 
755  QSetIterator<CustomAnimationState*> it(customAnimsToDelete);
756  while (it.hasNext()) {
757  CustomAnimationState *state = it.next();
758  delete[] state->slot;
759  delete state;
760  }
761  customAnimsToDelete.clear();
762 }
763 
764 void Animator::registerScrollingManager(QGraphicsWidget *widget)
765 {
766  if (!d->scrollingManagers.contains(widget)) {
767  KineticScrolling *scroll = new KineticScrolling(widget);
768  d->scrollingManagers.insert(widget, scroll);
769  connect(scroll,
770  SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this,
771  SLOT(scrollStateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
772  }
773 }
774 
775 void Animator::unregisterScrollingManager(QGraphicsWidget *widget)
776 {
777  if (d->scrollingManagers.contains(widget)) {
778  disconnect(d->scrollingManagers.value(widget),
779  SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this,
780  SLOT(scrollStateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
781  d->scrollingManagers.value(widget)->deleteLater();
782  d->scrollingManagers.remove(widget);
783  }
784 }
785 
786 
787 } // namespace Plasma
788 
Plasma::Animator
A system for applying effects to Plasma elements.
Definition: animator.h:46
Plasma::Animator::self
static Animator * self()
Singleton accessor.
Definition: deprecated/animator.cpp:142
Plasma::Animator::Animation
Animation
Definition: animator.h:55
Plasma::Animator::stopItemAnimation
Q_INVOKABLE void stopItemAnimation(int id)
Stops an item animation before the animation is complete.
Definition: deprecated/animator.cpp:395
Plasma::Animator::customAnimation
Q_INVOKABLE int customAnimation(int frames, int duration, Animator::CurveShape curve, QObject *receiver, const char *method)
Starts a custom animation, preventing the need to create a timeline with its own timer tick...
Definition: deprecated/animator.cpp:340
Plasma::Animator::customAnimationFinished
void customAnimationFinished(int id)
Plasma::Animator::animationFinished
void animationFinished(QGraphicsItem *item, Plasma::Animator::Animation anim)
QObject
Plasma::Animator::isAnimating
Q_INVOKABLE bool isAnimating() const
Can be used to query if there are other animations happening.
Definition: deprecated/animator.cpp:535
Plasma::Animator::stopElementAnimation
Q_INVOKABLE void stopElementAnimation(int id)
Definition: deprecated/animator.cpp:476
Plasma::Animator::movementFinished
void movementFinished(QGraphicsItem *item)
Plasma::AnimationScriptEngine::animation
QScriptValue animation(const QString &anim)
Definition: animationscriptengine.cpp:55
Plasma::isPluginVersionCompatible
bool isPluginVersionCompatible(unsigned int version)
Verifies that a plugin is compatible with plasma.
Definition: version.cpp:51
Plasma::Animator::animateElement
Q_INVOKABLE int animateElement(QGraphicsItem *obj, Animation)
Definition: deprecated/animator.cpp:431
Plasma::Animator::timerEvent
void timerEvent(QTimerEvent *event)
Definition: deprecated/animator.cpp:543
Plasma::Animator::DisappearAnimation
Definition: animator.h:57
Plasma::MIN_TICK_RATE_INT
static const int MIN_TICK_RATE_INT
Definition: deprecated/animator.cpp:41
Plasma::Animator::Movement
Movement
Definition: animator.h:81
Plasma::Animator::animateItem
Q_INVOKABLE int animateItem(QGraphicsItem *item, Animation anim)
Starts a standard animation on a QGraphicsItem.
Definition: deprecated/animator.cpp:230
Plasma::MIN_TICK_RATE
static const qreal MIN_TICK_RATE
Definition: deprecated/animator.cpp:42
Plasma::Animator::moveItem
Q_INVOKABLE int moveItem(QGraphicsItem *item, Movement movement, const QPoint &destination)
Starts a standard animation on a QGraphicsItem.
Definition: deprecated/animator.cpp:286
Plasma::AnimationDriver
Definition: animationdriver.h:40
Plasma::Animator::currentPixmap
Q_INVOKABLE QPixmap currentPixmap(int id)
Definition: deprecated/animator.cpp:503
Plasma::Animator::scrollStateChanged
void scrollStateChanged(QGraphicsWidget *widget, QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
animationdriver.h
Plasma::Animator::stopCustomAnimation
Q_INVOKABLE void stopCustomAnimation(int id)
Stops a custom animation.
Definition: deprecated/animator.cpp:379
Plasma::Animator::ActivateAnimation
Definition: animator.h:58
Plasma::Animator::CurveShape
CurveShape
Definition: animator.h:73
Plasma::Animator::stopItemMovement
Q_INVOKABLE void stopItemMovement(int id)
Stops an item movement before the animation is complete.
Definition: deprecated/animator.cpp:413
Plasma::Animator::unregisterScrollingManager
void unregisterScrollingManager(QGraphicsWidget *widget)
unregister the scrolling manager of a certain widget This function is deprecated: use ScrollWidget in...
Definition: deprecated/animator.cpp:775
animator.h
Plasma::Animator::registerScrollingManager
void registerScrollingManager(QGraphicsWidget *widget)
Register a widget as a scrolling widget.
Definition: deprecated/animator.cpp:764
Plasma::Animator::AppearAnimation
Definition: animator.h:56
Plasma::Animator::elementAnimationFinished
void elementAnimationFinished(int id)
Plasma::Animator::setInitialPixmap
Q_INVOKABLE void setInitialPixmap(int id, const QPixmap &pixmap)
Definition: deprecated/animator.cpp:491
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal