File indexing completed on 2024-05-26 05:16:56
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 * 0006 */ 0007 0008 #pragma once 0009 #include <KTextTemplate/Node> 0010 #include <QObject> 0011 0012 /** 0013 * @name icon tag 0014 * @brief Provides {% icon %} tag for inserting themed icons 0015 * 0016 * The syntax is: 0017 * @code 0018 * {% icon "icon-name"|var-with-icon-name [ sizeOrGroup ] [ alt text ] %} 0019 * @endcode 0020 * 0021 * Where @p icon-name is a string literal with icon name, @p var-with-icon-name 0022 * is a variable that contains a string with the icon name. @p sizeOrGrop is 0023 * one of the KIconLoader::Group or KIconLoader::StdSizes enum values. The value 0024 * is case-insensitive. 0025 * 0026 * The tag generates a full <img> HTML code: 0027 * @code 0028 * <img src="/usr/share/icons/[theme]/[type]/[size]/[icon-name].png" width="[width]" height="[height]"> 0029 * @endcode 0030 * 0031 * The full path to the icon is resolved using KIconLoader::iconPath(). The 0032 * @p width and @p height attributes are calculated based on current settings 0033 * for icon sizes in KDE. 0034 * 0035 * @note Support for nested variables inside tags is non-standard for Grantlee 0036 * tags, but makes it easier to use {% icon %} in sub-templates. 0037 */ 0038 class IconTag : public KTextTemplate::AbstractNodeFactory 0039 { 0040 Q_OBJECT 0041 public: 0042 explicit IconTag(QObject *parent = nullptr); 0043 ~IconTag() override; 0044 KTextTemplate::Node *getNode(const QString &tagContent, KTextTemplate::Parser *p) const override; 0045 }; 0046 class IconNode : public KTextTemplate::Node 0047 { 0048 Q_OBJECT 0049 public: 0050 explicit IconNode(QObject *parent = nullptr); 0051 IconNode(const QString &iconName, int sizeOrGroup, const QString &altText, QObject *parent = nullptr); 0052 ~IconNode() override; 0053 void render(KTextTemplate::OutputStream *stream, KTextTemplate::Context *c) const override; 0054 0055 private: 0056 QString mIconName; 0057 QString mAltText; 0058 int mSizeOrGroup; 0059 };