add more spacing
[personal-kdebase.git] / workspace / kwin / effects / shadow_helper.h
blob6acf9d2f2aaffb8284f520e01f49d695b775fd7e
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2008 Louai Al-Khanji <louai.khanji@gmail.com>
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 // This contains code shared by the shadow effect and shadow effect configurator
22 // Mark all functions static so the symbols are not exported!
24 #ifndef KWIN_SHADOW_HELPER_H
25 #define KWIN_SHADOW_HELPER_H
27 #include <KColorScheme>
28 #include <KColorUtils>
30 static const int MAX_ITERS = 10; // should be enough
31 static const qreal LUMA_THRESHOLD = 0.05;
32 static const qreal MINIMUM_CONTRAST = 3.0;
34 static bool contrastTooLow(const QColor& one, const QColor& two)
36 return KColorUtils::contrastRatio(one, two) < MINIMUM_CONTRAST;
39 static QColor schemeShadowColor()
41 QPalette palette;
42 QColor shadowColor;
43 QPalette::ColorRole shadowRole;
44 QColor windowColor;
46 windowColor = palette.color(QPalette::Window);
48 if (KColorUtils::luma(windowColor) >= LUMA_THRESHOLD)
49 shadowRole = QPalette::Shadow;
50 else
51 shadowRole = QPalette::Light;
53 shadowColor = palette.color(shadowRole);
55 // Some styles might set a weird shadow or light color. Make sure we
56 // do not end up looping forever or we might lock up the desktop!!
57 int iters = 0;
58 while (contrastTooLow(shadowColor, windowColor) && iters < MAX_ITERS)
60 iters++;
61 if (shadowRole == QPalette::Shadow)
62 shadowColor = KColorUtils::darken(shadowColor);
63 else
64 shadowColor = KColorUtils::lighten(shadowColor);
67 return shadowColor;
70 #endif // KWIN_SHADOW_HELPER_H