~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/animators/default/defaultAnimator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2007 Aaron Seigo <aseigo@kde.org>
 
3
 *
 
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.
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "defaultAnimator.h"
 
21
 
 
22
#include <QGraphicsItem>
 
23
#include <QPainter>
 
24
 
 
25
#include <KDebug>
 
26
 
 
27
DefaultAnimator::DefaultAnimator(QObject *parent, const QVariantList& list)
 
28
    : Plasma::AnimationDriver(parent)
 
29
{
 
30
    Q_UNUSED(list)
 
31
}
 
32
 
 
33
int DefaultAnimator::animationFps(Plasma::Animator::Animation animation) const
 
34
{
 
35
    switch (animation) {
 
36
        case Plasma::Animator::AppearAnimation:
 
37
            return 20;
 
38
        case Plasma::Animator::DisappearAnimation:
 
39
            return 20;
 
40
 
 
41
        default:
 
42
            return 0;
 
43
    }
 
44
}
 
45
 
 
46
int DefaultAnimator::elementAnimationFps(Plasma::Animator::Animation animation) const
 
47
{
 
48
    switch (animation) {
 
49
        case Plasma::Animator::AppearAnimation:
 
50
            return 20;
 
51
        case Plasma::Animator::DisappearAnimation:
 
52
            return 20;
 
53
 
 
54
        default:
 
55
            return 0;
 
56
    }
 
57
}
 
58
 
 
59
void DefaultAnimator::itemAppear(qreal progress, QGraphicsItem* item)
 
60
{
 
61
    //kDebug() << "DefaultAnimator::appear(" << progress << ", " << item << ")";
 
62
    if (progress >= 1) {
 
63
        item->resetTransform();
 
64
        return;
 
65
    }
 
66
    item->resetTransform();
 
67
    QRectF r = item->boundingRect();
 
68
    item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
 
69
    item->scale(progress, progress);
 
70
}
 
71
 
 
72
void DefaultAnimator::itemDisappear(qreal progress, QGraphicsItem* item)
 
73
{
 
74
    if (progress >= 1) {
 
75
        //item->resetTransform();
 
76
        return;
 
77
    }
 
78
    item->resetTransform();
 
79
    QRectF r = item->boundingRect();
 
80
    item->translate(r.width() / 2 * progress, r.height() / 2 * progress);
 
81
    item->scale(1-progress,1-progress);
 
82
}
 
83
 
 
84
QPixmap DefaultAnimator::elementAppear(qreal progress, const QPixmap& pixmap)
 
85
{
 
86
    //kDebug() << progress;
 
87
    QPixmap pix = pixmap;
 
88
 
 
89
    if (progress < 1) {
 
90
        QColor alpha;
 
91
        alpha.setAlphaF(progress);
 
92
 
 
93
        QPainter painter(&pix);
 
94
        painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
 
95
        painter.fillRect(pix.rect(), alpha);
 
96
    }
 
97
 
 
98
    return pix;
 
99
}
 
100
 
 
101
QPixmap DefaultAnimator::elementDisappear(qreal progress, const QPixmap& pixmap)
 
102
{
 
103
    //kDebug() << progress;
 
104
    QPixmap pix = pixmap;
 
105
 
 
106
    if (progress > 0) {
 
107
        QColor alpha;
 
108
        alpha.setAlphaF(1 - progress);
 
109
 
 
110
        QPainter painter(&pix);
 
111
        painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
 
112
        painter.fillRect(pix.rect(), alpha);
 
113
    }
 
114
 
 
115
    return pix;
 
116
}
 
117
 
 
118
#include "defaultAnimator.moc"