Index: src/kmessagewidget.cpp =================================================================== --- src/kmessagewidget.cpp +++ src/kmessagewidget.cpp @@ -32,6 +32,9 @@ #include #include +#include +#include + //--------------------------------------------------------------------- // KMessageWidgetPrivate //--------------------------------------------------------------------- @@ -254,32 +257,65 @@ return d->messageType; } +static QColor qColorFromSettings(const QSettings *settings, const QString &key, QColor value = QColor()) +{ + if (settings && settings->contains(key)) { + QStringList rgb = settings->value(key).toStringList(); + if (rgb.size() == 3) { + value.setRgb(rgb.at(0).toInt(), rgb.at(1).toInt(), rgb.at(2).toInt()); + } else if (rgb.size() >= 3) { + value.setRgb(rgb.at(0).toInt(), rgb.at(1).toInt(), rgb.at(2).toInt(), rgb.at(3).toInt()); + } + } + return value; +} + void KMessageWidget::setMessageType(KMessageWidget::MessageType type) { d->messageType = type; QColor bgBaseColor; - - // We have to hardcode 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 + const QPalette palette = QGuiApplication::palette(); + qreal bgBaseColorAlpha = 0.2; + + // We cannot use KColorScheme here because KWidgetsAddons is a tier 1 framework + // and therefore can't depend on any other KDE Frameworks. We thus try to get + // the colours that interest us directly from the global settings store using QSettings. + // It that fails we use hardcoded colours, or the highlight colour (for Information). + // The hardcoded RGB color values come from the "default" scheme in kcolorscheme.cpp + const QString kdeGlobals = QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("kdeglobals")); + const QString themeGroup = QStringLiteral("Colors:Window"); + QSettings *settings = !kdeGlobals.isEmpty() ? new QSettings(kdeGlobals, QSettings::IniFormat) : nullptr; + if (settings && settings->childGroups().contains(themeGroup)) { + settings->beginGroup(themeGroup); + } else { + delete settings; + settings = nullptr; + } switch (type) { case Positive: - bgBaseColor.setRgb(39, 174, 96); // Window: ForegroundPositive + bgBaseColor = qColorFromSettings(settings, QStringLiteral("ForegroundPositive"), QColor(39, 174, 96)); break; - case Information: - bgBaseColor.setRgb(61, 174, 233); // Window: ForegroundActive + case Information: { + bgBaseColor = qColorFromSettings(settings, QStringLiteral("ForegroundActive"), palette.highlight().color()); + // the alpha component is based on the perceived brightness (CIE-XYZ 1931) of the background colour + qreal bgIntensity = 0.299 * bgBaseColor.redF() + 0.586 * bgBaseColor.greenF() + 0.115 * bgBaseColor.blueF(); + bgBaseColorAlpha = 0.5 * bgIntensity; break; + } case Warning: - bgBaseColor.setRgb(246, 116, 0); // Window: ForegroundNeutral + bgBaseColor = qColorFromSettings(settings, QStringLiteral("ForegroundNeutral"), QColor(246, 116, 0)); break; case Error: - bgBaseColor.setRgb(218, 68, 83); // Window: ForegroundNegative + bgBaseColor = qColorFromSettings(settings, QStringLiteral("ForegroundNegative"), QColor(218, 68, 83)); break; } - const qreal bgBaseColorAlpha = 0.2; + if (settings) { + settings->endGroup(); + delete settings; + } + bgBaseColor.setAlphaF(bgBaseColorAlpha); - const QPalette palette = QGuiApplication::palette(); const QColor windowColor = palette.window().color(); const QColor textColor = palette.text().color(); const QColor border = bgBaseColor;