fix dialogparent implementation

forward port of 26a5f4dc3ec42616a13eee4f0112a22b6361c241
CCBUG: 267349
This commit is contained in:
Thomas Lübking 2011-03-19 16:34:46 +01:00
parent 2a91623891
commit f980fd8a8d
2 changed files with 28 additions and 40 deletions

View file

@ -3,6 +3,7 @@
This file is part of the KDE project.
Copyright (C) 2006 Rivo Laks <rivolaks@hot.ee>
Copyright (C) 2011 Thomas Lübking <thomas.luebking@web.de>
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
@ -35,76 +36,63 @@ DialogParentEffect::DialogParentEffect()
void DialogParentEffect::reconfigure(ReconfigureFlags)
{
// How long does it take for the effect to get it's full strength (in ms)
changeTime = animationTime(200);
changeTime = animationTime(300);
}
void DialogParentEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
{
// Check if this window has a modal dialog and change the window's
// effect's strength accordingly
bool hasDialog = w->findModal() != NULL;
if (hasDialog) {
// Increase effect strength of this window
effectStrength[w] = qMin(1.0, effectStrength[w] + time / changeTime);
} else {
effectStrength[w] = qMax(0.0, effectStrength[w] - time / changeTime);
QMap<EffectWindow*, float>::iterator it = effectStrength.find(w);
if (it != effectStrength.end()) {
if (!w->findModal()) {
*it -= time/changeTime;
if (*it <= 0.0f)
effectStrength.erase(it);
}
else if (*it < 1.0f)
*it = qMin(1.0f, *it + time/changeTime);
}
// Call the next effect
effects->prePaintWindow(w, data, time);
}
void DialogParentEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
double s = effectStrength[w];
const float s = effectStrength.value(w, 0.0);
if (s > 0.0f) {
// 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);
data.brightness *= (1.0f - 0.4*s); // [1.0; 0.6]
data.saturation *= (1.0f - 0.6*s); // [1.0; 0.4]
}
// Call the next effect.
effects->paintWindow(w, mask, region, data);
}
void DialogParentEffect::postPaintWindow(EffectWindow* w)
{
double s = effectStrength[w];
const float s = effectStrength.value(w, 0.0);
if (s > 0.0f && s < 1.0f) // not done yet
w->addRepaintFull();
// If strength is between 0 and 1, the effect is still in progress and the
// window has to be repainted during the next pass
if (s > 0.0 && s < 1.0)
w->addRepaintFull(); // trigger next animation repaint
// Call the next effect.
effects->postPaintWindow(w);
effects->postPaintWindow( w );
}
void DialogParentEffect::slotWindowActivated(EffectWindow* w)
{
// 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).
if (w && w->isModal()) {
// w is a modal dialog
EffectWindowList mainwindows = w->mainWindows();
foreach (EffectWindow * parent, mainwindows)
parent->addRepaintFull();
foreach (EffectWindow* parent, mainwindows) {
if (!effectStrength.contains(parent))
effectStrength[parent] = 0.0;
parent->addRepaintFull();
}
}
}
void DialogParentEffect::slotWindowClosed(EffectWindow* w)
{
// 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).
if (w && w->isModal()) {
// w is a modal dialog
EffectWindowList mainwindows = w->mainWindows();
foreach (EffectWindow * parent, mainwindows)
parent->addRepaintFull();
foreach(EffectWindow* parent, mainwindows)
parent->addRepaintFull(); // brighten up
}
effectStrength.remove(w);
}
} // namespace

View file

@ -53,8 +53,8 @@ protected:
bool hasModalWindow(EffectWindow* t);
private:
// The progress of the fading.
QHash<EffectWindow*, double> effectStrength;
double changeTime;
QMap<EffectWindow*, float> effectStrength;
float changeTime;
};
} // namespace