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 void DialogParentEffect::prePaintWindow( EffectWindow
* w
, WindowPrePaintData
& data
, int time
)
30 // How long does it take for the effect to get it's full strength (in ms)
31 const double changeTime
= 200;
33 // Check if this window has a modal dialog and change the window's
34 // effect's strength accordingly
35 bool hasDialog
= w
->findModal() != NULL
;
38 // Increase effect strength of this window
39 effectStrength
[w
] = qMin(1.0, effectStrength
[w
] + time
/changeTime
);
43 effectStrength
[w
] = qMax(0.0, effectStrength
[w
] - time
/changeTime
);
46 // Call the next effect
47 effects
->prePaintWindow( w
, data
, time
);
50 void DialogParentEffect::paintWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
)
52 double s
= effectStrength
[w
];
55 // Brightness will be within [1.0; 0.6]
56 data
.brightness
*= (1.0 - s
* 0.4);
57 // Saturation within [1.0; 0.4]
58 data
.saturation
*= (1.0 - s
* 0.6);
61 // Call the next effect.
62 effects
->paintWindow( w
, mask
, region
, data
);
65 void DialogParentEffect::postPaintWindow( EffectWindow
* w
)
67 double s
= effectStrength
[w
];
69 // If strength is between 0 and 1, the effect is still in progress and the
70 // window has to be repainted during the next pass
71 if( s
> 0.0 && s
< 1.0 )
72 w
->addRepaintFull(); // trigger next animation repaint
74 // Call the next effect.
75 effects
->postPaintWindow( w
);
78 void DialogParentEffect::windowActivated( EffectWindow
* w
)
80 // If this window is a dialog, we need to repaint it's parent window, so
81 // that the effect could be run for it
82 // Set the window to be faded (or NULL if no window is active).
83 if( w
&& w
->isModal() )
85 // w is a modal dialog
86 EffectWindowList mainwindows
= w
->mainWindows();
87 foreach( EffectWindow
* parent
, mainwindows
)
88 parent
->addRepaintFull();
92 void DialogParentEffect::windowClosed( EffectWindow
* w
)
94 // If this window is a dialog, we need to repaint it's parent window, so
95 // that the effect could be run for it
96 // Set the window to be faded (or NULL if no window is active).
97 if ( w
&& w
->isModal() )
99 // w is a modal dialog
100 EffectWindowList mainwindows
= w
->mainWindows();
101 foreach( EffectWindow
* parent
, mainwindows
)
102 parent
->addRepaintFull();