KI18n

kuitsetup.h
1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2013 Chusslove Illich <caslav.ilic@gmx.net>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KUITSETUP_H
8#define KUITSETUP_H
9
10#include <ki18n_export.h>
11
12#include <QHash>
13#include <QString>
14#include <QStringList>
15
16class KuitSetup;
17
18/**
19 * Global constants and functions related to KUIT markup.
20 */
21namespace Kuit
22{
23/**
24 * Visual formats into which KUIT markup can be resolved.
25 */
27 /**
28 * Visual format not defined.
29 * This value can be explicitly set
30 * (e.g. through \c KLocalizedString::withFormat)
31 * to indicate that the format should be decided
32 * by another mechanism (e.g. context UI marker).
33 */
35 /**
36 * Plain text.
37 */
39 /**
40 * Qt rich text (HTML subset).
41 */
43 /**
44 * Terminal escape sequences.
45 */
47};
48
49/**
50 * Classification of KUIT tags.
51 */
53 /**
54 * Tags wrapping text inserted into running text.
55 */
57 /**
58 * Tags splitting text into paragraph-level blocks.
59 */
61};
62
63/**
64 * Functions accepted by tag formatting functions.
65 *
66 * \param languages the target languages (by decreasing priority)
67 * \param tagName the wrapping tag name
68 * \param attributes the attribute name-value pairs in the tag
69 * \param text the wrapped text
70 * \param tagPath the ordered list of ancestor tag names, parent first
71 * \param format the target visual format
72 * \return formatted text
73 */
74typedef QString (*TagFormatter)(const QStringList &languages,
75 const QString &tagName,
76 const QHash<QString, QString> &attributes,
77 const QString &text,
78 const QStringList &tagPath,
79 Kuit::VisualFormat format);
80
81/**
82 * Get hold of the KUIT setup object for a given domain.
83 *
84 * \param domain the translation domain
85 * \return pointer to KUIT setup object
86 */
87KI18N_EXPORT KuitSetup &setupForDomain(const QByteArray &domain);
88}
89
91class KuitSetupPrivate;
92class KuitFormatterPrivate;
93
94/**
95 * @class KuitSetup kuitsetup.h <KuitSetup>
96 *
97 * Class for modifying KUIT markup in a given domain.
98 *
99 * Not directly constructed, but obtained through \c Kuit::setupForDomain.
100 */
101class KI18N_EXPORT KuitSetup
102{
103 friend KuitSetup &Kuit::setupForDomain(const QByteArray &domain);
104 friend class KuitFormatterPrivate;
105
106public:
107 /**
108 * Destructor.
109 */
110 ~KuitSetup();
111
112 /**
113 * Set the formatting string for a tag with attributes combination.
114 *
115 * If a new tag name is given, this effectively defines a new tag.
116 * The same holds for attribute names.
117 *
118 * The pattern string \p pattern should contain placeholders
119 * for inserting the text and the attribute values.
120 * %1 will be replaced with the wrapped text, and %2 and upwards
121 * with attribute values in the order given by \p attrNames.
122 * Non markup-aware translation call with context (\c ki18nc)
123 * should be used to create the pattern string.
124 *
125 * In addition to the pattern, a formatting function
126 * of the type \c TagFormatter can be given.
127 * This function receives the full markup parsing context,
128 * so that it can do whatever is necessary with the wrapped text.
129 * The result of this function is then substituted into the pattern.
130 * You can also give an empty pattern (as <tt>KLocalizedString()</tt>)
131 * together with the formatting function, in which case the function
132 * is assumed to do everything and no substitution is performed.
133 *
134 * \param tagName the name of the tag
135 * \param attribNames the names of the attributes (empty names are ignored)
136 * \param format the target visual format
137 * \param pattern the pattern string
138 * \param leadingNewlines the number of new lines (\\n) to be maintained
139 * between any preceding text and the text wrapped
140 * with this tag (for formats where it matters)
141 */
142 void setTagPattern(const QString &tagName,
143 const QStringList &attribNames,
144 Kuit::VisualFormat format,
145 const KLocalizedString &pattern,
146 Kuit::TagFormatter formatter = nullptr,
147 int leadingNewlines = 0);
148
149 /**
150 * Set the KUIT class of the tag.
151 *
152 * \param tagName the name of the tag
153 * \param aClass the KUIT tag class
154 */
155 void setTagClass(const QString &tagName, Kuit::TagClass aClass);
156
157 /**
158 * Set the default visual format for a given UI marker.
159 *
160 * Giving <tt>"@<major>"</tt> for \p marker means to set the format
161 * only for standalone <tt>\@<major></tt> marker,
162 * while <tt>"@<major>:"</tt> (with trailing colon) means to set
163 * the same format for all <tt>\@<major>:<minor></tt> combinations.
164 *
165 * Defined UI marker major/minor combinations are listed in the section
166 * \ref uimark_ctxt. If an UI marker combination outside of the defined
167 * is given as \p marker, it will be ignored.
168 *
169 * Setting \c Kuit::UndefinedFormat as \p format
170 * means to fall back to default format for the given UI marker.
171 *
172 * \param marker the UI marker
173 * \param format the visual format
174 */
175 void setFormatForMarker(const QString &marker, Kuit::VisualFormat format);
176
177private:
178 KI18N_NO_EXPORT explicit KuitSetup(const QByteArray &domain);
179 Q_DISABLE_COPY(KuitSetup)
180
181 // intentionally not a unique_ptr as this file gets included a lot and using a unique_ptr
182 // results in too many template instantiations
183 KuitSetupPrivate *const d;
184};
185
186#endif // KUITSETUP_H
Class for producing and handling localized messages.
Class for modifying KUIT markup in a given domain.
Definition kuitsetup.h:102
Global constants and functions related to KUIT markup.
TagClass
Classification of KUIT tags.
Definition kuitsetup.h:52
@ StructTag
Tags splitting text into paragraph-level blocks.
Definition kuitsetup.h:60
@ PhraseTag
Tags wrapping text inserted into running text.
Definition kuitsetup.h:56
QString(* TagFormatter)(const QStringList &languages, const QString &tagName, const QHash< QString, QString > &attributes, const QString &text, const QStringList &tagPath, Kuit::VisualFormat format)
Functions accepted by tag formatting functions.
Definition kuitsetup.h:74
VisualFormat
Visual formats into which KUIT markup can be resolved.
Definition kuitsetup.h:26
@ TermText
Terminal escape sequences.
Definition kuitsetup.h:46
@ UndefinedFormat
Visual format not defined.
Definition kuitsetup.h:34
@ RichText
Qt rich text (HTML subset).
Definition kuitsetup.h:42
@ PlainText
Plain text.
Definition kuitsetup.h:38
KI18N_EXPORT KuitSetup & setupForDomain(const QByteArray &domain)
Get hold of the KUIT setup object for a given domain.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.