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

« back to all changes in this revision

Viewing changes to kwin/effects/_test/swiveltabs/swiveltabs.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) 2009 Jorge Mata <matamax123@gmail.com>
 
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 "swiveltabs.h"
 
22
#include <cmath>
 
23
 
 
24
namespace KWin
 
25
{
 
26
 
 
27
KWIN_EFFECT(swiveltabs, SwivelTabsEffect)
 
28
KWIN_EFFECT_SUPPORTED(swiveltabs, SwivelTabsEffect::supported())
 
29
 
 
30
SwivelTabsEffect::SwivelTabsEffect()
 
31
{
 
32
    isActive = false;
 
33
    PI = 2.0 * acos(0.0);
 
34
    reconfigure(ReconfigureAll);
 
35
}
 
36
 
 
37
bool SwivelTabsEffect::supported()
 
38
{
 
39
    return effects->compositingType() == OpenGLCompositing;
 
40
}
 
41
 
 
42
void SwivelTabsEffect::reconfigure(ReconfigureFlags)
 
43
{
 
44
    KConfigGroup conf = EffectsHandler::effectConfig("SwivelTabs");
 
45
    vertical = conf.readEntry("SwivelVertical", true);
 
46
    horizontal = conf.readEntry("SwivelHorizontal", true);
 
47
    totalTime = conf.readEntry("SwivelDuration", 500);
 
48
}
 
49
 
 
50
void SwivelTabsEffect::prePaintScreen(ScreenPrePaintData& data, int time)
 
51
{
 
52
    if (isActive)
 
53
        data.mask |= Effect::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
 
54
    effects->prePaintScreen(data, time);
 
55
}
 
56
 
 
57
void SwivelTabsEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time)
 
58
{
 
59
    if (isActive && (w == windows.show || w == windows.hide)) {
 
60
        data.quads = data.quads.makeGrid(40);
 
61
        data.setTransformed();
 
62
        w->enablePainting(EffectWindow::PAINT_DISABLED);
 
63
        windows.time.addTime(time);
 
64
    }
 
65
    effects->prePaintWindow(w, data, time);
 
66
}
 
67
 
 
68
void SwivelTabsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
 
69
{
 
70
    if (isActive && (w == windows.show || w == windows.hide)) {
 
71
        for (int i = 0; i < data.quads.count(); ++i)
 
72
            transformQuad(data.quads[i]);
 
73
    }
 
74
    effects->paintWindow(w, mask, region, data);
 
75
}
 
76
 
 
77
void SwivelTabsEffect::postPaintWindow(EffectWindow* w)
 
78
{
 
79
    if (isActive && (w == windows.show || w == windows.hide))
 
80
        w->addRepaintFull();
 
81
    effects->postPaintWindow(w);
 
82
}
 
83
 
 
84
void SwivelTabsEffect::transformQuad(WindowQuad &quad)
 
85
{
 
86
    double F = windows.time.progress();
 
87
    int width = quad[1].x() - quad[0].x();
 
88
    int height = quad[3].y() - quad[0].y();
 
89
    int cx = quad[0].x() + (width / 2);
 
90
    int cy = quad[0].y() + (height / 2);
 
91
    if (lastF < 0.5 && F > 0.5) {
 
92
        effects->setElevatedWindow(windows.hide, false);
 
93
        effects->setElevatedWindow(windows.show, true);
 
94
    }
 
95
    lastF = F;
 
96
    if (F >= 1.0) {
 
97
        isActive = false;
 
98
        effects->setElevatedWindow(windows.hide, false);
 
99
        effects->setElevatedWindow(windows.show, false);
 
100
    }
 
101
    if (F < 0.5) {
 
102
        if (horizontal) {
 
103
            quad[0].setX(quad[0].x() + (width * F));
 
104
            quad[3].setX(quad[3].x() + (width * F));
 
105
            quad[1].setX(quad[1].x() - (width * F));
 
106
            quad[2].setX(quad[2].x() - (width * F));
 
107
        }
 
108
        if (vertical) {
 
109
            quad[0].setY(quad[0].y() + (height * F));
 
110
            quad[3].setY(quad[3].y() - (height * F));
 
111
            quad[1].setY(quad[1].y() + (height * F));
 
112
            quad[2].setY(quad[2].y() - (height * F));
 
113
        }
 
114
    } else {
 
115
        F -= 0.5;
 
116
        if (horizontal) {
 
117
            quad[0].setX(cx - (width * F));
 
118
            quad[3].setX(cx - (width * F));
 
119
            quad[1].setX(cx + (width * F));
 
120
            quad[2].setX(cx + (width * F));
 
121
        }
 
122
        if (vertical) {
 
123
            quad[0].setY(cy - (height * F));
 
124
            quad[3].setY(cy + (height * F));
 
125
            quad[1].setY(cy - (height * F));
 
126
            quad[2].setY(cy + (height * F));
 
127
        }
 
128
    }
 
129
}
 
130
 
 
131
void SwivelTabsEffect::clientGroupItemSwitched(EffectWindow* from, EffectWindow* to)
 
132
{
 
133
    if (isActive || from->isMinimized())
 
134
        return;
 
135
    windows.show = to;
 
136
    windows.hide = from;
 
137
    windows.time.setCurveShape(TimeLine::LinearCurve);
 
138
    windows.time.setDuration(animationTime(totalTime));
 
139
    windows.time.setProgress(0.0f);
 
140
    lastF = 0.0;
 
141
    isActive = true;
 
142
    effects->setElevatedWindow(to, false);
 
143
    effects->setElevatedWindow(from, true);
 
144
}
 
145
 
 
146
}