GrantleeTheme

icon.h
1 /*
2  * SPDX-FileCopyrightText: 2015 Daniel Vr├ítil <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #pragma once
9 #include <QObject>
10 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
11 #include <grantlee/node.h>
12 #else
13 #include <KTextTemplate/node.h>
14 #endif
15 
16 /**
17  * @name icon tag
18  * @brief Provides {% icon %} tag for inserting themed icons
19  *
20  * The syntax is:
21  * @code
22  * {% icon "icon-name"|var-with-icon-name [ sizeOrGroup ] [ alt text ] %}
23  * @endcode
24  *
25  * Where @p icon-name is a string literal with icon name, @p var-with-icon-name
26  * is a variable that contains a string with the icon name. @p sizeOrGrop is
27  * one of the KIconLoader::Group or KIconLoader::StdSizes enum values. The value
28  * is case-insensitive.
29  *
30  * The tag generates a full <img> HTML code:
31  * @code
32  * <img src="/usr/share/icons/[theme]/[type]/[size]/[icon-name].png" width="[width]" height="[height]">
33  * @endcode
34  *
35  * The full path to the icon is resolved using KIconLoader::iconPath(). The
36  * @p width and @p height attributes are calculated based on current settings
37  * for icon sizes in KDE.
38  *
39  * @note Support for nested variables inside tags is non-standard for Grantlee
40  * tags, but makes it easier to use {% icon %} in sub-templates.
41  */
42 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
43 class IconTag : public Grantlee::AbstractNodeFactory
44 #else
45 class IconTag : public KTextTemplate::AbstractNodeFactory
46 #endif
47 {
48  Q_OBJECT
49 public:
50  explicit IconTag(QObject *parent = nullptr);
51  ~IconTag() override;
52 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
53  Grantlee::Node *getNode(const QString &tagContent, Grantlee::Parser *p) const override;
54 #else
55  KTextTemplate::Node *getNode(const QString &tagContent, KTextTemplate::Parser *p) const override;
56 #endif
57 };
58 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
59 class IconNode : public Grantlee::Node
60 #else
61 class IconNode : public KTextTemplate::Node
62 #endif
63 {
64  Q_OBJECT
65 public:
66  explicit IconNode(QObject *parent = nullptr);
67  IconNode(const QString &iconName, int sizeOrGroup, const QString &altText, QObject *parent = nullptr);
68  ~IconNode() override;
69 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
70  void render(Grantlee::OutputStream *stream, Grantlee::Context *c) const override;
71 #else
72  void render(KTextTemplate::OutputStream *stream, KTextTemplate::Context *c) const override;
73 #endif
74 
75 private:
76  QString mIconName;
77  QString mAltText;
78  int mSizeOrGroup;
79 };
80 
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.