colour hsl_colour::to_rgb(double aAlpha) const { double c = (1.0 - std::abs(2.0 * lightness() - 1.0)) * saturation(); double h2 = hue() / 60.0; double x = c * (1.0 - std::abs(std::fmod(h2, 2.0) - 1.0)); double r, g, b; if (hue() == undefined_hue()) r = g = b = 0.0; else if (h2 >= 0.0 && h2 < 1.0) r = c, g = x, b = 0.0; else if (h2 >= 1.0 && h2 < 2.0) r = x, g = c, b = 0.0; else if (h2 >= 2.0 && h2 < 3.0) r = 0.0, g = c, b = x; else if (h2 >= 3.0 && h2 < 4.0) r = 0.0, g = x, b = c; else if (h2 >= 4.0 && h2 < 5.0) r = x, g = 0.0, b = c; else if (h2 >= 5.0 && h2 < 6.0) r = c, g = 0.0, b = x; else r = g = b = 0.0; double m = lightness() - 0.5f * c; colour result( static_cast<colour::component>(std::floor((r + m) * 255.0)), static_cast<colour::component>(std::floor((g + m) * 255.0)), static_cast<colour::component>(std::floor((b + m) * 255.0)), static_cast<colour::component>(std::floor(aAlpha * 255.0))); return result; }
void ItemPinned::paintEvent(QPaintEvent *paintEvent) { const auto *parent = parentWidget(); auto color = parent->palette().color(QPalette::Background); const int lightThreshold = 100; const bool menuBackgrounIsLight = color.lightness() > lightThreshold; color.setHsl( color.hue(), color.saturation(), qMax(0, qMin(255, color.lightness() + (menuBackgrounIsLight ? -200 : 50))) ); QPainter painter(this); const int border = pointsToPixels(6); const QRect rect(width() - border, 0, width(), height()); painter.setOpacity(0.15); painter.fillRect(rect, color); QWidget::paintEvent(paintEvent); }