Paint buttons of inactive windows different too

Prepare for caching of those colors - doesn't connect to actual KGS
signal yet - so are never invalidated


svn path=/trunk/KDE/kdebase/workspace/; revision=726729
This commit is contained in:
Casper Boemann 2007-10-18 19:09:41 +00:00
parent 1bd2d4c10f
commit a454357d4e
4 changed files with 47 additions and 8 deletions

View file

@ -31,6 +31,7 @@
#include <kdecoration.h>
#include <kglobal.h>
#include <KColorUtils>
#include "oxygenclient.h"
#include "oxygenbutton.h"
@ -61,6 +62,7 @@ OxygenButton::OxygenButton(OxygenClient &parent,
, helper_(parent.helper_)
, type_(type)
, lastmouse_(0)
, colorCacheInvalid_(true)
{
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent, false);
@ -73,6 +75,28 @@ OxygenButton::~OxygenButton()
{
}
//declare function from oxygenclient.cpp
QColor reduceContrast(const QColor &c0, const QColor &c1, double t);
QColor OxygenButton::buttonDetailColor(const QPalette &palette)
{
if (client_.isActive())
return palette.color(QPalette::Active, QPalette::ButtonText);
else {
if (colorCacheInvalid_) {
QColor ab = palette.color(QPalette::Active, QPalette::Button);
QColor af = palette.color(QPalette::Active, QPalette::ButtonText);
QColor nb = palette.color(QPalette::Inactive, QPalette::Button);
QColor nf = palette.color(QPalette::Inactive, QPalette::ButtonText);
colorCacheInvalid_ = false;
cachedButtonDetailColor_ = reduceContrast(nb, nf, qMax(2.5, KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4))));
}
return cachedButtonDetailColor_;
}
}
//////////////////////////////////////////////////////////////////////////////
// sizeHint()
// ----------
@ -150,7 +174,7 @@ void OxygenButton::paintEvent(QPaintEvent *)
painter.setRenderHints(QPainter::Antialiasing);
painter.setBrush(Qt::NoBrush);
QLinearGradient lg = helper_.decoGradient(QRect(4,4,13,13), pal.color(QPalette::ButtonText));
QLinearGradient lg = helper_.decoGradient(QRect(4,4,13,13), buttonDetailColor(pal));
painter.setPen(QPen(lg, 2.2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
switch(type_)
{
@ -179,8 +203,9 @@ void OxygenButton::paintEvent(QPaintEvent *)
case OxygenClient::MaximizeFull:
{
painter.translate(1.5, 1.5);
painter.setBrush(lg);
//painter.setBrush(lg);
QPoint points[4] = {QPoint(9, 6), QPoint(12, 9), QPoint(9, 12), QPoint(6, 9)};
//QPoint points[4] = {QPoint(9, 5), QPoint(13, 9), QPoint(9, 13), QPoint(5, 9)};
painter.drawPolygon(points, 4);
break;
}

View file

@ -59,6 +59,7 @@ private:
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
void paintEvent(QPaintEvent *e);
QColor buttonDetailColor(const QPalette &palette);
private Q_SLOTS:
void pressSlot();
@ -69,6 +70,8 @@ private:
ButtonType type_;
ButtonState status_;
int lastmouse_;
bool colorCacheInvalid_;
QColor cachedButtonDetailColor_;
};
} //namespace Oxygen

View file

@ -67,7 +67,11 @@ void renderDot(QPainter *p, const QPointF &point, qreal diameter)
OxygenClient::OxygenClient(KDecorationBridge *b, KDecorationFactory *f)
: KCommonDecoration(b, f), helper_(*globalHelper) { ; }
: KCommonDecoration(b, f)
, helper_(*globalHelper)
, colorCacheInvalid_(true)
{
}
OxygenClient::~OxygenClient()
{
@ -236,11 +240,16 @@ QColor OxygenClient::titlebarTextColor(const QPalette &palette)
if (isActive())
return palette.color(QPalette::Active, QPalette::WindowText);
else {
QColor ab = palette.color(QPalette::Active, QPalette::Window);
QColor af = palette.color(QPalette::Active, QPalette::WindowText);
QColor nb = palette.color(QPalette::Inactive, QPalette::Window);
QColor nf = palette.color(QPalette::Inactive, QPalette::WindowText);
return reduceContrast(nb, nf, qMax(2.5, KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4))));
if(colorCacheInvalid_) {
QColor ab = palette.color(QPalette::Active, QPalette::Window);
QColor af = palette.color(QPalette::Active, QPalette::WindowText);
QColor nb = palette.color(QPalette::Inactive, QPalette::Window);
QColor nf = palette.color(QPalette::Inactive, QPalette::WindowText);
colorCacheInvalid_ = false;
cachedTitlebarTextColor_ = reduceContrast(nb, nf, qMax(2.5, KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4))));
}
return cachedTitlebarTextColor_;
}
}

View file

@ -57,6 +57,8 @@ private:
void paintEvent(QPaintEvent *e);
void doShape();
QColor titlebarTextColor(const QPalette &palette);
bool colorCacheInvalid_;
QColor cachedTitlebarTextColor_;
protected:
friend class OxygenButton;