Merge branch 'sebas/themeswitch2'

Conflicts:
	src/shell/panelconfigview.cpp
This commit is contained in:
Sebastian Kügler 2014-02-17 17:59:32 +01:00
commit 7fcb1b7889
12 changed files with 175 additions and 39 deletions

View File

@ -55,3 +55,9 @@ defaultWallpaperTheme=Elarun
defaultFileSuffix=.png
defaultWidth=2560
defaultHeight=1600
[ContrastEffect]
enabled=true
contrast=0.3
intensity=1.9
saturation=1.7

View File

@ -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
}

View File

@ -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) {

View File

@ -174,7 +174,7 @@ protected:
private Q_SLOTS:
void syncBorders();
void updateContrast();
void updateVisibility(bool visible);
void updateMinimumWidth();

View File

@ -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();

View File

@ -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;
};
}

View File

@ -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;
}
}

View File

@ -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.

View File

@ -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");

View File

@ -58,6 +58,9 @@ protected:
protected Q_SLOTS:
void syncGeometry();
private Q_SLOTS:
void updateContrast();
private:
Plasma::Containment *m_containment;
PanelView *m_panelView;

View File

@ -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"

View File

@ -99,6 +99,7 @@ protected Q_SLOTS:
void updateStruts();
private Q_SLOTS:
void themeChanged();
void positionPanel();
void restore();