From 3527a11af07425e3d6a3b273dcfd059e3f9cecdf Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Sun, 28 May 2017 16:16:51 +0200 Subject: [PATCH] Add identification of BG color to improve contrast in selector --- src/Qt-Color-Widgets/src/color_wheel.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Qt-Color-Widgets/src/color_wheel.cpp b/src/Qt-Color-Widgets/src/color_wheel.cpp index 981e83c3..7d330c10 100644 --- a/src/Qt-Color-Widgets/src/color_wheel.cpp +++ b/src/Qt-Color-Widgets/src/color_wheel.cpp @@ -49,6 +49,7 @@ private: public: qreal hue, sat, val; + bool backgroundIsDark; unsigned int wheel_width; MouseStatus mouse_status; QPixmap hue_ring; @@ -63,7 +64,10 @@ public: wheel_width(20), mouse_status(Nothing), display_flags(FLAGS_DEFAULT), color_from(&QColor::fromHsvF), rainbow_from_hue(&detail::rainbow_hsv) - { } + { + qreal backgroundValue = widget->palette().background().color().valueF(); + backgroundIsDark = backgroundValue < 0.5; + } /// Calculate outer wheel radius from idget center qreal outer_radius() const @@ -351,10 +355,17 @@ void ColorWheel::paintEvent(QPaintEvent * ) painter.setClipping(false); // lum-sat selector - // isWhite defines when the selector is white based on values of saturation - // and color value combined as a union - bool isWhite = (p->val < 0.65 || p->sat > 0.43); - painter.setPen(QPen(isWhite ? Qt::white : Qt::black, 3)); + // we define the color of the selecto based on the background color of the widget + // in order to improve to contrast + if (p->backgroundIsDark) + { + bool isWhite = (p->val < 0.65 || p->sat > 0.43); + painter.setPen(QPen(isWhite ? Qt::white : Qt::black, 3)); + } + else + { + painter.setPen(QPen(p->val > 0.5 ? Qt::black : Qt::white, 3)); + } painter.setBrush(Qt::NoBrush); painter.drawEllipse(selector_position, selector_radius, selector_radius);