add more spacing
[personal-kdebase.git] / workspace / plasma / animators / default / defaultAnimator.cpp
blob8731a8e9ecc9c87eb8804a0f4a38d956de71b823
1 /*
2 * Copyright 2007 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2 or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "defaultAnimator.h"
22 #include <QGraphicsItem>
23 #include <QPainter>
25 #include <KDebug>
27 DefaultAnimator::DefaultAnimator(QObject *parent, const QVariantList& list)
28 : Plasma::AnimationDriver(parent)
30 Q_UNUSED(list)
33 int DefaultAnimator::animationFps(Plasma::Animator::Animation animation) const
35 switch (animation) {
36 case Plasma::Animator::AppearAnimation:
37 return 20;
38 case Plasma::Animator::DisappearAnimation:
39 return 20;
41 default:
42 return 0;
46 int DefaultAnimator::elementAnimationFps(Plasma::Animator::Animation animation) const
48 switch (animation) {
49 case Plasma::Animator::AppearAnimation:
50 return 20;
51 case Plasma::Animator::DisappearAnimation:
52 return 20;
54 default:
55 return 0;
59 void DefaultAnimator::itemAppear(qreal progress, QGraphicsItem* item)
61 //kDebug() << "DefaultAnimator::appear(" << progress << ", " << item << ")";
62 if (progress >= 1) {
63 item->resetTransform();
64 return;
66 item->resetTransform();
67 item->scale(progress, progress);
68 QRectF r = item->boundingRect();
69 item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
72 void DefaultAnimator::itemDisappear(qreal progress, QGraphicsItem* item)
74 if (progress >= 1) {
75 //item->resetTransform();
76 return;
78 item->resetTransform();
79 item->scale(1-progress,1-progress);
80 QRectF r = item->boundingRect();
81 item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
84 QPixmap DefaultAnimator::elementAppear(qreal progress, const QPixmap& pixmap)
86 //kDebug() << progress;
87 QPixmap pix = pixmap;
89 if (progress < 1) {
90 QColor alpha;
91 alpha.setAlphaF(progress);
93 QPainter painter(&pix);
94 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
95 painter.fillRect(pix.rect(), alpha);
98 return pix;
101 QPixmap DefaultAnimator::elementDisappear(qreal progress, const QPixmap& pixmap)
103 //kDebug() << progress;
104 QPixmap pix = pixmap;
106 if (progress > 0) {
107 QColor alpha;
108 alpha.setAlphaF(1 - progress);
110 QPainter painter(&pix);
111 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
112 painter.fillRect(pix.rect(), alpha);
115 return pix;
118 #include "defaultAnimator.moc"