Index: src/kmessagewidget.cpp =================================================================== --- src/kmessagewidget.cpp +++ src/kmessagewidget.cpp @@ -258,29 +258,40 @@ { d->messageType = type; QColor bgBaseColor; + const QPalette palette = QGuiApplication::palette(); + qreal bgBaseColorAlpha = 0.2; + // the message background colour takes the widget background colour + // into consideration and thus should use the actual receiving widget + // for best results. + const QColor windowColor = KMessageWidget::palette().window().color(); - // We have to hardcode colors here because KWidgetsAddons is a tier 1 framework + // We have to hardcode some colors here because KWidgetsAddons is a tier 1 framework // and therefore can't depend on any other KDE Frameworks - // The following RGB color values come from the "default" scheme in kcolorscheme.cpp + // The hardcoded RGB color values come from the "default" scheme in kcolorscheme.cpp switch (type) { case Positive: - bgBaseColor.setRgb(39, 174, 96); // Window: ForegroundPositive + bgBaseColor = palette.highlight().color(); + bgBaseColorAlpha = 0.4; break; - case Information: - bgBaseColor.setRgb(61, 174, 233); // Window: ForegroundActive + case Information: { + bgBaseColor = palette.toolTipBase().color(); + // the alpha component is based on the perceived brightness (CIE-XYZ 1931) of the background colour + // and its difference with receiving widget's background intensity: half the average of those values, + // constrained by the background intensity itself. + qreal bgIntensity = 0.299 * bgBaseColor.redF() + 0.586 * bgBaseColor.greenF() + 0.115 * bgBaseColor.blueF(); + qreal windowIntensity = 0.299 * windowColor.redF() + 0.586 * windowColor.greenF() + 0.115 * windowColor.blueF(); + bgBaseColorAlpha = 0.5 * qMax((bgIntensity + (1 - windowIntensity)), bgIntensity); break; + } case Warning: bgBaseColor.setRgb(246, 116, 0); // Window: ForegroundNeutral break; case Error: bgBaseColor.setRgb(218, 68, 83); // Window: ForegroundNegative break; } - const qreal bgBaseColorAlpha = 0.2; bgBaseColor.setAlphaF(bgBaseColorAlpha); - const QPalette palette = QGuiApplication::palette(); - const QColor windowColor = palette.window().color(); const QColor textColor = palette.text().color(); const QColor border = bgBaseColor;