~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kwin/clients/oxygen/helper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 */
 
18
 
 
19
#include "helper.h"
 
20
 
 
21
#include <KColorUtils>
 
22
 
 
23
#include <QtGui/QPainter>
 
24
 
 
25
#include <math.h>
 
26
 
 
27
OxygenWindecoHelper::OxygenWindecoHelper(const QByteArray &componentName)
 
28
    : OxygenHelper(componentName)
 
29
{
 
30
    m_windecoButtonCache.setMaxCost(64);
 
31
}
 
32
 
 
33
QPixmap OxygenWindecoHelper::windecoButton(const QColor &color, int size)
 
34
{
 
35
    quint64 key = (quint64(color.rgba()) << 32) | size;
 
36
    QPixmap *pixmap = m_windecoButtonCache.object(key);
 
37
 
 
38
    if (!pixmap)
 
39
    {
 
40
        pixmap = new QPixmap(size, (int)ceil(double(size)*10.0/9.0));
 
41
        pixmap->fill(QColor(0,0,0,0));
 
42
 
 
43
        QPainter p(pixmap);
 
44
        p.setRenderHints(QPainter::Antialiasing);
 
45
        p.setPen(Qt::NoPen);
 
46
        p.setWindow(0,0,18,20);
 
47
 
 
48
        QColor light = calcLightColor(color);
 
49
        QColor dark = calcDarkColor(color);
 
50
 
 
51
        // shadow
 
52
        drawShadow(p, calcShadowColor(color), 18);
 
53
 
 
54
        // bevel
 
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));
 
65
 
 
66
        // inside mask
 
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);
 
74
 
 
75
        // inside
 
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));
 
82
 
 
83
        // anti-shadow
 
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));
 
90
 
 
91
        m_windecoButtonCache.insert(key, pixmap);
 
92
    }
 
93
 
 
94
    return *pixmap;
 
95
}