1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
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.
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.
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
*********************************************************************/
21
#include "minimizeanimation.h"
22
#include <QtCore/QTimeLine>
27
KWIN_EFFECT(minimizeanimation, MinimizeAnimationEffect)
29
MinimizeAnimationEffect::MinimizeAnimationEffect()
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*)));
38
void MinimizeAnimationEffect::prePaintScreen(ScreenPrePaintData& data, int time)
41
QHash< EffectWindow*, QTimeLine* >::iterator entry = mTimeLineWindows.begin();
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);
49
timeline->setCurrentTime(timeline->currentTime() - time);
50
erase = (timeline->currentValue() <= 0.0f);
54
entry = mTimeLineWindows.erase(entry);
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;
65
effects->prePaintScreen(data, time);
68
void MinimizeAnimationEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
70
// Schedule window for transformation if the animation is still in
72
if (mTimeLineWindows.contains(w)) {
73
// We'll transform this window
74
data.setTransformed();
75
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE);
78
effects->prePaintWindow(w, data, time);
81
void MinimizeAnimationEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
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();
88
QRect geo = w->geometry();
89
QRect icon = w->iconGeometry();
90
// If there's no icon geometry, minimize to the center of the screen
92
icon = QRect(displayWidth() / 2, displayHeight() / 2, 0, 0);
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;
101
// Call the next effect.
102
effects->paintWindow(w, mask, region, data);
105
void MinimizeAnimationEffect::postPaintScreen()
107
if (mActiveAnimations > 0)
108
// Repaint the workspace so that everything would be repainted next time
109
effects->addRepaintFull();
110
mActiveAnimations = mTimeLineWindows.count();
112
// Call the next effect.
113
effects->postPaintScreen();
116
void MinimizeAnimationEffect::slotWindowDeleted(EffectWindow* w)
118
delete mTimeLineWindows.take(w);
121
void MinimizeAnimationEffect::slotWindowMinimized(EffectWindow* w)
123
if (effects->activeFullScreenEffect())
126
if (mTimeLineWindows.contains(w)) {
127
timeline = mTimeLineWindows[w];
129
timeline = new QTimeLine(animationTime(250), this);
130
mTimeLineWindows.insert(w, timeline);
132
timeline->setCurveShape(QTimeLine::EaseInCurve);
133
timeline->setCurrentTime(0.0);
136
void MinimizeAnimationEffect::slotWindowUnminimized(EffectWindow* w)
138
if (effects->activeFullScreenEffect())
141
if (mTimeLineWindows.contains(w)) {
142
timeline = mTimeLineWindows[w];
144
timeline = new QTimeLine(animationTime(250), this);
145
mTimeLineWindows.insert(w, timeline);
147
timeline->setCurveShape(QTimeLine::EaseInOutCurve);
148
timeline->setCurrentTime(timeline->duration());