[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase
From: Matthew Woehlke <mw_triad () users ! sourceforge ! net>
Date: 2007-08-25 1:11:59
Message-ID: 1188004319.456557.29620.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 704482 by mwoehlke:
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.
M +55 -0 runtime/kstyles/oxygen/helper.cpp
M +6 -0 runtime/kstyles/oxygen/helper.h
M +53 -66 runtime/kstyles/oxygen/lib/helper.cpp
M +12 -4 runtime/kstyles/oxygen/lib/helper.h
M +16 -6 runtime/kstyles/oxygen/oxygen.cpp
M +1 -0 workspace/kwin/clients/oxygen/CMakeLists.txt
A workspace/kwin/clients/oxygen/helper.cpp [License: LGPL (v2)]
A workspace/kwin/clients/oxygen/helper.h [License: LGPL (v2)]
M +3 -3 workspace/kwin/clients/oxygen/oxygenbutton.cpp
--- trunk/KDE/kdebase/runtime/kstyles/oxygen/helper.cpp #704481:704482
@@ -27,8 +27,63 @@
OxygenStyleHelper::OxygenStyleHelper(const QByteArray &componentName)
: OxygenHelper(componentName)
{
+ m_roundSlabCache.setMaxCost(64);
}
+QPixmap OxygenStyleHelper::roundSlab(const QColor &color, int size, double shade)
+{
+ quint64 key = (quint64(color.rgba()) << 32) | (int)(256.0 * shade) << 24 | size;
+ QPixmap *pixmap = m_roundSlabCache.object(key);
+
+ if (!pixmap)
+ {
+ pixmap = new QPixmap(size, int(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 base = KColorUtils::shade(color, shade);
+ QColor light = KColorUtils::shade(calcLightColor(color), shade);
+ QColor dark = KColorUtils::shade(calcDarkColor(color), shade);
+
+ // shadow
+ drawShadow(p, calcShadowColor(color), 18);
+
+ // bevel, part 1
+ qreal y = KColorUtils::luma(base);
+ qreal yl = KColorUtils::luma(light);
+ qreal yd = KColorUtils::luma(light);
+ QLinearGradient bevelGradient1(0, 9, 0, 16);
+ bevelGradient1.setColorAt(0.0, light);
+ bevelGradient1.setColorAt(0.9, dark);
+ if (y < yl && y > yd) // no middle when color is very light/dark
+ bevelGradient1.setColorAt(0.5, base);
+ p.setBrush(bevelGradient1);
+ p.drawEllipse(QRectF(2.0,2.0,14.0,14.0));
+
+ // bevel, part 2
+ QLinearGradient bevelGradient2(0, 6, 0, 26);
+ bevelGradient2.setColorAt(0.0, light);
+ bevelGradient2.setColorAt(0.9, base);
+ p.setBrush(bevelGradient2);
+ p.drawEllipse(QRectF(2.6,2.6,12.8,12.8));
+
+ // inside
+ QLinearGradient innerGradient(-12, 0, 0, 18);
+ innerGradient.setColorAt(0.0, light);
+ innerGradient.setColorAt(1.0, base);
+ p.setBrush(innerGradient);
+ p.drawEllipse(QRectF(3.4,3.4,11.2,11.2));
+
+ m_roundSlabCache.insert(key, pixmap);
+ }
+
+ return *pixmap;
+}
+
TileSet *OxygenStyleHelper::slab(const QColor &surroundColor)
{
quint64 key = (quint64(surroundColor.rgba()) << 32);
--- trunk/KDE/kdebase/runtime/kstyles/oxygen/helper.h #704481:704482
@@ -29,15 +29,21 @@
explicit OxygenStyleHelper(const QByteArray &componentName);
virtual ~OxygenStyleHelper() {}
+ QPixmap roundSlab(const QColor &color, int size, double shade);
+
TileSet *slab(const QColor &color);
TileSet *slabFocused(const QColor &color, QColor glowColor);
TileSet *slabSunken(const QColor &color);
+
TileSet *slope(const QColor &surroundColor);
+
TileSet *hole(const QColor &color);
TileSet *holeFocused(const QColor &color, QColor glowColor);
+
TileSet *verticalScrollBar(const QColor &color, int width, int height, int \
offset);
protected:
+ QCache<quint64, QPixmap> m_roundSlabCache;
QCache<quint64, TileSet> m_setCache;
QCache<quint64, TileSet> m_slabCache;
QCache<quint64, TileSet> m_slabFocusedCache;
--- trunk/KDE/kdebase/runtime/kstyles/oxygen/lib/helper.cpp #704481:704482
@@ -26,6 +26,8 @@
#include <QtGui/QPainter>
+#include <math.h>
+
// alphaBlendColors Copyright 2003 Sandro Giessl <ceebx@users.sourceforge.net>
// DEPRECATED (use KColorUtils::mix to the extent we still need such a critter)
QColor alphaBlendColors(const QColor &bgColor, const QColor &fgColor, const int a)
@@ -58,7 +60,6 @@
_bgcontrast = 0.1;// // shouldn't use contrast for this _contrast; // TODO get \
style setting
m_backgroundCache.setMaxCost(64);
- m_roundCache.setMaxCost(64);
}
KSharedConfigPtr OxygenHelper::config() const
@@ -72,6 +73,12 @@
return KColorUtils::luma(darker) > KColorUtils::luma(color);
}
+QColor OxygenHelper::alphaColor(QColor color, double alpha)
+{
+ color.setAlphaF(alpha);
+ return color;
+}
+
QColor OxygenHelper::backgroundRadialColor(const QColor &color) const
{
if (lowThreshold(color))
@@ -103,9 +110,30 @@
QColor OxygenHelper::calcDarkColor(const QColor &color)
{
- return KColorScheme::shade(color, KColorScheme::MidShade, _contrast);
+ if (lowThreshold(color))
+ return KColorUtils::mix(calcLightColor(color), color, 0.2 + 0.8 * \
_contrast); + else
+ return KColorScheme::shade(color, KColorScheme::MidShade, _contrast);
}
+QColor OxygenHelper::calcShadowColor(const QColor &color)
+{
+ return KColorScheme::shade(color, KColorScheme::ShadowShade, _contrast);
+}
+
+QColor OxygenHelper::backgroundColor(const QColor &color, int height, int y)
+{
+ double h = height * 0.5;
+ if (y > height>>1) {
+ double a = double(y) / h;
+ return KColorUtils::mix(backgroundTopColor(color), color, a);
+ }
+ else {
+ double a = (double(y) - h) / h;
+ return KColorUtils::mix(color, backgroundBottomColor(color), a);
+ }
+}
+
QPixmap OxygenHelper::verticalGradient(const QColor &color, int height)
{
quint64 key = (quint64(color.rgba()) << 32) | height | 0x8000;
@@ -161,73 +189,32 @@
return *pixmap;
}
-QPixmap OxygenHelper::roundButton(const QColor &color, int size)
+void OxygenHelper::drawShadow(QPainter &p, const QColor &color, int size)
{
- quint64 key = (quint64(color.rgba()) << 32) | size;
- QPixmap *pixmap = m_roundCache.object(key);
+ int m = size>>1;
- if (!pixmap)
- {
- pixmap = new QPixmap(size, size);
- pixmap->fill(QColor(0,0,0,0));
+ const double offset = 0.8;
+ double k0 = (double(m) - 4.0) / double(m);
+ QRadialGradient shadowGradient(m, m+offset, m, m, m+offset);
+ for (int i = 0; i < 8; i++) { // sinusoidal gradient
+ double k1 = k0 * double(8 - i) * 0.125 + double(i) * 0.125;
+ double a = (cos(3.14159 * i * 0.125) + 1.0) * 0.25;
+ shadowGradient.setColorAt(k1, alphaColor(color, a));
+ }
+ shadowGradient.setColorAt(1.0, alphaColor(color, 0.0));
+ p.setBrush(shadowGradient);
+ p.drawEllipse(QRectF(0, offset, size, size+offset));
+}
- QPainter p(pixmap);
- p.setRenderHints(QPainter::Antialiasing);
- p.setPen(Qt::NoPen);
- p.setWindow(0,0,20,20);
+QLinearGradient OxygenHelper::decoGradient(const QRect &r, const QColor &color)
+{
+ QColor light = KColorUtils::lighten(color, _contrast * 0.4);
+ QColor dark = KColorUtils::darken(color, _contrast * 0.4);
- // shadow
- QRadialGradient shadowGradient(10, 11, 9, 10, 12);
- shadowGradient.setColorAt(0.0, QColor(0,0,0,80));
- shadowGradient.setColorAt(1.0, QColor(0,0,0,0));
- p.setBrush(shadowGradient);
- p.drawEllipse(QRectF(0, 0, 20, 20));
+ QLinearGradient gradient(r.topLeft(), r.bottomLeft());
+ gradient.setColorAt(0.15, dark);
+ gradient.setColorAt(0.50, color);
+ gradient.setColorAt(0.85, light);
- // outline
- QRadialGradient edgeGradient(10, 10, 9, 10, 10);
- edgeGradient.setColorAt(0.0, QColor(0,0,0,60));
- edgeGradient.setColorAt(0.9, QColor(0,0,0,20));
- edgeGradient.setColorAt(1.0, QColor(0,0,0,0));
- p.setBrush(edgeGradient);
- p.drawEllipse(QRectF(0, 0, 20, 20));
-
- // base (for anti-shadow)
- p.setBrush(color);
- p.drawEllipse(QRectF(2.4,2.4,15.2,15.2));
-
- // bevel
- QColor light = calcLightColor(color);
- QColor dark = calcDarkColor(color);
- 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.65, 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.4,2.4,15.2,15.0));
-
- // inside mask
- QRadialGradient maskGradient(10,10,7.4,10,10);
- maskGradient.setColorAt(0.75, QColor(0,0,0,0));
- maskGradient.setColorAt(0.90, QColor(0,0,0,140));
- maskGradient.setColorAt(1.00, QColor(0,0,0,255));
- p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
- p.setBrush(maskGradient);
- p.drawRect(0,0,20,20);
-
- // inside
- QLinearGradient innerGradient(0, 0, 0, 20);
- innerGradient.setColorAt(0.0, color);
- innerGradient.setColorAt(1.0, calcLightColor(color));
- p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
- p.setBrush(innerGradient);
- p.drawEllipse(QRectF(2.5,2.5,15.0,14.8));
-
- m_roundCache.insert(key, pixmap);
- }
-
- return *pixmap;
+ return gradient;
}
--- trunk/KDE/kdebase/runtime/kstyles/oxygen/lib/helper.h #704481:704482
@@ -26,6 +26,7 @@
#include <QtGui/QColor>
#include <QtGui/QPixmap>
+#include <QtGui/QLinearGradient>
#include <QtCore/QCache>
// alphaBlendColors Copyright 2003 Sandro Giessl <ceebx@users.sourceforge.net>
@@ -42,17 +43,25 @@
KSharedConfigPtr config() const;
static bool lowThreshold(const QColor &color);
+ QColor alphaColor(QColor color, double alpha);
+
+ QColor calcLightColor(const QColor &color);
+ QColor calcDarkColor(const QColor &color);
+ QColor calcShadowColor(const QColor &color);
+
+ QColor backgroundColor(const QColor &color, int height, int y);
+
QColor backgroundRadialColor(const QColor &color) const;
QColor backgroundTopColor(const QColor &color) const;
QColor backgroundBottomColor(const QColor &color) const;
- QColor calcLightColor(const QColor &color);
- QColor calcDarkColor(const QColor &color);
QPixmap verticalGradient(const QColor &color, int height);
QPixmap radialGradient(const QColor &color, int width);
- QPixmap roundButton(const QColor &color, int size);
+ void drawShadow(QPainter &p, const QColor &color, int size);
+ QLinearGradient decoGradient(const QRect &r, const QColor &color);
+
protected:
KComponentData _componentData;
KSharedConfigPtr _config;
@@ -60,7 +69,6 @@
qreal _bgcontrast;
QCache<quint64, QPixmap> m_backgroundCache;
- QCache<quint64, QPixmap> m_roundCache;
};
#endif // __OXYGEN_HELPER_H
--- trunk/KDE/kdebase/runtime/kstyles/oxygen/oxygen.cpp #704481:704482
@@ -1275,7 +1275,7 @@
return;
TileSet *tile;
- QColor base = QColor(Qt::white);
+ QColor base = QColor(Qt::white); // FIXME -- wrong!
// for slabs, hover takes precedence over focus (other way around for holes)
// but in any case if the button is sunken we don't show focus nor hover
if(sunken)
@@ -1295,7 +1295,7 @@
return;
TileSet *tile;
- QColor base = QColor(Qt::white);
+ QColor base = QColor(Qt::white); // FIXME -- wrong!
// for holes, focus takes precedence over hover (other way around for buttons)
if (focus)
tile = _helper.holeFocused(base, _viewFocusColor);
@@ -1340,11 +1340,12 @@
void OxygenStyle::renderRadioButton(QPainter *p, const QRect &r, const QPalette \
&pal,
bool enabled, bool mouseOver, int prim) \
const {
- int x = r.x();
- int y = r.y();
- int s = qMin(r.width(), r.height());
+ QRect r2(r.x() + r.width()/2 - 9, r.y() + r.height()/2 - 9, 18, 20);
+ int x = r2.x();
+ int y = r2.y();
- p->drawPixmap(x, y, _helper.roundButton(pal.color(QPalette::Button), s));
+ QPixmap slabPixmap = _helper.roundSlab(pal.color(QPalette::Button), 18, 0.0);
+ p->drawPixmap(x, y+1, slabPixmap);
// highlighting...
if(mouseOver) {
@@ -1355,6 +1356,15 @@
{
case RadioButton::RadioOn:
{
+ double dx = r2.width() * 0.5 - 3.0;
+ double dy = r2.height() * 0.5 - 3.0;
+ QColor fore = pal.color(QPalette::ButtonText);
+ p->save();
+ p->setRenderHints(QPainter::Antialiasing);
+ p->setPen(Qt::NoPen);
+ p->setBrush(_helper.decoGradient(r, fore));
+ p->drawEllipse(QRectF(r2).adjusted(dx, dy, -dx, -dy));
+ p->restore();
return;
}
case RadioButton::RadioOff:
--- trunk/KDE/kdebase/workspace/kwin/clients/oxygen/CMakeLists.txt #704481:704482
@@ -2,6 +2,7 @@
set(kwin_oxy_SRCS
lib/helper.cpp
+ helper.cpp
oxygenclient.cpp
oxygenbutton.cpp
oxygen.cpp
--- trunk/KDE/kdebase/workspace/kwin/clients/oxygen/oxygenbutton.cpp #704481:704482
@@ -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 @@
}
QColor bg = globalHelper->backgroundTopColor(palette().window());
- painter.drawPixmap(0, 0, globalHelper->roundButton(palette().button(), \
BUTTONSIZE)); + painter.drawPixmap(0, 0, \
globalHelper->windecoButton(palette().button(), BUTTONSIZE)); }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic