Animators
defaultAnimator.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "defaultAnimator.h"
00021
00022 #include <QGraphicsItem>
00023 #include <QPainter>
00024
00025 #include <KDebug>
00026
00027 DefaultAnimator::DefaultAnimator(QObject *parent, const QVariantList& list)
00028 : Plasma::AnimationDriver(parent)
00029 {
00030 Q_UNUSED(list)
00031 }
00032
00033 int DefaultAnimator::animationFps(Plasma::Animator::Animation animation) const
00034 {
00035 switch (animation) {
00036 case Plasma::Animator::AppearAnimation:
00037 return 20;
00038 case Plasma::Animator::DisappearAnimation:
00039 return 20;
00040
00041 default:
00042 return 0;
00043 }
00044 }
00045
00046 int DefaultAnimator::elementAnimationFps(Plasma::Animator::Animation animation) const
00047 {
00048 switch (animation) {
00049 case Plasma::Animator::AppearAnimation:
00050 return 20;
00051 case Plasma::Animator::DisappearAnimation:
00052 return 20;
00053
00054 default:
00055 return 0;
00056 }
00057 }
00058
00059 void DefaultAnimator::itemAppear(qreal progress, QGraphicsItem* item)
00060 {
00061
00062 if (progress >= 1) {
00063 item->resetTransform();
00064 return;
00065 }
00066 item->resetTransform();
00067 item->scale(progress, progress);
00068 QRectF r = item->boundingRect();
00069 item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
00070 }
00071
00072 void DefaultAnimator::itemDisappear(qreal progress, QGraphicsItem* item)
00073 {
00074 if (progress >= 1) {
00075
00076 return;
00077 }
00078 item->resetTransform();
00079 item->scale(1-progress,1-progress);
00080 QRectF r = item->boundingRect();
00081 item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
00082 }
00083
00084 QPixmap DefaultAnimator::elementAppear(qreal progress, const QPixmap& pixmap)
00085 {
00086
00087 QPixmap pix = pixmap;
00088
00089 if (progress < 1) {
00090 QColor alpha;
00091 alpha.setAlphaF(progress);
00092
00093 QPainter painter(&pix);
00094 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
00095 painter.fillRect(pix.rect(), alpha);
00096 }
00097
00098 return pix;
00099 }
00100
00101 QPixmap DefaultAnimator::elementDisappear(qreal progress, const QPixmap& pixmap)
00102 {
00103
00104 QPixmap pix = pixmap;
00105
00106 if (progress > 0) {
00107 QColor alpha;
00108 alpha.setAlphaF(1 - progress);
00109
00110 QPainter painter(&pix);
00111 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
00112 painter.fillRect(pix.rect(), alpha);
00113 }
00114
00115 return pix;
00116 }
00117
00118 #include "defaultAnimator.moc"