1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 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 "dialogparent.h"
26 KWIN_EFFECT( dialogparent
, DialogParentEffect
)
28 DialogParentEffect::DialogParentEffect()
30 reconfigure( ReconfigureAll
);
33 void DialogParentEffect::reconfigure( ReconfigureFlags
)
35 // How long does it take for the effect to get it's full strength (in ms)
36 changeTime
= animationTime( 200 );
39 void DialogParentEffect::prePaintWindow( EffectWindow
* w
, WindowPrePaintData
& data
, int time
)
41 // Check if this window has a modal dialog and change the window's
42 // effect's strength accordingly
43 bool hasDialog
= w
->findModal() != NULL
;
46 // Increase effect strength of this window
47 effectStrength
[w
] = qMin(1.0, effectStrength
[w
] + time
/changeTime
);
51 effectStrength
[w
] = qMax(0.0, effectStrength
[w
] - time
/changeTime
);
54 // Call the next effect
55 effects
->prePaintWindow( w
, data
, time
);
58 void DialogParentEffect::paintWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
)
60 double s
= effectStrength
[w
];
63 // Brightness will be within [1.0; 0.6]
64 data
.brightness
*= (1.0 - s
* 0.4);
65 // Saturation within [1.0; 0.4]
66 data
.saturation
*= (1.0 - s
* 0.6);
69 // Call the next effect.
70 effects
->paintWindow( w
, mask
, region
, data
);
73 void DialogParentEffect::postPaintWindow( EffectWindow
* w
)
75 double s
= effectStrength
[w
];
77 // If strength is between 0 and 1, the effect is still in progress and the
78 // window has to be repainted during the next pass
79 if( s
> 0.0 && s
< 1.0 )
80 w
->addRepaintFull(); // trigger next animation repaint
82 // Call the next effect.
83 effects
->postPaintWindow( w
);
86 void DialogParentEffect::windowActivated( EffectWindow
* w
)
88 // If this window is a dialog, we need to repaint it's parent window, so
89 // that the effect could be run for it
90 // Set the window to be faded (or NULL if no window is active).
91 if( w
&& w
->isModal() )
93 // w is a modal dialog
94 EffectWindowList mainwindows
= w
->mainWindows();
95 foreach( EffectWindow
* parent
, mainwindows
)
96 parent
->addRepaintFull();
100 void DialogParentEffect::windowClosed( EffectWindow
* w
)
102 // If this window is a dialog, we need to repaint it's parent window, so
103 // that the effect could be run for it
104 // Set the window to be faded (or NULL if no window is active).
105 if ( w
&& w
->isModal() )
107 // w is a modal dialog
108 EffectWindowList mainwindows
= w
->mainWindows();
109 foreach( EffectWindow
* parent
, mainwindows
)
110 parent
->addRepaintFull();