diff --git a/autotest/CMakeLists.txt b/autotest/CMakeLists.txt --- a/autotest/CMakeLists.txt +++ b/autotest/CMakeLists.txt @@ -1,7 +1,7 @@ add_definitions( -DGRANTLEETHEME_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) ecm_add_test(grantleethemetest.cpp NAME_PREFIX "grantleetheme-" - LINK_LIBRARIES Qt5::Test KF5::GrantleeTheme KF5::ConfigCore Qt5::Gui + LINK_LIBRARIES Qt5::Test KF5::GrantleeTheme KF5::ConfigCore Qt5::Gui KF5::ConfigWidgets ) ecm_add_test(grantleethememanagertest.cpp NAME_PREFIX "grantleetheme-" diff --git a/autotest/data/themes/color/color.html b/autotest/data/themes/color/color.html --- a/autotest/data/themes/color/color.html +++ b/autotest/data/themes/color/color.html @@ -20,4 +20,13 @@ Color literal: {{ "lightsteelblue"|colorHexRgb }} Mix filtered: {% colorMix pal.button "#0000ff" 0.5 as myColor %}{{ myColor|colorDarker:200|colorCssRgba }} + +## Color scheme +Normal background: {{ colorScheme.normalBackground.hexRgb }} +Link background: {{ colorScheme.linkBackground.hexRgb }} +Normal text: {{ colorScheme.normalText.hexRgb }} +Link text: {{ colorScheme.linkText.hexRgb }} +Hover color: {{ colorScheme.hoverColor.hexRgb }} +Focus color: {{ colorScheme.focusColor.hexRgb }} + diff --git a/autotest/data/themes/color/color_expected.html b/autotest/data/themes/color/color_expected.html --- a/autotest/data/themes/color/color_expected.html +++ b/autotest/data/themes/color/color_expected.html @@ -21,4 +21,13 @@ Color literal: #b0c4de Mix filtered: rgba(64, 0, 64, 1) + +## Color scheme +Normal background: #fcfcfc +Link background: #e5eff7 +Normal text: #232627 +Link text: #2980b9 +Hover color: #93cee9 +Focus color: #3daee9 + diff --git a/autotest/grantleethemetest.cpp b/autotest/grantleethemetest.cpp --- a/autotest/grantleethemetest.cpp +++ b/autotest/grantleethemetest.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -199,6 +200,7 @@ pal.setColor(QPalette::Inactive, QPalette::Base, Qt::green); pal.setColor(QPalette::Disabled, QPalette::Base, Qt::blue); data[QStringLiteral("pal")] = QVariant::fromValue(pal); + data[QStringLiteral("colorScheme")] = QVariant::fromValue(KColorScheme(QPalette::Normal, KColorScheme::View)); GrantleeTheme::Theme theme(themePath, dirname, filename); QCOMPARE(theme.isValid(), isValid); diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt --- a/src/plugin/CMakeLists.txt +++ b/src/plugin/CMakeLists.txt @@ -3,6 +3,7 @@ set(grantleeplugin_SRCS kdegrantleeplugin.cpp color.cpp + colorscheme.cpp icon.cpp palette.cpp ) @@ -13,6 +14,7 @@ Grantlee5::Templates KF5::IconThemes KF5::GuiAddons + KF5::ConfigWidgets ) install(TARGETS kde_grantlee_plugin diff --git a/src/plugin/colorscheme.h b/src/plugin/colorscheme.h new file mode 100644 --- /dev/null +++ b/src/plugin/colorscheme.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2019 Volker Krause + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef GRANTLEETHEME_COLORSCHEME_H +#define GRANTLEETHEME_COLORSCHEME_H + +namespace ColorScheme +{ + void registerMetaType(); +} + +#endif // GRANTLEETHEME_COLORSCHEME_H diff --git a/src/plugin/colorscheme.cpp b/src/plugin/colorscheme.cpp new file mode 100644 --- /dev/null +++ b/src/plugin/colorscheme.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2019 Volker Krause + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "colorscheme.h" + +#include + +#include + +#define PROP_IMPL(PROP, METHOD) if (QString::compare(property, QLatin1String(#PROP), Qt::CaseInsensitive) == 0) \ + { return object.METHOD(KColorScheme::PROP).color(); } +#define BACKGROUND_PROP(PROP) PROP_IMPL(PROP, background) +#define FOREGROUND_PROP(PROP) PROP_IMPL(PROP, foreground) +#define DECORATION_PROP(PROP) PROP_IMPL(PROP, decoration) + +GRANTLEE_BEGIN_LOOKUP(KColorScheme) + BACKGROUND_PROP(NormalBackground) + BACKGROUND_PROP(AlternateBackground) + BACKGROUND_PROP(ActiveBackground) + BACKGROUND_PROP(LinkBackground) + BACKGROUND_PROP(VisitedBackground) + BACKGROUND_PROP(NegativeBackground) + BACKGROUND_PROP(NeutralBackground) + BACKGROUND_PROP(PositiveBackground) + + FOREGROUND_PROP(NormalText) + FOREGROUND_PROP(InactiveText) + FOREGROUND_PROP(ActiveText) + FOREGROUND_PROP(LinkText) + FOREGROUND_PROP(VisitedText) + FOREGROUND_PROP(NegativeText) + FOREGROUND_PROP(NeutralText) + FOREGROUND_PROP(PositiveText) + + DECORATION_PROP(FocusColor) + DECORATION_PROP(HoverColor) + + return {}; +GRANTLEE_END_LOOKUP + + +void ColorScheme::registerMetaType() +{ + Grantlee::registerMetaType(); +} diff --git a/src/plugin/kdegrantleeplugin.cpp b/src/plugin/kdegrantleeplugin.cpp --- a/src/plugin/kdegrantleeplugin.cpp +++ b/src/plugin/kdegrantleeplugin.cpp @@ -19,14 +19,16 @@ #include "kdegrantleeplugin.h" #include "color.h" +#include "colorscheme.h" #include "icon.h" #include "palette.h" KDEGrantleePlugin::KDEGrantleePlugin(QObject *parent) : QObject(parent) , Grantlee::TagLibraryInterface() { Color::registerMetaType(); + ColorScheme::registerMetaType(); Palette::registerMetaType(); }