File indexing completed on 2024-05-12 15:50:04
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 SPDX-FileCopyrightText: 2020 Jonathan Poelen <jonathan.poelen@gmail.com> 0004 0005 SPDX-License-Identifier: MIT 0006 */ 0007 0008 #ifndef KSYNTAXHIGHLIGHTING_FORMAT_H 0009 #define KSYNTAXHIGHLIGHTING_FORMAT_H 0010 0011 #include "ksyntaxhighlighting_export.h" 0012 #include "theme.h" 0013 0014 #include <QExplicitlySharedDataPointer> 0015 0016 QT_BEGIN_NAMESPACE 0017 class QColor; 0018 class QString; 0019 class QXmlStreamReader; 0020 QT_END_NAMESPACE 0021 0022 namespace KSyntaxHighlighting 0023 { 0024 class FormatPrivate; 0025 0026 /** Describes the format to be used for a specific text fragment. 0027 * The actual format used for displaying is merged from the format information 0028 * in the syntax definition file, and a theme. 0029 * 0030 * @see Theme 0031 * @since 5.28 0032 */ 0033 class KSYNTAXHIGHLIGHTING_EXPORT Format 0034 { 0035 public: 0036 /** Creates an empty/invalid format. */ 0037 Format(); 0038 Format(const Format &other); 0039 ~Format(); 0040 0041 Format &operator=(const Format &other); 0042 0043 /** Returns @c true if this is a valid format, ie. one that 0044 * was read from a syntax definition file. 0045 */ 0046 bool isValid() const; 0047 0048 /** The name of this format as used in the syntax definition file. */ 0049 QString name() const; 0050 0051 /** Returns a unique identifier of this format. 0052 * This is useful for efficient storing of formats in a text line. The 0053 * identifier is unique per Repository instance, but will change when 0054 * the repository is reloaded (which also invalidatess the corresponding 0055 * Definition anyway). 0056 */ 0057 quint16 id() const; 0058 0059 /** Returns the underlying TextStyle of this Format. 0060 * Every Theme::TextStyle is visually defined by a Theme. A Format uses one 0061 * of the Theme::TextStyle%s and on top allows modifications such as setting 0062 * a different foreground color etc. 0063 * @see Theme::TextStyle 0064 * @since 5.49 0065 */ 0066 Theme::TextStyle textStyle() const; 0067 0068 /** Returns @c true if the combination of this format and the theme @p theme 0069 * do not change the default text format in any way. 0070 * This is useful for output formats where changing formatting implies cost, 0071 * and thus benefit from optimizing the default case of not having any format 0072 * applied. If you make use of this, make sure to set the default text style 0073 * to what the corresponding theme sets for Theme::Normal. 0074 */ 0075 bool isDefaultTextStyle(const Theme &theme) const; 0076 0077 /** Returns @c true if the combination of this format and the theme @p theme 0078 * change the foreground color compared to the default format. 0079 */ 0080 bool hasTextColor(const Theme &theme) const; 0081 /** Returns the foreground color of the combination of this format and the 0082 * given theme. 0083 */ 0084 QColor textColor(const Theme &theme) const; 0085 /** Returns the foreground color for selected text of the combination of 0086 * this format and the given theme. 0087 */ 0088 QColor selectedTextColor(const Theme &theme) const; 0089 /** Returns @c true if the combination of this format and the theme @p theme 0090 * change the background color compared to the default format. 0091 */ 0092 bool hasBackgroundColor(const Theme &theme) const; 0093 /** Returns the background color of the combination of this format and the 0094 * given theme. 0095 */ 0096 QColor backgroundColor(const Theme &theme) const; 0097 /** Returns the background color of selected text of the combination of 0098 * this format and the given theme. 0099 */ 0100 QColor selectedBackgroundColor(const Theme &theme) const; 0101 0102 /** Returns @c true if the combination of this format and the given theme 0103 * results in bold text formatting. 0104 */ 0105 bool isBold(const Theme &theme) const; 0106 /** Returns @c true if the combination of this format and the given theme 0107 * results in italic text formatting. 0108 */ 0109 bool isItalic(const Theme &theme) const; 0110 /** Returns @c true if the combination of this format and the given theme 0111 * results in underlined text. 0112 */ 0113 bool isUnderline(const Theme &theme) const; 0114 /** Returns @c true if the combination of this format and the given theme 0115 * results in struck through text. 0116 */ 0117 bool isStrikeThrough(const Theme &theme) const; 0118 0119 /** 0120 * Returns whether characters with this format should be spell checked. 0121 */ 0122 bool spellCheck() const; 0123 0124 /** Returns @c true if the syntax definition file sets a value for the bold text 0125 * attribute and, therefore, overrides the theme and the default formatting 0126 * style. If the return is @p true, this value is obtained by isBold(). 0127 * @see isBold() 0128 * @since 5.62 0129 */ 0130 bool hasBoldOverride() const; 0131 0132 /** Returns @c true if the syntax definition file sets a value for the italic text 0133 * attribute and, therefore, overrides the theme and the default formatting style. 0134 * If the return is @p true, this value is obtained by isItalic(). 0135 * @see isItalic() 0136 * @since 5.62 0137 */ 0138 bool hasItalicOverride() const; 0139 0140 /** Returns @c true if the syntax definition file sets a value for the underlined 0141 * text attribute and, therefore, overrides the theme and the default formatting 0142 * style. If the return is @p true, this value is obtained by isUnderline(). 0143 * @see isUnderline() 0144 * @since 5.62 0145 */ 0146 bool hasUnderlineOverride() const; 0147 0148 /** Returns @c true if the syntax definition file specifies a value for the 0149 * struck through text attribute. If the return is @p true, this value 0150 * is obtained by isStrikeThrough(). 0151 * @see isStrikeThrough() 0152 * @since 5.62 0153 */ 0154 bool hasStrikeThroughOverride() const; 0155 0156 /** Returns @c true if the syntax definition file sets a value for the foreground 0157 * text color attribute and, therefore, overrides the theme and the default formatting 0158 * style. If the return is @p true, this value is obtained by textColor(). 0159 * @see textColor(), hasTextColor() 0160 * @since 5.62 0161 */ 0162 bool hasTextColorOverride() const; 0163 0164 /** Returns @c true if the syntax definition file sets a value for the background 0165 * color attribute and, therefore, overrides the theme and the default formatting 0166 * style. If the return is @p true, this value is obtained by backgroundColor(). 0167 * @see backgroundColor(), hasBackgroundColor() 0168 * @since 5.62 0169 */ 0170 bool hasBackgroundColorOverride() const; 0171 0172 /** Returns @c true if the syntax definition file specifies a value for the 0173 * selected text color attribute. If the return is @p true, this value is 0174 * obtained by selectedTextColor(). 0175 * @see selectedTextColor() 0176 * @since 5.62 0177 */ 0178 bool hasSelectedTextColorOverride() const; 0179 0180 /** Returns @c true if the syntax definition file specifies a value for the 0181 * selected background color attribute. If the return is @p true, this 0182 * value is obtained by selectedBackgroundColor(). 0183 * @see selectedBackgroundColor() 0184 * @since 5.62 0185 */ 0186 bool hasSelectedBackgroundColorOverride() const; 0187 0188 private: 0189 friend class FormatPrivate; 0190 QExplicitlySharedDataPointer<FormatPrivate> d; 0191 }; 0192 } 0193 0194 QT_BEGIN_NAMESPACE 0195 Q_DECLARE_TYPEINFO(KSyntaxHighlighting::Format, Q_MOVABLE_TYPE); 0196 QT_END_NAMESPACE 0197 0198 #endif // KSYNTAXHIGHLIGHTING_FORMAT_H