diff --git a/desktoptheme/air/metadata.desktop b/desktoptheme/air/metadata.desktop index 1e195a031..e16fadbec 100644 --- a/desktoptheme/air/metadata.desktop +++ b/desktoptheme/air/metadata.desktop @@ -55,3 +55,9 @@ defaultWallpaperTheme=Elarun defaultFileSuffix=.png defaultWidth=2560 defaultHeight=1600 + +[ContrastEffect] +enabled=true +contrast=0.3 +intensity=1.9 +saturation=1.7 diff --git a/examples/applets/notes/contents/ui/main.qml b/examples/applets/notes/contents/ui/main.qml index b74e15203..a3bdb9879 100644 --- a/examples/applets/notes/contents/ui/main.qml +++ b/examples/applets/notes/contents/ui/main.qml @@ -17,7 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.0 +import QtQuick 2.1 +import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents @@ -25,7 +26,7 @@ import org.kde.plasma.components 2.0 as PlasmaComponents PlasmaCore.SvgItem { Layout.minimumWidth: 150 Layout.minimumHeight: 150 - svg: PlasmaCore.Svg("widgets/notes") + svg: PlasmaCore.Svg { imagePath: "widgets/notes" } elementId: "yellow-notes" Connections { @@ -40,6 +41,7 @@ PlasmaCore.SvgItem { PlasmaComponents.TextArea { id: noteText anchors.fill: parent + anchors.margins: 20 text: plasmoid.configuration.Text onTextChanged: plasmoid.configuration.Text = text } diff --git a/src/declarativeimports/core/dialog.cpp b/src/declarativeimports/core/dialog.cpp index db3c67e8c..84da3d733 100644 --- a/src/declarativeimports/core/dialog.cpp +++ b/src/declarativeimports/core/dialog.cpp @@ -83,6 +83,9 @@ DialogProxy::DialogProxy(QQuickItem *parent) //Create the FrameSvg background. m_frameSvgItem = new Plasma::FrameSvgItem(contentItem()); m_frameSvgItem->setImagePath("dialogs/background"); + + connect(&m_theme, &Plasma::Theme::themeChanged, this, &DialogProxy::updateContrast); + //m_frameSvgItem->setImagePath("widgets/background"); // larger borders, for testing those } @@ -412,12 +415,9 @@ void DialogProxy::syncMainItemToSize() m_frameSvgItem->setY(0); m_frameSvgItem->setWidth(width()); m_frameSvgItem->setHeight(height()); + KWindowEffects::enableBlurBehind(winId(), true, m_frameSvgItem->frameSvg()->mask()); - if (qGray(m_theme.color(Plasma::Theme::BackgroundColor).rgb()) > 127) { - KWindowEffects::enableBackgroundContrast(winId(), true, 0.30, 1.9, 1.7, m_frameSvgItem->frameSvg()->mask()); - } else { - KWindowEffects::enableBackgroundContrast(winId(), true, 0.45, 0.45, 1.7, m_frameSvgItem->frameSvg()->mask()); - } + updateContrast(); if (m_mainItem) { m_mainItem.data()->setX(m_frameSvgItem->margins()->left()); @@ -465,6 +465,15 @@ void DialogProxy::requestSyncToMainItemSize(bool delayed) } } +void DialogProxy::updateContrast() +{ + KWindowEffects::enableBackgroundContrast(winId(), m_theme.backgroundContrastEnabled(), + m_theme.backgroundContrast(), + m_theme.backgroundIntensity(), + m_theme.backgroundSaturation(), + m_frameSvgItem->frameSvg()->mask()); +} + void DialogProxy::setType(WindowType type) { if (type == m_type) { diff --git a/src/declarativeimports/core/dialog.h b/src/declarativeimports/core/dialog.h index a4cd427f9..a922ed4f6 100644 --- a/src/declarativeimports/core/dialog.h +++ b/src/declarativeimports/core/dialog.h @@ -174,7 +174,7 @@ protected: private Q_SLOTS: void syncBorders(); - + void updateContrast(); void updateVisibility(bool visible); void updateMinimumWidth(); diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp index 66dc8f64e..9b8b7df2a 100644 --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -64,7 +64,8 @@ ThemePrivate::ThemePrivate(QObject *parent) blurActive(false), isDefault(true), useGlobal(true), - hasWallpapers(false) + hasWallpapers(false), + backgroundContrastEnabled(true) { ThemeConfig config; cacheTheme = config.cacheTheme(); @@ -521,6 +522,35 @@ void ThemePrivate::processWallpaperSettings(KConfigBase *metadata) defaultWallpaperHeight = cg.readEntry("defaultHeight", DEFAULT_WALLPAPER_HEIGHT); } +void ThemePrivate::processContrastSettings(KConfigBase* metadata) +{ + KConfigGroup cg; + if (metadata->hasGroup("ContrastEffect")) { + cg = KConfigGroup(metadata, "ContrastEffect"); + backgroundContrastEnabled = cg.readEntry("enabled", false); + + //if (backgroundContrastEnabled) { + // Make up sensible default values, based on the background color + // This works for a light theme -- lighting up the background + qreal _contrast = 0.3; + qreal _intensity = 1.9; + qreal _saturation = 1.7; + + // If we're using a dark background color, darken the background + if (qGray(color(Plasma::Theme::BackgroundColor).rgb()) < 127) { + _contrast = 0.45; + _intensity = 0.45; + _saturation = 1.7; + } + backgroundContrast = cg.readEntry("contrast", _contrast); + backgroundIntensity = cg.readEntry("intensity", _intensity); + backgroundSaturation = cg.readEntry("saturation", _saturation); + //} + } else { + backgroundContrastEnabled = false; + } +} + void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings) { QString theme = tempThemeName; @@ -563,12 +593,32 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings //qDebug() << "we're going for..." << colorsFile << "*******************"; + if (colorsFile.isEmpty()) { + colors = 0; + if (qApp) { + installEventFilter(qApp); + } + } else { + if (qApp) { + removeEventFilter(qApp); + } + colors = KSharedConfig::openConfig(colorsFile); + } + + colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, colors); + buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors); + viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors); + const QString wallpaperPath = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/wallpapers/"); + hasWallpapers = !QStandardPaths::locate(QStandardPaths::GenericDataLocation, wallpaperPath, QStandardPaths::LocateDirectory).isEmpty(); + // load the wallpaper settings, if any if (realTheme) { const QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/metadata.desktop"))); KConfig metadata(metadataPath); pluginInfo = KPluginInfo(metadataPath); + processContrastSettings(&metadata); + processWallpaperSettings(&metadata); KConfigGroup cg(&metadata, "Settings"); @@ -599,24 +649,6 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings } } - if (colorsFile.isEmpty()) { - colors = 0; - if (qApp) { - installEventFilter(qApp); - } - } else { - if (qApp) { - removeEventFilter(qApp); - } - colors = KSharedConfig::openConfig(colorsFile); - } - - colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, colors); - buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors); - viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors); - const QString wallpaperPath = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/wallpapers/"); - hasWallpapers = !QStandardPaths::locate(QStandardPaths::GenericDataLocation, wallpaperPath, QStandardPaths::LocateDirectory).isEmpty(); - if (realTheme && isDefault && writeSettings) { // we're the default theme, let's save our state KConfigGroup &cg = config(); diff --git a/src/plasma/private/theme_p.h b/src/plasma/private/theme_p.h index 9fea9d2e5..291ce33a6 100644 --- a/src/plasma/private/theme_p.h +++ b/src/plasma/private/theme_p.h @@ -78,6 +78,7 @@ public: bool useCache(); void setThemeName(const QString &themeName, bool writeSettings); void processWallpaperSettings(KConfigBase *metadata); + void processContrastSettings(KConfigBase *metadata); const QString processStyleSheet(const QString &css); const QString svgStyleSheet(); @@ -146,6 +147,11 @@ public: bool useGlobal : 1; bool hasWallpapers : 1; bool cacheTheme : 1; + + qreal backgroundContrast; + qreal backgroundIntensity; + qreal backgroundSaturation; + bool backgroundContrastEnabled; }; } diff --git a/src/plasma/theme.cpp b/src/plasma/theme.cpp index e2632eabb..aba84d58b 100644 --- a/src/plasma/theme.cpp +++ b/src/plasma/theme.cpp @@ -540,6 +540,26 @@ QSizeF Theme::mSize(const QFont &font) const return QFontMetrics(font).boundingRect("M").size(); } +bool Theme::backgroundContrastEnabled() const +{ + return d->backgroundContrastEnabled; +} + +qreal Theme::backgroundContrast() const +{ + return d->backgroundContrast; +} + +qreal Theme::backgroundIntensity() const +{ + return d->backgroundIntensity; +} + +qreal Theme::backgroundSaturation() const +{ + return d->backgroundSaturation; +} + } diff --git a/src/plasma/theme.h b/src/plasma/theme.h index 813df15aa..42677fb1b 100644 --- a/src/plasma/theme.h +++ b/src/plasma/theme.h @@ -420,6 +420,53 @@ class PLASMA_EXPORT Theme : public QObject */ QColor viewFocusColor() const; + /** This method allows Plasma to enable and disable the background + * contrast effect for a given theme, improving readability. The + * value is read from the "enabled" key in the "ContrastEffect" + * group in the Theme's metadata file. + * The configuration in the metadata.desktop file of the theme + * could look like this (for a lighter background): + * \code + * [ContrastEffect] + * enabled=true + * contrast=0.45 + * intensity=0.45 + * saturation=1.7 + * \endcode + * @return Whether or not to enable the contrasteffect + * @since 5.0 + */ + bool backgroundContrastEnabled() const; + + /** This method allows Plasma to set a background contrast effect + * for a given theme, improving readability. The value is read + * from the "contrast" key in the "ContrastEffect" group in the + * Theme's metadata file. + * @return The contrast provided to the contrasteffect + * @since 5.0 + * @see backgroundContrastEnabled + */ + qreal backgroundContrast() const; + + /** This method allows Plasma to set a background contrast effect + * for a given theme, improving readability. The value is read + * from the "intensity" key in the "ContrastEffect" group in the + * Theme's metadata file. + * @return The intensity provided to the contrasteffect + * @since 5.0 + * @see backgroundContrastEnabled + */ + qreal backgroundIntensity() const; + + /** This method allows Plasma to set a background contrast effect + * for a given theme, improving readability. The value is read + * from the "saturation" key in the "ContrastEffect" group in the + * Theme's metadata file. + * @return The saturation provided to the contrasteffect + * @since 5.0 + * @see backgroundContrastEnabled + */ + qreal backgroundSaturation() const; /** * Returns the size of the letter "M" as rendered on the screen with the given font. diff --git a/src/shell/panelconfigview.cpp b/src/shell/panelconfigview.cpp index d181a176b..e2346af19 100644 --- a/src/shell/panelconfigview.cpp +++ b/src/shell/panelconfigview.cpp @@ -48,11 +48,8 @@ PanelConfigView::PanelConfigView(Plasma::Containment *containment, PanelView *pa setFlags(Qt::BypassWindowManagerHint); KWindowEffects::enableBlurBehind(winId(), true); - if (qGray(m_theme.color(Plasma::Theme::BackgroundColor).rgb()) > 127) { - KWindowEffects::enableBackgroundContrast(winId(), true, 0.30, 1.9, 1.7); - } else { - KWindowEffects::enableBackgroundContrast(winId(), true, 0.45, 0.45, 1.7); - } + updateContrast(); + connect(&m_theme, &Plasma::Theme::themeChanged, this, &PanelConfigView::updateContrast); engine()->rootContext()->setContextProperty("panel", panelView); engine()->rootContext()->setContextProperty("configDialog", this); @@ -78,6 +75,14 @@ QAction *PanelConfigView::action(const QString &name) return 0; } +void PanelConfigView::updateContrast() +{ + KWindowEffects::enableBackgroundContrast(winId(), m_theme.backgroundContrastEnabled(), + m_theme.backgroundContrast(), + m_theme.backgroundIntensity(), + m_theme.backgroundSaturation()); +} + void PanelConfigView::showAddWidgetDialog() { QAction *addWidgetAction = m_containment->actions()->action("add widgets"); diff --git a/src/shell/panelconfigview.h b/src/shell/panelconfigview.h index 2d91aff81..223ccfb14 100644 --- a/src/shell/panelconfigview.h +++ b/src/shell/panelconfigview.h @@ -58,6 +58,9 @@ protected: protected Q_SLOTS: void syncGeometry(); +private Q_SLOTS: + void updateContrast(); + private: Plasma::Containment *m_containment; PanelView *m_panelView; diff --git a/src/shell/panelview.cpp b/src/shell/panelview.cpp index d47809547..9d3790ec8 100644 --- a/src/shell/panelview.cpp +++ b/src/shell/panelview.cpp @@ -55,13 +55,8 @@ PanelView::PanelView(ShellCorona *corona, QWindow *parent) KWindowSystem::setType(winId(), NET::Dock); setVisible(false); - //TODO: how to take the shape from the framesvg? - KWindowEffects::enableBlurBehind(winId(), true); - if (qGray(m_theme.color(Plasma::Theme::BackgroundColor).rgb()) > 127) { - KWindowEffects::enableBackgroundContrast(winId(), true, 0.30, 1.9, 1.7); - } else { - KWindowEffects::enableBackgroundContrast(winId(), true, 0.45, 0.45, 1.7); - } + themeChanged(); + connect(&m_theme, &Plasma::Theme::themeChanged, this, &PanelView::themeChanged); //Screen management connect(this, &QWindow::screenChanged, @@ -623,4 +618,14 @@ void PanelView::updateStruts() //recreateUnhideTrigger(); } +void PanelView::themeChanged() +{ + //TODO: how to take the shape from the framesvg? + KWindowEffects::enableBlurBehind(winId(), true); + KWindowEffects::enableBackgroundContrast(winId(), m_theme.backgroundContrastEnabled(), + m_theme.backgroundContrast(), + m_theme.backgroundIntensity(), + m_theme.backgroundSaturation()); +} + #include "moc_panelview.cpp" diff --git a/src/shell/panelview.h b/src/shell/panelview.h index 69de7c112..e3aebc0ac 100644 --- a/src/shell/panelview.h +++ b/src/shell/panelview.h @@ -99,6 +99,7 @@ protected Q_SLOTS: void updateStruts(); private Q_SLOTS: + void themeChanged(); void positionPanel(); void restore();