GrantleeTheme

color.h
1 /*
2  * SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  */
6 
7 #pragma once
8 #include <QObject>
9 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
10 #include <grantlee/filter.h>
11 #include <grantlee/node.h>
12 #else
13 #include <KTextTemplate/filter.h>
14 #include <KTextTemplate/node.h>
15 #endif
16 
17 /**
18  * @name colorHexRgb filter
19  * @brief Provides colorName filter for converting a QColor to a color string.
20  *
21  * The syntax is:
22  * @code
23  * {{ myColor|colorHexRgb }}
24  * @endcode
25  */
26 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
27 class ColorHexRgbFilter : public Grantlee::Filter
28 #else
29 class ColorHexRgbFilter : public KTextTemplate::Filter
30 #endif
31 {
32 public:
33  QVariant doFilter(const QVariant &input, const QVariant &arg, bool autoescape) const override;
34 };
35 
36 /**
37  * @name colorCssRgba filter
38  * @brief Provides colorRgba filter for converting a QColor to a rgba() CSS color definition.
39  *
40  * The syntax is:
41  * @code
42  * {{ myColor|colorCssRgba }}
43  * @endcode
44  */
45 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
46 class ColorCssRgbaFilter : public Grantlee::Filter
47 #else
48 class ColorCssRgbaFilter : public KTextTemplate::Filter
49 #endif
50 {
51 public:
52  QVariant doFilter(const QVariant &input, const QVariant &arg, bool autoescape) const override;
53 };
54 
55 /**
56  * @name colorLighter filter
57  * @brief Provides colorLighter filter for applying QColor::lighter to a color.
58  *
59  * The syntax is:
60  * @code
61  * {{ myColor|colorLighter:<factor> }}
62  * @endcode
63  */
64 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
65 class ColorLighterFilter : public Grantlee::Filter
66 #else
67 class ColorLighterFilter : public KTextTemplate::Filter
68 #endif
69 {
70 public:
71  QVariant doFilter(const QVariant &input, const QVariant &arg, bool autoescape) const override;
72 };
73 
74 /**
75  * @name colorDarker filter
76  * @brief Provides colorDarker filter for applying QColor::darker to a color.
77  *
78  * The syntax is:
79  * @code
80  * {{ myColor|colorDarker:<factor> }}
81  * @endcode
82  */
83 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
84 class ColorDarkerFilter : public Grantlee::Filter
85 #else
86 class ColorDarkerFilter : public KTextTemplate::Filter
87 #endif
88 {
89 public:
90  QVariant doFilter(const QVariant &input, const QVariant &arg, bool autoescape) const override;
91 };
92 
93 /**
94  * @name colorSetAlpha filter
95  * @brief Provides colorSetAlpha filter for setting a fixed alpha value on the given color.
96  *
97  * The syntax is:
98  * @code
99  * {{ myColor|colorSetAlpha:<alpha-value-from-0-to-255> }}
100  * @endcode
101  */
102 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
103 class ColorSetAlphaFilter : public Grantlee::Filter
104 #else
105 class ColorSetAlphaFilter : public KTextTemplate::Filter
106 #endif
107 {
108 public:
109  QVariant doFilter(const QVariant &input, const QVariant &arg, bool autoescape) const override;
110 };
111 
112 /**
113  * @name colorMix tag
114  * @brief Provides {% colorMix %} tag for mixing two colors
115  *
116  * The syntax is:
117  * @code
118  * {% colorMix "#rrggbb"|var-with-color "#rrggbb"|var-with-color <ratio> %}
119  * @endcode
120  *
121  * The tag generates a rgba() CSS color definition.
122  */
123 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
124 class ColorMixTag : public Grantlee::AbstractNodeFactory
125 #else
126 class ColorMixTag : public KTextTemplate::AbstractNodeFactory
127 #endif
128 {
129  Q_OBJECT
130 public:
131  explicit ColorMixTag(QObject *parent = nullptr);
132  ~ColorMixTag() override;
133 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
134  Grantlee::Node *getNode(const QString &tagContent, Grantlee::Parser *p) const override;
135 #else
136  KTextTemplate::Node *getNode(const QString &tagContent, KTextTemplate::Parser *p) const override;
137 #endif
138 };
139 
140 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
141 class ColorMixNode : public Grantlee::Node
142 #else
143 class ColorMixNode : public KTextTemplate::Node
144 #endif
145 {
146  Q_OBJECT
147 public:
148  explicit ColorMixNode(const QString &color1Name, const QString &color2Name, double ratio, const QString &varName, QObject *parent = nullptr);
149  ~ColorMixNode() override;
150 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
151  void render(Grantlee::OutputStream *stream, Grantlee::Context *c) const override;
152 #else
153  void render(KTextTemplate::OutputStream *stream, KTextTemplate::Context *c) const override;
154 #endif
155 
156 private:
157  QString m_color1Name;
158  QString m_color2Name;
159  QString m_varName;
160  double m_ratio;
161 };
162 
163 namespace Color
164 {
165 void registerMetaType();
166 }
167 
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 04:06:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.