Merge nuno-approved radio buttons and windeco buttons (approved except background needs to be a touch darker) into the style/windeco, from the buttontest toy. Since the windeco button is not used by the style, this means the windeco now has a helper subclass. As well there is some significant restructuring of the helper code.
svn path=/trunk/KDE/kdebase/workspace/; revision=704482
This commit is contained in:
parent
38bc48cb11
commit
d9d5dddc3b
4 changed files with 135 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
set(kwin_oxy_SRCS
|
||||
lib/helper.cpp
|
||||
helper.cpp
|
||||
oxygenclient.cpp
|
||||
oxygenbutton.cpp
|
||||
oxygen.cpp
|
||||
|
|
95
clients/oxygen/helper.cpp
Normal file
95
clients/oxygen/helper.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "helper.h"
|
||||
|
||||
#include <KColorUtils>
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
OxygenWindecoHelper::OxygenWindecoHelper(const QByteArray &componentName)
|
||||
: OxygenHelper(componentName)
|
||||
{
|
||||
m_windecoButtonCache.setMaxCost(64);
|
||||
}
|
||||
|
||||
QPixmap OxygenWindecoHelper::windecoButton(const QColor &color, int size)
|
||||
{
|
||||
quint64 key = (quint64(color.rgba()) << 32) | size;
|
||||
QPixmap *pixmap = m_windecoButtonCache.object(key);
|
||||
|
||||
if (!pixmap)
|
||||
{
|
||||
pixmap = new QPixmap(size, (int)ceil(double(size)*10.0/9.0));
|
||||
pixmap->fill(QColor(0,0,0,0));
|
||||
|
||||
QPainter p(pixmap);
|
||||
p.setRenderHints(QPainter::Antialiasing);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setWindow(0,0,18,20);
|
||||
|
||||
QColor light = calcLightColor(color);
|
||||
QColor dark = calcDarkColor(color);
|
||||
|
||||
// shadow
|
||||
drawShadow(p, calcShadowColor(color), 18);
|
||||
|
||||
// bevel
|
||||
qreal y = KColorUtils::luma(color);
|
||||
qreal yl = KColorUtils::luma(light);
|
||||
qreal yd = KColorUtils::luma(light);
|
||||
QLinearGradient bevelGradient(0, 0, 0, 18);
|
||||
bevelGradient.setColorAt(0.45, light);
|
||||
bevelGradient.setColorAt(0.80, dark);
|
||||
if (y < yl && y > yd) // no middle when color is very light/dark
|
||||
bevelGradient.setColorAt(0.55, color);
|
||||
p.setBrush(QBrush(bevelGradient));
|
||||
p.drawEllipse(QRectF(2.0,2.0,14.0,14.0));
|
||||
|
||||
// inside mask
|
||||
QRadialGradient maskGradient(9,9,7,9,9);
|
||||
maskGradient.setColorAt(0.70, QColor(0,0,0,0));
|
||||
maskGradient.setColorAt(0.85, QColor(0,0,0,140));
|
||||
maskGradient.setColorAt(0.95, QColor(0,0,0,255));
|
||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
p.setBrush(maskGradient);
|
||||
p.drawRect(0,0,20,20);
|
||||
|
||||
// inside
|
||||
QLinearGradient innerGradient(0, 3, 0, 15);
|
||||
innerGradient.setColorAt(0.0, color);
|
||||
innerGradient.setColorAt(1.0, light);
|
||||
p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
|
||||
p.setBrush(innerGradient);
|
||||
p.drawEllipse(QRectF(2.0,2.0,14.0,14.0));
|
||||
|
||||
// anti-shadow
|
||||
QRadialGradient highlightGradient(9,8.5,8,9,8.5);
|
||||
highlightGradient.setColorAt(0.85, alphaColor(light, 0.0));
|
||||
highlightGradient.setColorAt(1.00, light);
|
||||
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
p.setBrush(highlightGradient);
|
||||
p.drawEllipse(QRectF(2.0,2.0,14.0,14.0));
|
||||
|
||||
m_windecoButtonCache.insert(key, pixmap);
|
||||
}
|
||||
|
||||
return *pixmap;
|
||||
}
|
36
clients/oxygen/helper.h
Normal file
36
clients/oxygen/helper.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __OXYGEN_WINDECO_HELPER_H
|
||||
#define __OXYGEN_WINDECO_HELPER_H
|
||||
|
||||
#include "lib/helper.h"
|
||||
|
||||
class OxygenWindecoHelper : public OxygenHelper
|
||||
{
|
||||
public:
|
||||
explicit OxygenWindecoHelper(const QByteArray &componentName);
|
||||
virtual ~OxygenWindecoHelper() {}
|
||||
|
||||
QPixmap windecoButton(const QColor &color, int size);
|
||||
|
||||
protected:
|
||||
QCache<quint64, QPixmap> m_windecoButtonCache;
|
||||
};
|
||||
|
||||
#endif // __OXYGEN_WINDECO_HELPER_H
|
|
@ -35,11 +35,11 @@
|
|||
#include "oxygenbutton.h"
|
||||
#include "oxygen.h"
|
||||
#include "definitions.cpp"
|
||||
#include "lib/helper.h"
|
||||
#include "helper.h"
|
||||
|
||||
namespace Oxygen
|
||||
{
|
||||
K_GLOBAL_STATIC_WITH_ARGS(OxygenHelper, globalHelper, ("OxygenDeco"))
|
||||
K_GLOBAL_STATIC_WITH_ARGS(OxygenWindecoHelper, globalHelper, ("OxygenDeco"))
|
||||
|
||||
// class OxygenClient;
|
||||
/*
|
||||
|
@ -139,7 +139,7 @@ void OxygenButton::paintEvent(QPaintEvent *)
|
|||
}
|
||||
|
||||
QColor bg = globalHelper->backgroundTopColor(palette().window());
|
||||
painter.drawPixmap(0, 0, globalHelper->roundButton(palette().button(), BUTTONSIZE));
|
||||
painter.drawPixmap(0, 0, globalHelper->windecoButton(palette().button(), BUTTONSIZE));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue