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

« back to all changes in this revision

Viewing changes to kwin/effects/minimizeanimation/minimizeanimation.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) 2007 Rivo Laks <rivolaks@hot.ee>
 
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 "minimizeanimation.h"
 
22
#include <QtCore/QTimeLine>
 
23
 
 
24
namespace KWin
 
25
{
 
26
 
 
27
KWIN_EFFECT(minimizeanimation, MinimizeAnimationEffect)
 
28
 
 
29
MinimizeAnimationEffect::MinimizeAnimationEffect()
 
30
{
 
31
    mActiveAnimations = 0;
 
32
    connect(effects, SIGNAL(windowDeleted(EffectWindow*)), this, SLOT(slotWindowDeleted(EffectWindow*)));
 
33
    connect(effects, SIGNAL(windowMinimized(EffectWindow*)), this, SLOT(slotWindowMinimized(EffectWindow*)));
 
34
    connect(effects, SIGNAL(windowUnminimized(EffectWindow*)), this, SLOT(slotWindowUnminimized(EffectWindow*)));
 
35
}
 
36
 
 
37
 
 
38
void MinimizeAnimationEffect::prePaintScreen(ScreenPrePaintData& data, int time)
 
39
{
 
40
 
 
41
    QHash< EffectWindow*, QTimeLine* >::iterator entry = mTimeLineWindows.begin();
 
42
    bool erase = false;
 
43
    while (entry != mTimeLineWindows.end()) {
 
44
        QTimeLine *timeline = entry.value();
 
45
        if (entry.key()->isMinimized()) {
 
46
            timeline->setCurrentTime(timeline->currentTime() + time);
 
47
            erase = (timeline->currentValue() >= 1.0f);
 
48
        } else {
 
49
            timeline->setCurrentTime(timeline->currentTime() - time);
 
50
            erase = (timeline->currentValue() <= 0.0f);
 
51
        }
 
52
        if (erase) {
 
53
            delete timeline;
 
54
            entry = mTimeLineWindows.erase(entry);
 
55
        } else
 
56
            ++entry;
 
57
    }
 
58
 
 
59
    mActiveAnimations = mTimeLineWindows.count();
 
60
    if (mActiveAnimations > 0)
 
61
        // We need to mark the screen windows as transformed. Otherwise the
 
62
        //  whole screen won't be repainted, resulting in artefacts
 
63
        data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
 
64
 
 
65
    effects->prePaintScreen(data, time);
 
66
}
 
67
 
 
68
void MinimizeAnimationEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
 
69
{
 
70
    // Schedule window for transformation if the animation is still in
 
71
    //  progress
 
72
    if (mTimeLineWindows.contains(w)) {
 
73
        // We'll transform this window
 
74
        data.setTransformed();
 
75
        w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE);
 
76
    }
 
77
 
 
78
    effects->prePaintWindow(w, data, time);
 
79
}
 
80
 
 
81
void MinimizeAnimationEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
 
82
{
 
83
    QHash< EffectWindow*, QTimeLine* >::const_iterator entry = mTimeLineWindows.constFind(w);
 
84
    if (entry != mTimeLineWindows.constEnd()) {
 
85
        // 0 = not minimized, 1 = fully minimized
 
86
        double progress = entry.value()->currentValue();
 
87
 
 
88
        QRect geo = w->geometry();
 
89
        QRect icon = w->iconGeometry();
 
90
        // If there's no icon geometry, minimize to the center of the screen
 
91
        if (!icon.isValid())
 
92
            icon = QRect(displayWidth() / 2, displayHeight() / 2, 0, 0);
 
93
 
 
94
        data.xScale *= interpolate(1.0, icon.width() / (double)geo.width(), progress);
 
95
        data.yScale *= interpolate(1.0, icon.height() / (double)geo.height(), progress);
 
96
        data.xTranslate = (int)interpolate(data.xTranslate, icon.x() - geo.x(), progress);
 
97
        data.yTranslate = (int)interpolate(data.yTranslate, icon.y() - geo.y(), progress);
 
98
        data.opacity *= 0.1 + (1 - progress) * 0.9;
 
99
    }
 
100
 
 
101
    // Call the next effect.
 
102
    effects->paintWindow(w, mask, region, data);
 
103
}
 
104
 
 
105
void MinimizeAnimationEffect::postPaintScreen()
 
106
{
 
107
    if (mActiveAnimations > 0)
 
108
        // Repaint the workspace so that everything would be repainted next time
 
109
        effects->addRepaintFull();
 
110
    mActiveAnimations = mTimeLineWindows.count();
 
111
 
 
112
    // Call the next effect.
 
113
    effects->postPaintScreen();
 
114
}
 
115
 
 
116
void MinimizeAnimationEffect::slotWindowDeleted(EffectWindow* w)
 
117
{
 
118
    delete mTimeLineWindows.take(w);
 
119
}
 
120
 
 
121
void MinimizeAnimationEffect::slotWindowMinimized(EffectWindow* w)
 
122
{
 
123
    if (effects->activeFullScreenEffect())
 
124
        return;
 
125
    QTimeLine *timeline;
 
126
    if (mTimeLineWindows.contains(w)) {
 
127
        timeline = mTimeLineWindows[w];
 
128
    } else {
 
129
        timeline = new QTimeLine(animationTime(250), this);
 
130
        mTimeLineWindows.insert(w, timeline);
 
131
    }
 
132
    timeline->setCurveShape(QTimeLine::EaseInCurve);
 
133
    timeline->setCurrentTime(0.0);
 
134
}
 
135
 
 
136
void MinimizeAnimationEffect::slotWindowUnminimized(EffectWindow* w)
 
137
{
 
138
    if (effects->activeFullScreenEffect())
 
139
        return;
 
140
    QTimeLine *timeline;
 
141
    if (mTimeLineWindows.contains(w)) {
 
142
        timeline = mTimeLineWindows[w];
 
143
    } else {
 
144
        timeline = new QTimeLine(animationTime(250), this);
 
145
        mTimeLineWindows.insert(w, timeline);
 
146
    }
 
147
    timeline->setCurveShape(QTimeLine::EaseInOutCurve);
 
148
    timeline->setCurrentTime(timeline->duration());
 
149
}
 
150
 
 
151
} // namespace
 
152