Migrate plastikbutton.cpp to KColorUtils/KColorScheme way of handling colors, thereby removing last user of misc.cpp. Remove now-unused misc.{cpp,h}.

svn path=/trunk/KDE/kdebase/workspace/; revision=753965
This commit is contained in:
Matthew Woehlke 2007-12-28 20:42:45 +00:00
parent 560d0809e8
commit 8c93a0b698
6 changed files with 35 additions and 147 deletions

View file

@ -3,11 +3,11 @@ add_subdirectory( config )
########### next target ###############
set(kwin3_plastik_PART_SRCS
plastik.cpp
plastikclient.cpp
plastikbutton.cpp
misc.cpp )
set(kwin3_plastik_PART_SRCS
plastik.cpp
plastikclient.cpp
plastikbutton.cpp
)
kde4_add_plugin(kwin3_plastik ${kwin3_plastik_PART_SRCS})

View file

@ -1,81 +0,0 @@
/* Plastik KWin window decoration
Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
based on the window decoration "Web":
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <QColor>
#include <QImage>
#include <QPainter>
#include "misc.h"
QColor hsvRelative(const QColor& baseColor, int relativeH, int relativeS, int relativeV)
{
int h, s, v;
baseColor.getHsv(&h, &s, &v);
h += relativeH;
s += relativeS;
v += relativeV;
if(h < 0) { h = 0; }
else if(h > 359) { h = 359; }
if(s < 0) { s = 0; }
else if(s > 255) { s = 255; }
if(v < 0) { v = 0; }
else if(v > 255) { v = 255; }
QColor c;
c.setHsv( h, s, v );
return c;
}
QColor alphaBlendColors(const QColor &bgColor, const QColor &fgColor, const int a)
{
// normal button...
QRgb rgb = bgColor.rgb();
QRgb rgb_b = fgColor.rgb();
int alpha = a;
if(alpha>255) alpha = 255;
if(alpha<0) alpha = 0;
int inv_alpha = 255 - alpha;
QColor result = QColor( qRgb(qRed(rgb_b)*inv_alpha/255 + qRed(rgb)*alpha/255,
qGreen(rgb_b)*inv_alpha/255 + qGreen(rgb)*alpha/255,
qBlue(rgb_b)*inv_alpha/255 + qBlue(rgb)*alpha/255) );
return result;
}
QImage recolorImage(QImage *img, QColor color) {
QImage destImg(img->width(),img->height(), QImage::Format_ARGB32);
for (int x = 0; x < img->width(); x++) {
for (int y = 0; y < img->height(); y++) {
if(img->pixel(x,y) == qRgb(0,0,255) ) {
destImg.setPixel(x,y,color.rgb() ); // set to the new color
} else {
destImg.setPixel(x,y,qRgba(0,0,0,0) ); // set transparent...
}
}
}
return destImg;
}

View file

@ -1,30 +0,0 @@
/* Plastik KWin window decoration
Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
based on the window decoration "Web":
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef MISC_H
#define MISC_H
QColor hsvRelative(const QColor& baseColor, int relativeH, int relativeS = 0, int relativeV = 0);
QColor alphaBlendColors(const QColor &backgroundColor, const QColor &foregroundColor, const int alpha);
QImage recolorImage(QImage *img, QColor color);
#endif // MISC_H

View file

@ -25,7 +25,6 @@
#include <QImage>
#include <QPixmap>
#include "misc.h"
#include "plastik.h"
#include "plastik.moc"
#include "plastikclient.h"

View file

@ -33,9 +33,10 @@
#include "plastikbutton.moc"
#include "plastikclient.h"
#include "misc.h"
#include <KGlobalSettings>
#include <KColorScheme>
#include <KColorUtils>
namespace KWinPlastik
{
@ -176,34 +177,34 @@ void PlastikButton::drawButton(QPainter *painter)
bool active = m_client->isActive();
QPixmap tempPixmap;
QColor highlightColor;
if(type() == CloseButton) {
highlightColor = QColor(255,64,0);
} else {
highlightColor = Qt::white;
double c = KGlobalSettings::contrastF();
QColor titleBar = KDecoration::options()->color(KDecoration::ColorTitleBar, active);
QColor contourTop = KColorScheme::shade(titleBar, KColorScheme::DarkShade, c - 0.4);
QColor contourBottom = KColorScheme::shade(titleBar, KColorScheme::MidShade, c);
QColor surfaceTop = KColorScheme::shade(titleBar, KColorScheme::MidlightShade, c - 0.4);
QColor surfaceBottom = KColorScheme::shade(titleBar, KColorScheme::LightShade, c - 0.4);
QColor highlightColor = titleBar;
double alpha;
if (type() == CloseButton) {
KColorScheme kcs(active ? QPalette::Active : QPalette::Inactive, KColorScheme::Button);
highlightColor = kcs.foreground(KColorScheme::NegativeText).color();
}
if (isDown()) {
highlightColor = KColorScheme::shade(highlightColor, KColorScheme::ShadowShade);
alpha = 0.3;
}
else if (animProgress > 0) {
alpha = 0.6 * (double)animProgress / (double)ANIMATIONSTEPS;
highlightColor = KColorScheme::shade(highlightColor, KColorScheme::LightShade, qMin(1.0, c + 0.4));
}
QColor contourTop = alphaBlendColors(Handler()->getColor(TitleGradient2, active),
Qt::black, 215);
QColor contourBottom = alphaBlendColors(Handler()->getColor(TitleGradient3, active),
Qt::black, 215);
QColor sourfaceTop = alphaBlendColors(Handler()->getColor(TitleGradient2, active),
Qt::white, 210);
QColor sourfaceBottom = alphaBlendColors(Handler()->getColor(TitleGradient3, active),
Qt::white, 210);
int highlightAlpha = static_cast<int>(255-((60/static_cast<double>(ANIMATIONSTEPS))*
static_cast<double>(animProgress) ) );
contourTop = alphaBlendColors(contourTop, highlightColor, highlightAlpha );
contourBottom = alphaBlendColors(contourBottom, highlightColor, highlightAlpha);
sourfaceTop = alphaBlendColors(sourfaceTop, highlightColor, highlightAlpha);
sourfaceBottom = alphaBlendColors(sourfaceBottom, highlightColor, highlightAlpha);
if (isDown() ) {
contourTop = alphaBlendColors(contourTop, Qt::black, 200);
contourBottom = alphaBlendColors(contourBottom, Qt::black, 200);
sourfaceTop = alphaBlendColors(sourfaceTop, Qt::black, 200);
sourfaceBottom = alphaBlendColors(sourfaceBottom, Qt::black, 200);
if (alpha > 0.0) {
contourTop = KColorUtils::mix(contourTop, highlightColor, alpha);
contourBottom = KColorUtils::mix(contourBottom, highlightColor, alpha);
surfaceTop = KColorUtils::mix(surfaceTop, highlightColor, alpha);
surfaceBottom = KColorUtils::mix(surfaceBottom, highlightColor, alpha);
}
QPixmap buffer(width(), height());
@ -225,8 +226,8 @@ void PlastikButton::drawButton(QPainter *painter)
bP.drawRoundRect(r, rx, ry);
// surface
QLinearGradient surfaceGradient(0, 0, 0, r.height());
surfaceGradient.setColorAt(0.0, sourfaceTop);
surfaceGradient.setColorAt(1.0, sourfaceBottom);
surfaceGradient.setColorAt(0.0, surfaceTop);
surfaceGradient.setColorAt(1.0, surfaceBottom);
bP.setBrush(surfaceGradient);
bP.drawRoundRect(r.adjusted(1,1,-1,-1), rx, ry);
}

View file

@ -34,7 +34,6 @@
#include "plastikclient.h"
#include "plastikbutton.h"
#include "misc.h"
#include <KColorScheme>