2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "dialogparent.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(dialogparent, DialogParentEffect)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-09-04 16:59:14 +00:00
|
|
|
DialogParentEffect::DialogParentEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
2011-02-27 08:25:45 +00:00
|
|
|
connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-10-09 05:33:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DialogParentEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// How long does it take for the effect to get it's full strength (in ms)
|
2011-01-30 14:34:42 +00:00
|
|
|
changeTime = animationTime(200);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DialogParentEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// Check if this window has a modal dialog and change the window's
|
|
|
|
// effect's strength accordingly
|
|
|
|
bool hasDialog = w->findModal() != NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (hasDialog) {
|
2007-04-29 17:35:43 +00:00
|
|
|
// Increase effect strength of this window
|
2011-01-30 14:34:42 +00:00
|
|
|
effectStrength[w] = qMin(1.0, effectStrength[w] + time / changeTime);
|
|
|
|
} else {
|
|
|
|
effectStrength[w] = qMax(0.0, effectStrength[w] - time / changeTime);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Call the next effect
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DialogParentEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2007-09-03 15:00:43 +00:00
|
|
|
double s = effectStrength[w];
|
2011-01-30 14:34:42 +00:00
|
|
|
if (s > 0.0f) {
|
2007-04-29 17:35:43 +00:00
|
|
|
// Brightness will be within [1.0; 0.6]
|
|
|
|
data.brightness *= (1.0 - s * 0.4);
|
|
|
|
// Saturation within [1.0; 0.4]
|
|
|
|
data.saturation *= (1.0 - s * 0.6);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Call the next effect.
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DialogParentEffect::postPaintWindow(EffectWindow* w)
|
|
|
|
{
|
2007-09-03 15:00:43 +00:00
|
|
|
double s = effectStrength[w];
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// If strength is between 0 and 1, the effect is still in progress and the
|
|
|
|
// window has to be repainted during the next pass
|
2011-01-30 14:34:42 +00:00
|
|
|
if (s > 0.0 && s < 1.0)
|
2007-04-29 17:35:43 +00:00
|
|
|
w->addRepaintFull(); // trigger next animation repaint
|
|
|
|
|
|
|
|
// Call the next effect.
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintWindow(w);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DialogParentEffect::windowActivated(EffectWindow* w)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// If this window is a dialog, we need to repaint it's parent window, so
|
|
|
|
// that the effect could be run for it
|
|
|
|
// Set the window to be faded (or NULL if no window is active).
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w && w->isModal()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
// w is a modal dialog
|
|
|
|
EffectWindowList mainwindows = w->mainWindows();
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * parent, mainwindows)
|
|
|
|
parent->addRepaintFull();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void DialogParentEffect::slotWindowClosed(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// If this window is a dialog, we need to repaint it's parent window, so
|
|
|
|
// that the effect could be run for it
|
|
|
|
// Set the window to be faded (or NULL if no window is active).
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w && w->isModal()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
// w is a modal dialog
|
|
|
|
EffectWindowList mainwindows = w->mainWindows();
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * parent, mainwindows)
|
|
|
|
parent->addRepaintFull();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|