2
* Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License version 2 as published by the Free Software Foundation.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Library General Public License for more details.
13
* You should have received a copy of the GNU Library General Public License
14
* along with this library; see the file COPYING.LIB. If not, write to
15
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
* Boston, MA 02110-1301, USA.
21
#include <KColorUtils>
23
#include <QtGui/QPainter>
27
OxygenWindecoHelper::OxygenWindecoHelper(const QByteArray &componentName)
28
: OxygenHelper(componentName)
30
m_windecoButtonCache.setMaxCost(64);
33
QPixmap OxygenWindecoHelper::windecoButton(const QColor &color, int size)
35
quint64 key = (quint64(color.rgba()) << 32) | size;
36
QPixmap *pixmap = m_windecoButtonCache.object(key);
40
pixmap = new QPixmap(size, (int)ceil(double(size)*10.0/9.0));
41
pixmap->fill(QColor(0,0,0,0));
44
p.setRenderHints(QPainter::Antialiasing);
46
p.setWindow(0,0,18,20);
48
QColor light = calcLightColor(color);
49
QColor dark = calcDarkColor(color);
52
drawShadow(p, calcShadowColor(color), 18);
55
qreal y = KColorUtils::luma(color);
56
qreal yl = KColorUtils::luma(light);
57
qreal yd = KColorUtils::luma(light);
58
QLinearGradient bevelGradient(0, 0, 0, 18);
59
bevelGradient.setColorAt(0.45, light);
60
bevelGradient.setColorAt(0.80, dark);
61
if (y < yl && y > yd) // no middle when color is very light/dark
62
bevelGradient.setColorAt(0.55, color);
63
p.setBrush(QBrush(bevelGradient));
64
p.drawEllipse(QRectF(2.0,2.0,14.0,14.0));
67
QRadialGradient maskGradient(9,9,7,9,9);
68
maskGradient.setColorAt(0.70, QColor(0,0,0,0));
69
maskGradient.setColorAt(0.85, QColor(0,0,0,140));
70
maskGradient.setColorAt(0.95, QColor(0,0,0,255));
71
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
72
p.setBrush(maskGradient);
73
p.drawRect(0,0,20,20);
76
QLinearGradient innerGradient(0, 3, 0, 15);
77
innerGradient.setColorAt(0.0, color);
78
innerGradient.setColorAt(1.0, light);
79
p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
80
p.setBrush(innerGradient);
81
p.drawEllipse(QRectF(2.0,2.0,14.0,14.0));
84
QRadialGradient highlightGradient(9,8.5,8,9,8.5);
85
highlightGradient.setColorAt(0.85, alphaColor(light, 0.0));
86
highlightGradient.setColorAt(1.00, light);
87
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
88
p.setBrush(highlightGradient);
89
p.drawEllipse(QRectF(2.0,2.0,14.0,14.0));
91
m_windecoButtonCache.insert(key, pixmap);