oxyhelpers (lib): remove unused stuff, add roundButton to cache, other minor stuff

NOTE: breaks oxygen style until I fix it next commit (because I can't commit different checkouts at the same time)

svn path=/trunk/KDE/kdebase/workspace/; revision=695300
This commit is contained in:
Matthew Woehlke 2007-08-01 20:14:58 +00:00
parent ba0fe2ac7b
commit 1508942ee9
2 changed files with 64 additions and 67 deletions

View file

@ -55,7 +55,8 @@ OxygenHelper::OxygenHelper(const QByteArray &componentName)
_config = _componentData.config();
_contrast = KGlobalSettings::contrastF(_config);
m_cache.setMaxCost(64);
m_backgroundCache.setMaxCost(64);
m_roundCache.setMaxCost(64);
}
KSharedConfigPtr OxygenHelper::config() const
@ -80,28 +81,18 @@ QColor OxygenHelper::backgroundBottomColor(const QColor &color) const
QColor OxygenHelper::calcLightColor(const QColor &color)
{
return KColorScheme::shade(color, KColorScheme::LightShade, 0.7);
}
QColor OxygenHelper::calcMidlightColor(const QColor &color)
{
return KColorScheme::shade(color, KColorScheme::MidlightShade, 0.7);
}
QColor OxygenHelper::calcMidColor(const QColor &color)
{
return KColorScheme::shade(color, KColorScheme::MidShade, -0.4);
return KColorScheme::shade(color, KColorScheme::LightShade, _contrast);
}
QColor OxygenHelper::calcDarkColor(const QColor &color)
{
return KColorScheme::shade(color, KColorScheme::MidShade, 0.7);
return KColorScheme::shade(color, KColorScheme::MidShade, _contrast);
}
QPixmap OxygenHelper::verticalGradient(const QColor &color, int height)
{
quint64 key = (quint64(color.rgba()) << 32) | height | 0x8000;
QPixmap *pixmap = m_cache.object(key);
QPixmap *pixmap = m_backgroundCache.object(key);
if (!pixmap)
{
@ -116,7 +107,7 @@ QPixmap OxygenHelper::verticalGradient(const QColor &color, int height)
p.setCompositionMode(QPainter::CompositionMode_Source);
p.fillRect(pixmap->rect(), gradient);
m_cache.insert(key, pixmap);
m_backgroundCache.insert(key, pixmap);
}
return *pixmap;
@ -125,7 +116,7 @@ QPixmap OxygenHelper::verticalGradient(const QColor &color, int height)
QPixmap OxygenHelper::radialGradient(const QColor &color, int width)
{
quint64 key = (quint64(color.rgba()) << 32) | width | 0xb000;
QPixmap *pixmap = m_cache.object(key);
QPixmap *pixmap = m_backgroundCache.object(key);
if (!pixmap)
{
@ -147,15 +138,20 @@ QPixmap OxygenHelper::radialGradient(const QColor &color, int width)
p.scale(width/128.0,1);
p.fillRect(pixmap->rect(), gradient);
m_cache.insert(key, pixmap);
m_backgroundCache.insert(key, pixmap);
}
return *pixmap;
}
QPixmap* OxygenHelper::roundButton(const QColor &color, int size)
QPixmap OxygenHelper::roundButton(const QColor &color, int size)
{
QPixmap *pixmap = new QPixmap(size, size);
quint64 key = (quint64(color.rgba()) << 32) | size;
QPixmap *pixmap = m_roundCache.object(key);
if (!pixmap)
{
pixmap = new QPixmap(size, size);
pixmap->fill(QColor(0,0,0,0));
QPainter p(pixmap);
@ -183,7 +179,7 @@ QPixmap* OxygenHelper::roundButton(const QColor &color, int size)
p.drawEllipse(QRectF(2.4,2.4,15.2,15.2));
// bevel
QLinearGradient bevelGradient(0, 0, 0, 20);
QLinearGradient bevelGradient(0, 0, 0, 18);
bevelGradient.setColorAt(0.45, calcLightColor(color));
bevelGradient.setColorAt(0.55, color);
bevelGradient.setColorAt(0.65, calcDarkColor(color));
@ -207,5 +203,8 @@ QPixmap* OxygenHelper::roundButton(const QColor &color, int size)
p.setBrush(innerGradient);
p.drawEllipse(QRectF(2.5,2.5,15.0,14.8));
return pixmap;
m_roundCache.insert(key, pixmap);
}
return *pixmap;
}

View file

@ -45,21 +45,19 @@ public:
QColor backgroundTopColor(const QColor &color) const;
QColor backgroundBottomColor(const QColor &color) const;
QColor calcLightColor(const QColor &color);
QColor calcMidlightColor(const QColor &color);
QColor calcMidColor(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);
QPixmap roundButton(const QColor &color, int size);
protected:
KComponentData _componentData;
KSharedConfigPtr _config;
qreal _contrast;
QCache<quint64, QPixmap> m_cache;
QCache<quint64, QPixmap> m_backgroundCache;
QCache<quint64, QPixmap> m_roundCache;
};