diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,13 +22,13 @@ include(KDECMakeSettings) set(REQUIRED_QT_VERSION 5.5.0) -find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets DBus X11Extras) +find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Widgets DBus X11Extras Qml Quick) set(KF5_DEP_VERSION "5.33.0") find_package(KF5 ${KF5_DEP_VERSION} REQUIRED COMPONENTS Config ConfigWidgets I18n IconThemes KIO Notifications Wayland - WidgetsAddons WindowSystem + WidgetsAddons WindowSystem Kirigami2 ) find_package(XCB COMPONENTS XCB) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(platformtheme) +add_subdirectory(kirigami-integration) diff --git a/src/kirigami-integration/CMakeLists.txt b/src/kirigami-integration/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/kirigami-integration/CMakeLists.txt @@ -0,0 +1,23 @@ + + +set(org.kde.desktop_SRCS + plasmadesktoptheme.cpp + plasmadesktopthemefactory.cpp +) + + +add_library(org.kde.desktop MODULE ${org.kde.desktop_SRCS}) + +target_link_libraries(org.kde.desktop + PUBLIC + Qt5::Core + KF5::Kirigami2 + PRIVATE + Qt5::Qml + Qt5::Quick + KF5::ConfigWidgets + KF5::IconThemes +) + +install(TARGETS org.kde.desktop DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kirigami) + diff --git a/src/kirigami-integration/kirigamiplasmaintegration.json b/src/kirigami-integration/kirigamiplasmaintegration.json new file mode 100644 --- /dev/null +++ b/src/kirigami-integration/kirigamiplasmaintegration.json @@ -0,0 +1 @@ +{} diff --git a/src/kirigami-integration/plasmadesktoptheme.h b/src/kirigami-integration/plasmadesktoptheme.h new file mode 100644 --- /dev/null +++ b/src/kirigami-integration/plasmadesktoptheme.h @@ -0,0 +1,86 @@ +/* +* Copyright (C) 2017 by Marco Martin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details +* +* You should have received a copy of the GNU Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef KIRIGAMIPLASMATHEME_H +#define KIRIGAMIPLASMATHEME_H + +#include +#include +#include +#include +#include + +class PlasmaDesktopTheme; + +class PlasmaDesktopTheme : public Kirigami::PlatformTheme +{ + Q_OBJECT + + // colors + Q_PROPERTY(QColor buttonTextColor READ buttonTextColor NOTIFY colorsChanged) + Q_PROPERTY(QColor buttonBackgroundColor READ buttonBackgroundColor NOTIFY colorsChanged) + Q_PROPERTY(QColor buttonHoverColor READ buttonHoverColor NOTIFY colorsChanged) + Q_PROPERTY(QColor buttonFocusColor READ buttonFocusColor NOTIFY colorsChanged) + + Q_PROPERTY(QColor viewTextColor READ viewTextColor NOTIFY colorsChanged) + Q_PROPERTY(QColor viewBackgroundColor READ viewBackgroundColor NOTIFY colorsChanged) + Q_PROPERTY(QColor viewHoverColor READ viewHoverColor NOTIFY colorsChanged) + Q_PROPERTY(QColor viewFocusColor READ viewFocusColor NOTIFY colorsChanged) + + //FIXME: this is due https://bugreports.qt.io/browse/QTBUG-63089 + Q_PROPERTY(QStringList keys READ keys CONSTANT) + +public: + explicit PlasmaDesktopTheme(QObject *parent = 0); + ~PlasmaDesktopTheme(); + + Q_INVOKABLE QIcon iconFromTheme(const QString &name) Q_DECL_OVERRIDE; + + void syncColors(); + + QColor buttonTextColor() const; + QColor buttonBackgroundColor() const; + QColor buttonHoverColor() const; + QColor buttonFocusColor() const; + + QColor viewTextColor() const; + QColor viewBackgroundColor() const; + QColor viewHoverColor() const; + QColor viewFocusColor() const; + + QStringList keys() const; + +Q_SIGNALS: + void colorsChanged(); + +private: + QPointer m_parentItem; + //legacy colors + QColor m_buttonTextColor; + QColor m_buttonBackgroundColor; + QColor m_buttonHoverColor; + QColor m_buttonFocusColor; + QColor m_viewTextColor; + QColor m_viewBackgroundColor; + QColor m_viewHoverColor; + QColor m_viewFocusColor; +}; + + +#endif // KIRIGAMIPLASMATHEME_H diff --git a/src/kirigami-integration/plasmadesktoptheme.cpp b/src/kirigami-integration/plasmadesktoptheme.cpp new file mode 100644 --- /dev/null +++ b/src/kirigami-integration/plasmadesktoptheme.cpp @@ -0,0 +1,235 @@ +/* +* Copyright (C) 2017 by Marco Martin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details +* +* You should have received a copy of the GNU Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "plasmadesktoptheme.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +PlasmaDesktopTheme::PlasmaDesktopTheme(QObject *parent) + : PlatformTheme(parent) +{ + m_parentItem = qobject_cast(parent); + Q_ASSERT(m_parentItem); + connect(m_parentItem.data(), &QQuickItem::enabledChanged, + this, &PlasmaDesktopTheme::syncColors); + if (m_parentItem && m_parentItem->window()) { + connect(m_parentItem->window(), &QWindow::activeChanged, + this, &PlasmaDesktopTheme::syncColors); + } + connect(m_parentItem.data(), &QQuickItem::windowChanged, + this, [this]() { + if (m_parentItem && m_parentItem->window()) { + connect(m_parentItem->window(), &QWindow::activeChanged, + this, &PlasmaDesktopTheme::syncColors); + } + syncColors(); + }); + + //TODO: correct? depends from https://codereview.qt-project.org/206889 + connect(qApp, &QGuiApplication::fontDatabaseChanged, this, [this]() {setDefaultFont(qApp->font());}); + + connect(this, &PlasmaDesktopTheme::colorSetChanged, + this, &PlasmaDesktopTheme::syncColors); + connect(qApp, &QGuiApplication::paletteChanged, + this, &PlasmaDesktopTheme::syncColors); + + syncColors(); +} + +PlasmaDesktopTheme::~PlasmaDesktopTheme() +{ +} + +QIcon PlasmaDesktopTheme::iconFromTheme(const QString &name) +{ + KColorScheme::ColorSet set; + + switch (colorSet()) { + case PlatformTheme::Button: + set = KColorScheme::ColorSet::Button; + break; + case PlatformTheme::View: + set = KColorScheme::ColorSet::View; + break; + case PlatformTheme::Complementary: + set = KColorScheme::ColorSet::Complementary; + break; + case PlatformTheme::Window: + default: + set = KColorScheme::ColorSet::Window; + } + KIconLoader::global()->setColorSet(set); + + return KDE::icon(name, KIconLoader::global()); +} + +QStringList PlasmaDesktopTheme::keys() const +{ + QStringList props; + for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); ++i) { + const QString prop = QString::fromUtf8(metaObject()->property(i).name()); + if (prop != QStringLiteral("keys")) { + props << prop; + } + } + return props; +} + +void PlasmaDesktopTheme::syncColors() +{ + KColorScheme::ColorSet set; + + switch (colorSet()) { + case PlatformTheme::Button: + set = KColorScheme::ColorSet::Button; + break; + case PlatformTheme::View: + set = KColorScheme::ColorSet::View; + break; + case PlatformTheme::Complementary: + set = KColorScheme::ColorSet::Complementary; + break; + case PlatformTheme::Window: + default: + set = KColorScheme::ColorSet::Window; + } + + QPalette::ColorGroup group = QPalette::Active; + if (m_parentItem) { + if (!m_parentItem->isEnabled()) { + group = QPalette::Disabled; + } else if (m_parentItem->window() && !m_parentItem->window()->isActive()) { + group = QPalette::Inactive; + } + } + + const KColorScheme selectionScheme(group, KColorScheme::ColorSet::Selection); + const KColorScheme scheme(group, set); + setTextColor(scheme.foreground(KColorScheme::NormalText).color()); + setBackgroundColor(scheme.background(KColorScheme::NormalBackground).color()); + setDisabledTextColor(scheme.foreground(KColorScheme::InactiveText).color()); + setHighlightColor(selectionScheme.background(KColorScheme::NormalBackground).color()); + setHighlightedTextColor(selectionScheme.foreground(KColorScheme::NormalText).color()); + + setLinkColor(scheme.foreground(KColorScheme::LinkText).color()); + setVisitedLinkColor(scheme.foreground(KColorScheme::VisitedText).color()); + + QPalette pal = palette(); + static const QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive, QPalette::Disabled }; + for (int i = 0; i < 3; i++) { + QPalette::ColorGroup state = states[i]; + pal.setBrush(state, QPalette::WindowText, scheme.foreground()); + pal.setBrush(state, QPalette::Window, scheme.background()); + pal.setBrush(state, QPalette::Base, scheme.background()); + pal.setBrush(state, QPalette::Text, scheme.foreground()); + pal.setBrush(state, QPalette::Button, scheme.background()); + pal.setBrush(state, QPalette::ButtonText, scheme.foreground()); + pal.setBrush(state, QPalette::Highlight, selectionScheme.background()); + pal.setBrush(state, QPalette::HighlightedText, selectionScheme.foreground()); + pal.setBrush(state, QPalette::ToolTipBase, scheme.background()); + pal.setBrush(state, QPalette::ToolTipText, scheme.foreground()); + + pal.setColor(state, QPalette::Light, scheme.shade(KColorScheme::LightShade)); + pal.setColor(state, QPalette::Midlight, scheme.shade(KColorScheme::MidlightShade)); + pal.setColor(state, QPalette::Mid, scheme.shade(KColorScheme::MidShade)); + pal.setColor(state, QPalette::Dark, scheme.shade(KColorScheme::DarkShade)); + pal.setColor(state, QPalette::Shadow, scheme.shade(KColorScheme::ShadowShade)); + + pal.setBrush(state, QPalette::AlternateBase, scheme.background(KColorScheme::AlternateBackground)); + pal.setBrush(state, QPalette::Link, scheme.foreground(KColorScheme::LinkText)); + pal.setBrush(state, QPalette::LinkVisited, scheme.foreground(KColorScheme::VisitedText)); + } + setPalette(pal); + + + //legacy stuff + const KColorScheme buttonScheme(QPalette::Active, KColorScheme::ColorSet::Button); + m_buttonTextColor = buttonScheme.foreground(KColorScheme::NormalText).color(); + m_buttonBackgroundColor = buttonScheme.background(KColorScheme::NormalBackground).color(); + m_buttonHoverColor = buttonScheme.decoration(KColorScheme::HoverColor).color(); + m_buttonFocusColor = buttonScheme.decoration(KColorScheme::FocusColor).color(); + + const KColorScheme viewScheme(QPalette::Active, KColorScheme::ColorSet::View); + m_viewTextColor = viewScheme.foreground(KColorScheme::NormalText).color(); + m_viewBackgroundColor = viewScheme.background(KColorScheme::NormalBackground).color(); + m_viewHoverColor = viewScheme.decoration(KColorScheme::HoverColor).color(); + m_viewFocusColor = viewScheme.decoration(KColorScheme::FocusColor).color(); + + emit colorsChanged(); +} + +QColor PlasmaDesktopTheme::buttonTextColor() const +{ + qWarning()<<"WARNING: buttonTextColor is deprecated, use textColor with colorSet: Theme.Button instead"; + return m_buttonTextColor; +} + +QColor PlasmaDesktopTheme::buttonBackgroundColor() const +{ + qWarning()<<"WARNING: buttonBackgroundColor is deprecated, use backgroundColor with colorSet: Theme.Button instead"; + return m_buttonBackgroundColor; +} + +QColor PlasmaDesktopTheme::buttonHoverColor() const +{ + qWarning()<<"WARNING: buttonHoverColor is deprecated, use backgroundColor with colorSet: Theme.Button instead"; + return m_buttonHoverColor; +} + +QColor PlasmaDesktopTheme::buttonFocusColor() const +{ + qWarning()<<"WARNING: buttonFocusColor is deprecated, use backgroundColor with colorSet: Theme.Button instead"; + return m_buttonFocusColor; +} + + +QColor PlasmaDesktopTheme::viewTextColor() const +{ + qWarning()<<"WARNING: viewTextColor is deprecated, use backgroundColor with colorSet: Theme.View instead"; + return m_viewTextColor; +} + +QColor PlasmaDesktopTheme::viewBackgroundColor() const +{ + qWarning()<<"WARNING: viewBackgroundColor is deprecated, use backgroundColor with colorSet: Theme.View instead"; + return m_viewBackgroundColor; +} + +QColor PlasmaDesktopTheme::viewHoverColor() const +{ + qWarning()<<"WARNING: viewHoverColor is deprecated, use backgroundColor with colorSet: Theme.View instead"; + return m_viewHoverColor; +} + +QColor PlasmaDesktopTheme::viewFocusColor() const +{ + qWarning()<<"WARNING: viewFocusColor is deprecated, use backgroundColor with colorSet: Theme.View instead"; + return m_viewFocusColor; +} + +#include "moc_plasmadesktoptheme.cpp" diff --git a/src/kirigami-integration/plasmadesktopthemefactory.h b/src/kirigami-integration/plasmadesktopthemefactory.h new file mode 100644 --- /dev/null +++ b/src/kirigami-integration/plasmadesktopthemefactory.h @@ -0,0 +1,43 @@ +/* +* Copyright (C) 2017 by Marco Martin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details +* +* You should have received a copy of the GNU Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef PLASMADESKTOPTHEMEFACTORY_H +#define PLASMADESKTOPTHEMEFACTORY_H + +#include +#include + +class PlasmaDesktopThemeFactory : public Kirigami::PlatformThemeFactory +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "org.kde.kirigami.PlatformThemeFactory" FILE "kirigamiplasmaintegration.json") + + Q_INTERFACES(Kirigami::PlatformThemeFactory) + +public: + explicit PlasmaDesktopThemeFactory(QObject *parent = nullptr); + ~PlasmaDesktopThemeFactory(); + + Kirigami::PlatformTheme *create(QObject *parent) Q_DECL_OVERRIDE; +}; + + + +#endif // PLASMADESKTOPTHEMEFACTORY_H diff --git a/src/kirigami-integration/plasmadesktopthemefactory.cpp b/src/kirigami-integration/plasmadesktopthemefactory.cpp new file mode 100644 --- /dev/null +++ b/src/kirigami-integration/plasmadesktopthemefactory.cpp @@ -0,0 +1,38 @@ +/* +* Copyright (C) 2017 by Marco Martin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details +* +* You should have received a copy of the GNU Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "plasmadesktopthemefactory.h" +#include "plasmadesktoptheme.h" + +PlasmaDesktopThemeFactory::PlasmaDesktopThemeFactory(QObject *parent) + : Kirigami::PlatformThemeFactory(parent) +{ +} + +PlasmaDesktopThemeFactory::~PlasmaDesktopThemeFactory() +{ +} + +Kirigami::PlatformTheme *PlasmaDesktopThemeFactory::create(QObject *parent) +{ + Q_ASSERT(parent); + return new PlasmaDesktopTheme(parent); +} + +#include "moc_plasmadesktopthemefactory.cpp"