From 52d665ae37a221e81e6c7a6927d4fcf68c7bfc49 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Fri, 4 Sep 2009 04:18:52 +0000 Subject: [PATCH] removed lib to use svn external from 'kdebase/runtime/kstyles/oxygen/lib' instead, to minimize code duplication svn path=/trunk/KDE/kdebase/workspace/; revision=1019624 --- clients/nitrogen/lib/helper.cpp | 583 ------------------------------- clients/nitrogen/lib/helper.h | 117 ------- clients/nitrogen/lib/tileset.cpp | 132 ------- clients/nitrogen/lib/tileset.h | 102 ------ 4 files changed, 934 deletions(-) delete mode 100644 clients/nitrogen/lib/helper.cpp delete mode 100644 clients/nitrogen/lib/helper.h delete mode 100644 clients/nitrogen/lib/tileset.cpp delete mode 100644 clients/nitrogen/lib/tileset.h diff --git a/clients/nitrogen/lib/helper.cpp b/clients/nitrogen/lib/helper.cpp deleted file mode 100644 index 06b835adfe..0000000000 --- a/clients/nitrogen/lib/helper.cpp +++ /dev/null @@ -1,583 +0,0 @@ -/* -* Copyright 2008 Long Huynh Huu -* Copyright 2007 Matthew Woehlke -* Copyright 2007 Casper Boemann -* Copyright 2007 Fredrik Höglund -* -* 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 -#include -#include -#include -#include -#include - -#include "helper.h" - - -const double NitrogenHelper::_shadowGain = 1.5; - -//_______________________________________________________________________________________________________________ -NitrogenHelper::NitrogenHelper(const QByteArray &componentName): - _componentData(componentName, 0, KComponentData::SkipMainComponentRegistration) -{ - _config = _componentData.config(); - _contrast = KGlobalSettings::contrastF(_config); - _bgcontrast = 0.3; - - m_backgroundCache.setMaxCost(64); - m_windecoButtonCache.setMaxCost(64); - m_windecoButtonGlowCache.setMaxCost(64); - -} - -//_______________________________________________________________________________________________________________ -KSharedConfigPtr NitrogenHelper::config() const -{ return _config; } - -//_______________________________________________________________________________________________________________ -void NitrogenHelper::reloadConfig() -{ - double old_contrast = _contrast; - - _config->reparseConfiguration(); - _contrast = KGlobalSettings::contrastF(_config); - - // contrast changed, invalidate our caches - if (_contrast != old_contrast) invalidateCaches(); - -} - -//_______________________________________________________________________________________________________________ -void NitrogenHelper::renderWindowBackground( - QPainter *p, - const QRect &clipRect, - const QWidget *widget, - const QPalette & pal, - int gradient_shift ) -{ - - if (clipRect.isValid()) { - p->save(); - p->setClipRegion(clipRect,Qt::IntersectClip); - } - - QRect r = widget->window()->rect(); - - // use an additional pixmap for buffering - // to avoid flicker observe when painting large (wide) windows - QPixmap pixmap( r.size() ); - { - - QPainter p( &pixmap ); - if (clipRect.isValid()) p.setClipRegion(clipRect); - - // get coordinates relative to the client area - const QWidget* w = widget; - int x = 0; - int y = 0; - - // get window - while (!w->isWindow()) - { - x += w->geometry().x(); - y += w->geometry().y(); - w = w->window(); - } - - QColor color = pal.color( w->backgroundRole() ); - int splitY = qMin(300, 3*r.height()/4); - - QRect upperRect = QRect(-x, -y, r.width(), splitY); - QPixmap tile = verticalGradient(color, splitY); - p.drawTiledPixmap(upperRect, tile); - - QRect lowerRect = QRect(-x, splitY-y, r.width(), r.height() - splitY); - p.fillRect(lowerRect, backgroundBottomColor(color)); - int radialW = qMin(600, r.width()); - - // on first paint the frame may not have been done yet, so just fixate it - QRect radialRect = QRect((r.width() - radialW)/2 - x, -y, radialW, 64+gradient_shift); - if (clipRect.intersects(radialRect)) - { - tile = radialGradient(color, radialW, gradient_shift ); - p.drawPixmap(radialRect, tile); - } - - } - - p->drawPixmap( r, pixmap ); - if (clipRect.isValid()) p->restore(); - -} - -//_______________________________________________________________________________________________________________ -void NitrogenHelper::invalidateCaches() -{ - m_backgroundCache.clear(); - m_windecoButtonCache.clear(); - m_windecoButtonGlowCache.clear(); -} - -//_______________________________________________________________________________________________________________ -bool NitrogenHelper::lowThreshold(const QColor &color) -{ - QColor darker = KColorScheme::shade(color, KColorScheme::MidShade, 0.5); - return KColorUtils::luma(darker) > KColorUtils::luma(color); -} - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::alphaColor(QColor color, double alpha) -{ - if (alpha < 1.0) color.setAlphaF( qMax(0.0, alpha) * color.alphaF() ); - return color; -} - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::backgroundRadialColor(const QColor &color) const -{ - return lowThreshold(color) ? - KColorScheme::shade(color, KColorScheme::LightShade, 0.0): - KColorScheme::shade(color, KColorScheme::LightShade, _bgcontrast); -} - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::backgroundTopColor(const QColor &color) const -{ - return lowThreshold(color) ? - KColorScheme::shade(color, KColorScheme::MidlightShade, 0.0): - KColorScheme::shade(color, KColorScheme::MidlightShade, _bgcontrast); -} - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::backgroundBottomColor(const QColor &color) const -{ - QColor midColor = KColorScheme::shade(color, KColorScheme::MidShade, 0.0); - if (lowThreshold(color)) return midColor; - - double by = KColorUtils::luma(color), my = KColorUtils::luma(midColor); - return KColorUtils::shade(color, (my - by) * _bgcontrast); -} - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::calcLightColor(const QColor &color) const -{ return KColorScheme::shade(color, KColorScheme::LightShade, _contrast); } - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::calcDarkColor(const QColor &color) const -{ - return lowThreshold(color) ? - KColorUtils::mix(calcLightColor(color), color, 0.2 + 0.8 * _contrast): - KColorScheme::shade(color, KColorScheme::MidShade, _contrast); -} - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::calcShadowColor(const QColor &color) const -{ - return - KColorScheme::shade(KColorUtils::mix(QColor(255,255,255),color, color.alpha()*(1/255.0)), - KColorScheme::ShadowShade, _contrast); - -} - -//_______________________________________________________________________________________________________________ -QColor NitrogenHelper::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 NitrogenHelper::verticalGradient(const QColor &color, int height) -{ - quint64 key = (quint64(color.rgba()) << 32) | height | 0x8000; - QPixmap *pixmap = m_backgroundCache.object(key); - - if (!pixmap) - { - pixmap = new QPixmap(32, height); - - QLinearGradient gradient(0, 0, 0, height); - gradient.setColorAt(0.0, backgroundTopColor(color)); - gradient.setColorAt(0.5, color); - gradient.setColorAt(1.0, backgroundBottomColor(color)); - - QPainter p(pixmap); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(pixmap->rect(), gradient); - - m_backgroundCache.insert(key, pixmap); - } - - return *pixmap; -} - -//_______________________________________________________________________________________________________________ -QPixmap NitrogenHelper::radialGradient(const QColor &color, int width, int y_offset ) -{ - quint64 key = (quint64(color.rgba()) << 32) | width | 0xb000; - QPixmap *pixmap = m_backgroundCache.object(key); - - if (!pixmap) - { - pixmap = new QPixmap(width, 64+y_offset); - pixmap->fill(Qt::transparent); - QColor radialColor = backgroundRadialColor(color); - - // create gradient - QRadialGradient gradient(64, 0, 64); - radialColor.setAlpha(255); gradient.setColorAt(0, radialColor); - radialColor.setAlpha(101); gradient.setColorAt(0.5, radialColor); - radialColor.setAlpha(37); gradient.setColorAt(0.75, radialColor); - radialColor.setAlpha(0); gradient.setColorAt(1, radialColor); - - // need some tr - QPainter p(pixmap); - p.translate( 0, y_offset ); - p.scale(width/128.0,1); - p.fillRect(QRect(0,0,128,64+y_offset).translated(0, -y_offset ), gradient); - - m_backgroundCache.insert(key, pixmap); - } - - return *pixmap; -} - -//_______________________________________________________________________________________________________________ -void NitrogenHelper::drawShadow(QPainter &p, const QColor &color, int size) const -{ - double m = double(size-2)*0.5; - - const double offset = 0.8; - double k0 = (m-4.0) / m; - QRadialGradient shadowGradient(m+1.0, m+offset+1.0, m); - for (int i = 0; i < 8; i++) { // sinusoidal gradient - double k1 = (k0 * double(8 - i) + double(i)) * 0.125; - double a = (cos(3.14159 * i * 0.125) + 1.0) * 0.25; - shadowGradient.setColorAt(k1, alphaColor(color, a * _shadowGain)); - } - shadowGradient.setColorAt(1.0, alphaColor(color, 0.0)); - p.setBrush(shadowGradient); - p.drawEllipse(QRectF(0, 0, size, size)); -} - -//_______________________________________________________________________________________________________________ -QLinearGradient NitrogenHelper::decoGradient(const QRect &r, const QColor &color) -{ - - QColor light = KColorScheme::shade(color, KColorScheme::LightShade, _contrast * 0.7); - QColor dark = KColorScheme::shade(color, KColorScheme::DarkShade, _contrast * 0.7); - - double y = KColorUtils::luma(color); - double yd = KColorUtils::luma(dark); - double yl = KColorUtils::luma(light); - - QLinearGradient gradient(r.topLeft(), r.bottomLeft()); - if (yd > y) - { - gradient.setColorAt(0.2, color); - gradient.setColorAt(0.8, dark); - } - else if (yl < y) - { - gradient.setColorAt(0.2, light); - gradient.setColorAt(0.8, color); - } - else - { - gradient.setColorAt(0.2, dark); - gradient.setColorAt(0.5, color); - gradient.setColorAt(0.8, light); - } - - return gradient; -} - -//_______________________________________________________________________________________________________________ -QPixmap NitrogenHelper::windecoButton(const QColor &color, bool pressed, int size) -{ - - quint64 key = (quint64(color.rgba()) << 32) | (size << 1) | pressed; - QPixmap *pixmap = m_windecoButtonCache.object(key); - - if (!pixmap) - { - pixmap = new QPixmap(size, size); - pixmap->fill(Qt::transparent); - - QPainter p(pixmap); - p.setRenderHints(QPainter::Antialiasing); - p.setPen(Qt::NoPen); - - double u = double(size)/22.0; - QColor light = calcLightColor(color); - QColor dark = calcDarkColor(color); - QColor shadow = calcShadowColor(color); - - QRectF rect(0.0, 0.0, size, size); - QRectF buttonRect = rect.adjusted(2*u,2*u,-2*u,-2*u); - - QLinearGradient fill(QPointF(0.0, 0.0*u), QPointF(0.0, 21.0*u)); - fill.setColorAt(0.0, alphaColor(light, 0.7)); - fill.setColorAt(1.0, alphaColor(dark, 0.7)); - - p.setBrush(fill); - p.drawEllipse(buttonRect); - p.setBrush(Qt::NoBrush); - - // shadow - if (pressed) - { - p.setPen(alphaColor(dark, 0.4)); - p.drawEllipse(buttonRect.adjusted(0.9, 0.6, -0.7, -0.7).adjusted(1.7,1.7,-1.7,-1.7)); - p.setPen(alphaColor(dark, 0.8)); - p.drawEllipse(buttonRect.adjusted(0.9, 0.6, -0.7, -0.7).adjusted(1.2,1.2,-1.2,-1.2)); - } - p.setPen(QPen(KColorUtils::mix(dark, shadow, 0.12), 2.0)); - p.drawEllipse(buttonRect.adjusted(0.9, 0.6, -0.7, -0.7).adjusted(0,0.1,0,-0.1)); - p.setPen(QPen(KColorUtils::mix(dark, shadow, 0.6), 1.2)); - p.drawEllipse(buttonRect.adjusted(1.0, 1.4, -0.8, -0.8)); - - // reflection - QLinearGradient lightgr(QPointF(0.0, 0.0*u), QPointF(0.0, 21.0*u)); - lightgr.setColorAt(0.0, Qt::transparent); - lightgr.setColorAt(1.0, light); - p.setPen(QPen(lightgr, 1.7)); - p.drawEllipse(buttonRect.adjusted(0.0, -0.5, -0.1, 0.0)); - - m_windecoButtonCache.insert(key, pixmap); - - } - - return *pixmap; -} - -//_______________________________________________________________________________________________________________ -QPixmap NitrogenHelper::windecoButtonGlow(const QColor &color, int size) -{ - quint64 key = (quint64(color.rgba()) << 32) | size; - QPixmap *pixmap = m_windecoButtonGlowCache.object(key); - - if (!pixmap) - { - pixmap = new QPixmap(size, size); - pixmap->fill(Qt::transparent); - - QPainter p(pixmap); - p.setRenderHints(QPainter::Antialiasing); - p.setPen(Qt::NoPen); - - double u = size/21.0; - QRectF rect(0.0, 0.0, size, size); - QRectF buttonRect = rect.adjusted(2*u,2*u,-2*u,-2*u); - - //mask - p.setBrush(QColor(0,0,0,125)); - p.drawEllipse(rect.adjusted(u, 0, -u, -2*u)); - - //glow - QColor dark = calcDarkColor(color); - QColor light = calcLightColor(color); - - QRadialGradient glow(QPointF(size/2.0, size/2.0 + 0.25), size/2.0); - glow.setColorAt(12.0 / 21.0, Qt::transparent); - glow.setColorAt(16.0 / 21.0, dark); - glow.setColorAt(18.0 / 21.0, alphaColor(light, 0.25)); - glow.setColorAt(20.0 / 21.0, Qt::transparent); - - p.setCompositionMode(QPainter::CompositionMode_SourceIn); - p.setBrush(glow); - p.drawEllipse(rect); - - m_windecoButtonGlowCache.insert(key, pixmap); - } - - return *pixmap; - -} -//_______________________________________________________________________________________________________________ -QPixmap NitrogenHelper::glow(const QColor &color, int size, int rsize) -{ - QPixmap pixmap(rsize, rsize); - pixmap.fill(QColor(0,0,0,0)); - - QPainter p(&pixmap); - p.setRenderHints(QPainter::Antialiasing); - p.setPen(Qt::NoPen); - p.setWindow(0,0,size,size); - - QRectF r(0, 0, size, size); - double m = double(size)*0.5; - - const double width = 3.0; - const double bias = _glowBias * double(size) / double(rsize); - double k0 = (m-width+bias) / m; - QRadialGradient glowGradient(m, m, m); - - for (int i = 0; i < 8; i++) - { - - // inverse parabolic gradient - double k1 = (k0 * double(8 - i) + double(i)) * 0.125; - double a = 1.0 - sqrt(i * 0.125); - glowGradient.setColorAt(k1, alphaColor(color, a)); - - } - - glowGradient.setColorAt(1.0, alphaColor(color, 0.0)); - - // glow - p.setBrush(glowGradient); - p.drawEllipse(r); - - // mask - p.setCompositionMode(QPainter::CompositionMode_DestinationOut); - p.setBrush(QBrush(Qt::black)); - p.drawEllipse(r.adjusted(width, width, -width, -width)); - - p.end(); - - return pixmap; -} - -//_______________________________________________________________________________________________________________ -void NitrogenHelper::drawFloatFrame(QPainter *p, const QRect r, const QColor &color, bool drawUglyShadow, bool isActive, const QColor &frameColor) const -{ - p->save(); - p->setRenderHint(QPainter::Antialiasing); - QRect frame = r; - frame.adjust(1,1,-1,-1); - int x,y,w,h; - frame.getRect(&x, &y, &w, &h); - - QColor light = calcLightColor(backgroundTopColor(color)); - QColor dark = calcLightColor(backgroundBottomColor(color)); - QColor glow = KColorUtils::mix(QColor(128,128,128),frameColor,0.7); - - p->setBrush(Qt::NoBrush); - - if (drawUglyShadow) { - if(isActive) { //window active - it's a glow - not a shadow - p->setPen(glow); - p->drawLine(QPointF(x+4, y-0.5), QPointF(x+w-4, y-0.5)); - p->drawArc(QRectF(x-0.5, y-0.5, 11, 11),90*16, 90*16); - p->drawArc(QRectF(x+w-11+0.5, y-0.5, 11, 11), 0, 90*16); - p->drawLine(QPointF(x-0.5, y+4), QPointF(x-0.5, y+h-4)); - p->drawLine(QPointF(x+w+0.5, y+4), QPointF(x+w+0.5, y+h-4)); - p->drawArc(QRectF(x-0.5, y+h-11+0.5, 11, 11),180*16, 90*16); - p->drawArc(QRectF(x+w-11+0.5, y+h-11+0.5, 11, 11),270*16, 90*16); - p->drawLine(QPointF(x+4, y+h+0.5), QPointF(x+w-4, y+h+0.5)); - light = KColorUtils::mix(light, frameColor); - dark = KColorUtils::mix(dark, frameColor); - } - else { //window inactive - draw something resembling shadow - QColor shadow = KColorUtils::darken(color, 0.0, 0.0); // fully desaturate - p->setPen(KColorUtils::darken(shadow, 0.2)); - p->drawLine(QPointF(x+4, y-0.5), QPointF(x+w-4, y-0.5)); - p->drawArc(QRectF(x-0.5, y-0.5, 11, 11),90*16, 90*16); - p->drawArc(QRectF(x+w-11+0.5, y-0.5, 11, 11), 0, 90*16); - p->setPen(KColorUtils::darken(shadow, 0.35)); - p->drawLine(QPointF(x-0.5, y+4), QPointF(x-0.5, y+h-4)); - p->drawLine(QPointF(x+w+0.5, y+4), QPointF(x+w+0.5, y+h-4)); - p->setPen(KColorUtils::darken(shadow, 0.45)); - p->drawArc(QRectF(x-0.5, y+h-11+0.5, 11, 11),180*16, 90*16); - p->drawArc(QRectF(x+w-11+0.5, y+h-11+0.5, 11, 11),270*16, 90*16); - p->setPen(KColorUtils::darken(shadow, 0.6)); - p->drawLine(QPointF(x+4, y+h+0.5), QPointF(x+w-4, y+h+0.5)); - } - } - - p->setPen(QPen(light, 0.8)); - p->drawLine(QPointF(x+4, y+0.6), QPointF(x+w-4, y+0.6)); - QLinearGradient lg = QLinearGradient(0.0, 1.5, 0.0, 4.5); - lg.setColorAt(0, light); - lg.setColorAt(1, dark); - p->setPen(QPen(lg, 0.8)); - p->drawArc(QRectF(x+0.6, y+0.6, 9, 9),90*16, 90*16); - p->drawArc(QRectF(x+w-9-0.6, y+0.6, 9, 9), 0, 90*16); - p->drawLine(QPointF(x+0.6, y+4), QPointF(x+0.6, y+h-4)); - p->drawLine(QPointF(x+w-0.6, y+4), QPointF(x+w-0.6, y+h-4)); - p->restore(); -} - -//_______________________________________________________________________________________________________________ -void NitrogenHelper::drawSeparator(QPainter *p, const QRect &rect, const QColor &color, Qt::Orientation orientation) const -{ - QColor light = calcLightColor(color); - QColor dark = calcDarkColor(color); - - bool antialias = p->testRenderHint(QPainter::Antialiasing); - p->setRenderHint(QPainter::Antialiasing,false); - - QPoint start,end,offset; - - if (orientation == Qt::Horizontal) { - - start = QPoint(rect.x(),rect.y()+rect.height()/2-1); - end = QPoint(rect.right(),rect.y()+rect.height()/2-1); - offset = QPoint(0,1); - - } else { - - start = QPoint(rect.x()+rect.width()/2-1,rect.y()); - end = QPoint(rect.x()+rect.width()/2-1,rect.bottom()); - offset = QPoint(1,0); - light.setAlpha(150); - - } - - QLinearGradient lg(start,end); - lg.setColorAt(0.3, dark); - lg.setColorAt(0.7, dark); - dark.setAlpha(0); - lg.setColorAt(0.0, dark); - lg.setColorAt(1.0, dark); - p->setPen(QPen(lg,1)); - - if (orientation == Qt::Horizontal) p->drawLine(start,end); - else p->drawLine(start+offset,end+offset); - - lg = QLinearGradient(start,end); - lg.setColorAt(0.3, light); - lg.setColorAt(0.7, light); - light.setAlpha(0); - lg.setColorAt(0.0, light); - lg.setColorAt(1.0, light); - p->setPen(QPen(lg,1)); - - - if (orientation == Qt::Horizontal) p->drawLine(start+offset,end+offset); - else { - - p->drawLine(start,end); - p->drawLine(start+offset*2,end+offset*2); - - } - - p->setRenderHint(QPainter::Antialiasing, antialias); -} - diff --git a/clients/nitrogen/lib/helper.h b/clients/nitrogen/lib/helper.h deleted file mode 100644 index 9fe2208965..0000000000 --- a/clients/nitrogen/lib/helper.h +++ /dev/null @@ -1,117 +0,0 @@ -// $Id: helper.h,v 1.6 2009/05/29 14:34:07 hpereira Exp $ - -/* - * Copyright 2008 Long Huynh Huu - * Copyright 2007 Matthew Woehlke - * Copyright 2007 Casper Boemann - * Copyright 2007 Fredrik Höglund - * - * 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 __NITROGEN_HELPER_H -#define __NITROGEN_HELPER_H - -#include -#include - -#include -#include -#include -#include - - -#define _glowBias 0.9 // not likely to be configurable - -// WARNING - NitrogenHelper must be a K_GLOBAL_STATIC! -class NitrogenHelper -{ - - public: - - //! constructor - explicit NitrogenHelper(const QByteArray& ); - - //! destructor - virtual ~NitrogenHelper() {} - - //! configuration - KSharedConfigPtr config() const; - - //! reload configuration - void reloadConfig(); - - //! window backbround - void renderWindowBackground( - QPainter *p, - const QRect &clipRect, - const QWidget *widget, - const QPalette & pal, - int gradient_shift = 0 - ); - - //! clear cache - virtual void invalidateCaches(); - - //!@name color calculations - // @{ - static bool lowThreshold(const QColor &color); - static QColor alphaColor(QColor color, double alpha); - QColor calcLightColor(const QColor &color) const; - QColor calcDarkColor(const QColor &color) const; - QColor calcShadowColor(const QColor &color) const; - 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; - //@} - - //!@name gradients - //@{ - QPixmap verticalGradient(const QColor &color, int height); - QPixmap radialGradient(const QColor &color, int width, int y_offset = 0); - QLinearGradient decoGradient(const QRect &r, const QColor &color); - //@} - - //! buttons - QPixmap windecoButton(const QColor &color, bool pressed, int size = 21); - QPixmap windecoButtonGlow(const QColor &color, int size = 21); - - //! frame - void drawFloatFrame(QPainter *p, const QRect r, const QColor &color, bool drawUglyShadow=true, bool isActive=false, const QColor &frameColor=QColor()) const; - - //! separator - void drawSeparator(QPainter *p, const QRect &r, const QColor &color, Qt::Orientation orientation) const; - - protected: - - void drawShadow(QPainter&, const QColor&, int size) const; - static QPixmap glow(const QColor&, int size, int rsize); - - static const double _shadowGain; - - KComponentData _componentData; - KSharedConfigPtr _config; - qreal _contrast; - qreal _bgcontrast; - - // cache - QCache m_backgroundCache; - QCache m_windecoButtonCache; - QCache m_windecoButtonGlowCache; - -}; - -#endif // __NITROGEN_HELPER_H diff --git a/clients/nitrogen/lib/tileset.cpp b/clients/nitrogen/lib/tileset.cpp deleted file mode 100644 index c4c3d1c3c6..0000000000 --- a/clients/nitrogen/lib/tileset.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2008 Long Huynh Huu - * Copyright 2007 Matthew Woehlke - * - * 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 - -#include "tileset.h" - -void TileSet::initPixmap(int s, const QPixmap &pix, int w, int h, const QRect ®ion) -{ - if (w != region.width() || h != region.height()) { - QPixmap tile = pix.copy(region); - _pixmap[s] = QPixmap(w, h); - _pixmap[s].fill(QColor(0,0,0,0)); - QPainter p(&_pixmap[s]); - p.drawTiledPixmap(0, 0, w, h, tile); - } - else { - _pixmap[s] = pix.copy(region); - } -} - -TileSet::TileSet(const QPixmap &pix, int w1, int h1, int w2, int h2) - : _w1(w1), _h1(h1) -{ - if (pix.isNull()) - return; - - _w3 = pix.width() - (w1 + w2); - _h3 = pix.height() - (h1 + h2); - int w = w2; while (w < 32 && w2 > 0) w += w2; - int h = h2; while (h < 32 && h2 > 0) h += h2; - - initPixmap(0, pix, _w1, _h1, QRect(0, 0, _w1, _h1)); - initPixmap(1, pix, w, _h1, QRect(_w1, 0, w2, _h1)); - initPixmap(2, pix, _w3, _h1, QRect(_w1+w2, 0, _w3, _h1)); - initPixmap(3, pix, _w1, h, QRect(0, _h1, _w1, h2)); - initPixmap(4, pix, w, h, QRect(_w1, _h1, w2, h2)); - initPixmap(5, pix, _w3, h, QRect(_w1+w2, _h1, _w3, h2)); - initPixmap(6, pix, _w1, _h3, QRect(0, _h1+h2, _w1, _h3)); - initPixmap(7, pix, w, _h3, QRect(_w1, _h1+h2, w2, _h3)); - initPixmap(8, pix, _w3, _h3, QRect(_w1+w2, _h1+h2, _w3, _h3)); -} - -TileSet::TileSet(const QPixmap &pix, int w1, int h1, int w3, int h3, int x1, int y1, int w2, int h2) - : _w1(w1), _h1(h1), _w3(w3), _h3(h3) -{ - if (pix.isNull()) - return; - - int x2 = pix.width() - _w3; - int y2 = pix.height() - _h3; - int w = w2; while (w < 32 && w2 > 0) w += w2; - int h = h2; while (h < 32 && h2 > 0) h += h2; - - initPixmap(0, pix, _w1, _h1, QRect(0, 0, _w1, _h1)); - initPixmap(1, pix, w, _h1, QRect(x1, 0, w2, _h1)); - initPixmap(2, pix, _w3, _h1, QRect(x2, 0, _w3, _h1)); - initPixmap(3, pix, _w1, h, QRect(0, y1, _w1, h2)); - initPixmap(4, pix, w, h, QRect(x1, y1, w2, h2)); - initPixmap(5, pix, _w3, h, QRect(x2, y1, _w3, h2)); - initPixmap(6, pix, _w1, _h3, QRect(0, y2, _w1, _h3)); - initPixmap(7, pix, w, _h3, QRect(x1, y2, w2, _h3)); - initPixmap(8, pix, _w3, _h3, QRect(x2, y2, _w3, _h3)); -} - -TileSet::TileSet(const TileSet &other) - : _w1(other._w1), _h1(other._h1), _w3(other._w3), _h3(other._h3) -{ - for (int i=0; i<9; i++) { - _pixmap[i] = other._pixmap[i]; - } -} - -TileSet& TileSet::operator=(const TileSet &other) -{ - _w1 = other._w1; - _w3 = other._w3; - _h1 = other._h1; - _h3 = other._h3; - for (int i=0; i<9; i++) { - _pixmap[i] = other._pixmap[i]; - } - return *this; -} - -inline bool bits(TileSet::Tiles flags, TileSet::Tiles testFlags) -{ - return (flags & testFlags) == testFlags; -} - -void TileSet::render(const QRect &r, QPainter *p, Tiles t) const -{ - if (_pixmap[0].isNull()) - return; - - int x0, y0, w, h; - r.getRect(&x0, &y0, &w, &h); - w -= _w1 + _w3; - h -= _h1 + _h3; - int x1 = x0 + _w1; - int x2 = x1 + w; - int y1 = y0 + _h1; - int y2 = y1 + h; - - if (bits(t, Top|Left)) p->drawPixmap(x0, y0, _pixmap[0]); - if (bits(t, Top|Right)) p->drawPixmap(x2, y0, _pixmap[2]); - if (bits(t, Bottom|Left)) p->drawPixmap(x0, y2, _pixmap[6]); - if (bits(t, Bottom|Right)) p->drawPixmap(x2, y2, _pixmap[8]); - - if (t & Top) p->drawTiledPixmap(x1, y0, w, _h1, _pixmap[1]); - if (t & Bottom) p->drawTiledPixmap(x1, y2, w, _h3, _pixmap[7]); - if (t & Left) p->drawTiledPixmap(x0, y1, _w1, h, _pixmap[3]); - if (t & Right) p->drawTiledPixmap(x2, y1, _w3, h, _pixmap[5]); - - if (t & Center) p->drawTiledPixmap(x1, y1, w, h, _pixmap[4]); -} diff --git a/clients/nitrogen/lib/tileset.h b/clients/nitrogen/lib/tileset.h deleted file mode 100644 index 6f9fb3335a..0000000000 --- a/clients/nitrogen/lib/tileset.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2007 Matthew Woehlke - * - * 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 TILESET_H -#define TILESET_H - -#include -#include - -class TileSet -{ -public: - /** - * Create a TileSet from a pixmap. The size of the bottom/right chunks is - * whatever is left over from the other chunks, whose size is specified - * in the required parameters. - * - * @param w1 width of the left chunks - * @param h1 height of the top chunks - * @param w2 width of the not-left-or-right chunks - * @param h2 height of the not-top-or-bottom chunks - */ - TileSet(const QPixmap&, int w1, int h1, int w2, int h2); - - /** - * Create a TileSet from a pixmap. The size of the top/left and bottom/right - * chunks is specified, with the middle chunks created from the specified - * portion of the pixmap. This allows the middle chunks to overlap the outer - * chunks (or to not use all pixels). The top/left and bottom/right chunks - * are carved out of the corners of the pixmap. - * - * @param w1 width of the left chunks - * @param h1 height of the top chunks - * @param w3 width of the right chunks - * @param h3 height of bottom chunks - * @param x2 x-coordinate of the top of the not-left-or-right chunks - * @param y2 y-coordinate of the left of the not-top-or-bottom chunks - * @param w2 width of the not-left-or-right chunks - * @param h2 height of the not-top-or-bottom chunks - */ - TileSet(const QPixmap &pix, int w1, int h1, int w3, int h3, int x2, int y2, int w2, int h2); - - TileSet() : _empty(true) {} - TileSet(const TileSet&); - - virtual ~TileSet() {} - - TileSet& operator=(const TileSet&); - - /** - * Flags specifying what sides to draw in ::render. Corners are drawn when - * the sides forming that corner are drawn, e.g. Top|Left draws the - * top-center, center-left, and top-left chunks. The center-center chunk is - * only drawn when Center is requested. - */ - enum Tile { - Top = 0x1, - Left = 0x2, - Right = 0x8, - Bottom = 0x4, - Center = 0x10, - Ring = 0x0f, - Horizontal = 0x1a, - Vertical = 0x15, - Full = 0x1f - }; - Q_DECLARE_FLAGS(Tiles, Tile) - - /** - * Fills the specified rect with tiled chunks. Corners are never tiled, - * edges are tiled in one direction, and the center chunk is tiled in both - * directions. Partial tiles are used as needed so that the entire rect is - * perfectly filled. Filling is performed as if all chunks are being drawn. - */ - void render(const QRect&, QPainter*, Tiles = Ring) const; - -protected: - void initPixmap(int s, const QPixmap&, int w, int h, const QRect ®ion); - - bool _empty; - QPixmap _pixmap[9]; - int _w1, _h1, _w3, _h3; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(TileSet::Tiles) - -#endif //TILESET_H