diff --git a/clients/oxygen/oxygenbutton.cpp b/clients/oxygen/oxygenbutton.cpp index ec409344e8..402acaeee4 100644 --- a/clients/oxygen/oxygenbutton.cpp +++ b/clients/oxygen/oxygenbutton.cpp @@ -31,6 +31,7 @@ #include #include +#include #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; } diff --git a/clients/oxygen/oxygenbutton.h b/clients/oxygen/oxygenbutton.h index 2c22591334..4bdf94a780 100644 --- a/clients/oxygen/oxygenbutton.h +++ b/clients/oxygen/oxygenbutton.h @@ -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 diff --git a/clients/oxygen/oxygenclient.cpp b/clients/oxygen/oxygenclient.cpp index 75274b5678..3304bcc8b3 100644 --- a/clients/oxygen/oxygenclient.cpp +++ b/clients/oxygen/oxygenclient.cpp @@ -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_; } } diff --git a/clients/oxygen/oxygenclient.h b/clients/oxygen/oxygenclient.h index 7d8e79a2a9..2c7feeb555 100644 --- a/clients/oxygen/oxygenclient.h +++ b/clients/oxygen/oxygenclient.h @@ -57,6 +57,8 @@ private: void paintEvent(QPaintEvent *e); void doShape(); QColor titlebarTextColor(const QPalette &palette); + bool colorCacheInvalid_; + QColor cachedTitlebarTextColor_; protected: friend class OxygenButton;