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