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

« back to all changes in this revision

Viewing changes to kwin/effects/scalein/scalein.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
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
#include "scalein.h"
 
22
#include <QtCore/QTimeLine>
 
23
 
 
24
namespace KWin
 
25
{
 
26
 
 
27
KWIN_EFFECT(scalein, ScaleInEffect)
 
28
 
 
29
ScaleInEffect::ScaleInEffect()
 
30
    : Effect()
 
31
{
 
32
    connect(effects, SIGNAL(windowAdded(EffectWindow*)), this, SLOT(slotWindowAdded(EffectWindow*)));
 
33
    connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*)));
 
34
}
 
35
 
 
36
void ScaleInEffect::prePaintScreen(ScreenPrePaintData& data, int time)
 
37
{
 
38
    if (!mTimeLineWindows.isEmpty())
 
39
        data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
 
40
    effects->prePaintScreen(data, time);
 
41
}
 
42
 
 
43
void ScaleInEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
 
44
{
 
45
    if (mTimeLineWindows.contains(w)) {
 
46
        mTimeLineWindows[ w ]->setCurveShape(QTimeLine::EaseInOutCurve);
 
47
        mTimeLineWindows[ w ]->setCurrentTime(mTimeLineWindows[ w ]->currentTime() + time);
 
48
        if (mTimeLineWindows[ w ]->currentValue() < 1)
 
49
            data.setTransformed();
 
50
        else
 
51
            delete mTimeLineWindows.take(w);
 
52
    }
 
53
    effects->prePaintWindow(w, data, time);
 
54
}
 
55
 
 
56
void ScaleInEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
 
57
{
 
58
    if (mTimeLineWindows.contains(w) && isScaleWindow(w)) {
 
59
        const qreal value = mTimeLineWindows[ w ]->currentValue();
 
60
        data.opacity *= value;
 
61
        data.xScale *= value;
 
62
        data.yScale *= value;
 
63
        data.xTranslate += int(w->width() / 2 * (1 - value));
 
64
        data.yTranslate += int(w->height() / 2 * (1 - value));
 
65
    }
 
66
    effects->paintWindow(w, mask, region, data);
 
67
}
 
68
 
 
69
bool ScaleInEffect::isScaleWindow(EffectWindow* w)
 
70
{
 
71
    const void* e = w->data(WindowAddedGrabRole).value<void*>();
 
72
    // TODO: isSpecialWindow is rather generic, maybe tell windowtypes separately?
 
73
    if (w->isPopupMenu() || w->isSpecialWindow() || w->isUtility() || (e && e != this))
 
74
        return false;
 
75
    return true;
 
76
}
 
77
 
 
78
void ScaleInEffect::postPaintWindow(EffectWindow* w)
 
79
{
 
80
    if (mTimeLineWindows.contains(w))
 
81
        w->addRepaintFull(); // trigger next animation repaint
 
82
    effects->postPaintWindow(w);
 
83
}
 
84
 
 
85
void ScaleInEffect::slotWindowAdded(EffectWindow* c)
 
86
{
 
87
    if (c->isOnCurrentDesktop()) {
 
88
        mTimeLineWindows.insert(c, new QTimeLine(animationTime(250), this));
 
89
        c->addRepaintFull();
 
90
    }
 
91
}
 
92
 
 
93
void ScaleInEffect::slotWindowClosed(EffectWindow* c)
 
94
{
 
95
    delete mTimeLineWindows.take(c);
 
96
}
 
97
 
 
98
} // namespace