kwin/effects/sheet/sheet.cpp

206 lines
6 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com>
Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "sheet.h"
#include "sheetconfig.h"
#include <QTimeLine>
#include <QGraphicsRotation>
#include <QVector3D>
// Effect is based on fade effect by Philip Falkner
namespace KWin
{
static const int IsSheetWindow = 0x22A982D5;
SheetEffect::SheetEffect()
2011-01-30 14:34:42 +00:00
{
reconfigure(ReconfigureAll);
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
2011-01-30 14:34:42 +00:00
}
bool SheetEffect::supported()
2011-01-30 14:34:42 +00:00
{
return effects->isOpenGLCompositing();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void SheetEffect::reconfigure(ReconfigureFlags)
{
SheetConfig::self()->readConfig();
duration = animationTime(SheetConfig::animationTime() != 0 ? SheetConfig::animationTime() : 500);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void SheetEffect::prePaintScreen(ScreenPrePaintData& data, int time)
{
if (!windows.isEmpty()) {
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
screenTime = time;
}
2011-01-30 14:34:42 +00:00
effects->prePaintScreen(data, time);
}
2011-01-30 14:34:42 +00:00
void SheetEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
{
InfoMap::iterator info = windows.find(w);
if (info != windows.end()) {
data.setTransformed();
2011-01-30 14:34:42 +00:00
if (info->added)
info->timeLine->setCurrentTime(info->timeLine->currentTime() + screenTime);
2011-01-30 14:34:42 +00:00
else if (info->closed) {
info->timeLine->setCurrentTime(info->timeLine->currentTime() - screenTime);
2011-01-30 14:34:42 +00:00
if (info->deleted)
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
}
2011-01-30 14:34:42 +00:00
}
effects->prePaintWindow(w, data, time);
// if the window isn't to be painted, then let's make sure
// to track its progress
2011-01-30 14:34:42 +00:00
if (info != windows.end() && !w->isPaintingEnabled() && !effects->activeFullScreenEffect())
w->addRepaintFull();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void SheetEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
InfoMap::const_iterator info = windows.constFind(w);
if (info != windows.constEnd()) {
const double progress = info->timeLine->currentValue();
QGraphicsRotation rot;
data.setRotationAxis(Qt::XAxis);
data.setRotationAngle(60.0 * (1.0 - progress));
data *= QVector3D(1.0, progress, progress);
data.translate(0.0, - (w->y() - info->parentY) * (1.0 - progress));
}
2011-01-30 14:34:42 +00:00
effects->paintWindow(w, mask, region, data);
}
2011-01-30 14:34:42 +00:00
void SheetEffect::postPaintWindow(EffectWindow* w)
{
InfoMap::iterator info = windows.find(w);
if (info != windows.end()) {
if (info->added && info->timeLine->currentValue() == 1.0) {
2011-01-30 14:34:42 +00:00
windows.remove(w);
effects->addRepaintFull();
} else if (info->closed && info->timeLine->currentValue() == 0.0) {
info->closed = false;
2011-01-30 14:34:42 +00:00
if (info->deleted) {
windows.remove(w);
w->unrefWindow();
}
2011-01-30 14:34:42 +00:00
effects->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
if (info->added || info->closed)
w->addRepaintFull();
}
2011-01-30 14:34:42 +00:00
effects->postPaintWindow(w);
}
void SheetEffect::slotWindowAdded(EffectWindow* w)
2011-01-30 14:34:42 +00:00
{
if (!isSheetWindow(w))
return;
2011-01-30 14:34:42 +00:00
w->setData(IsSheetWindow, true);
InfoMap::iterator it = windows.find(w);
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
info->added = true;
info->closed = false;
info->deleted = false;
delete info->timeLine;
info->timeLine = new QTimeLine(duration);
const EffectWindowList stack = effects->stackingOrder();
// find parent
2011-01-30 14:34:42 +00:00
foreach (EffectWindow * window, stack) {
if (window->findModal() == w) {
info->parentY = window->y();
break;
}
}
2011-01-30 14:34:42 +00:00
w->addRepaintFull();
}
void SheetEffect::slotWindowClosed(EffectWindow* w)
2011-01-30 14:34:42 +00:00
{
if (!isSheetWindow(w))
return;
2011-01-30 14:34:42 +00:00
w->refWindow();
2011-01-30 14:34:42 +00:00
InfoMap::iterator it = windows.find(w);
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
info->added = false;
info->closed = true;
info->deleted = true;
delete info->timeLine;
info->timeLine = new QTimeLine(duration);
info->timeLine->setCurrentTime(duration);
bool found = false;
// find parent
const EffectWindowList stack = effects->stackingOrder();
2011-01-30 14:34:42 +00:00
foreach (EffectWindow * window, stack) {
if (window->findModal() == w) {
info->parentY = window->y();
found = true;
break;
}
2011-01-30 14:34:42 +00:00
}
if (!found)
info->parentY = 0;
w->addRepaintFull();
2011-01-30 14:34:42 +00:00
}
void SheetEffect::slotWindowDeleted(EffectWindow* w)
2011-01-30 14:34:42 +00:00
{
windows.remove(w);
}
2011-01-30 14:34:42 +00:00
bool SheetEffect::isSheetWindow(EffectWindow* w)
{
return (w->isModal() || w->data(IsSheetWindow).toBool());
}
bool SheetEffect::isActive() const
{
return !windows.isEmpty();
}
SheetEffect::WindowInfo::WindowInfo()
: deleted(false)
, added(false)
, closed(false)
, timeLine(0)
, parentY(0)
{
}
SheetEffect::WindowInfo::~WindowInfo()
{
delete timeLine;
}
} // namespace