Warning, file /frameworks/ktexteditor/src/include/ktexteditor/attribute.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2003-2005 Hamish Rodda <rodda@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KTEXTEDITOR_ATTRIBUTE_H 0008 #define KTEXTEDITOR_ATTRIBUTE_H 0009 0010 #include <QTextFormat> 0011 0012 #include <QExplicitlySharedDataPointer> 0013 #include <QSharedData> 0014 0015 #include <ktexteditor_export.h> 0016 0017 class QAction; 0018 0019 namespace KTextEditor 0020 { 0021 /** 0022 * The following lists all valid default styles that are used for the syntax 0023 * highlighting files in the itemData's defStyleNum attribute. 0024 * Not all default styles are used by a syntax highlighting file. 0025 * 0026 * \sa defaultStyleCount 0027 */ 0028 enum DefaultStyle { 0029 // 0030 // normal text 0031 // 0032 /** Default for normal text and source code. */ 0033 dsNormal = 0, 0034 /** Used for language keywords. */ 0035 dsKeyword, 0036 /** Used for function definitions and function calls. */ 0037 dsFunction, 0038 /** Used for variables, if applicable. */ 0039 dsVariable, 0040 /** Used for control flow highlighting, e.g., if, then, else, return, continue. */ 0041 dsControlFlow, 0042 /** Used for operators such as +, -, *, / and :: etc. */ 0043 dsOperator, 0044 /** Used for built-in language classes and functions. */ 0045 dsBuiltIn, 0046 /** Used for extensions, such as Qt or boost. */ 0047 dsExtension, 0048 /** Used for preprocessor statements. */ 0049 dsPreprocessor, 0050 /** Used for attributes of a function, e.g. \@override in Java. */ 0051 dsAttribute, 0052 0053 // 0054 // Strings & Characters 0055 // 0056 /** Used for a single character. */ 0057 dsChar, 0058 /** Used for an escaped character. */ 0059 dsSpecialChar, 0060 /** Used for strings. */ 0061 dsString, 0062 /** Used for verbatim strings such as HERE docs. */ 0063 dsVerbatimString, 0064 /** Used for special strings such as regular expressions or LaTeX math mode. */ 0065 dsSpecialString, 0066 /** Used for includes, imports and modules. */ 0067 dsImport, 0068 0069 // 0070 // Number, Types & Constants 0071 // 0072 /** Used for data types such as int, char, float etc. */ 0073 dsDataType, 0074 /** Used for decimal values. */ 0075 dsDecVal, 0076 /** Used for numbers with base other than 10. */ 0077 dsBaseN, 0078 /** Used for floating point numbers. */ 0079 dsFloat, 0080 /** Used for language constants. */ 0081 dsConstant, 0082 0083 // 0084 // Comments & Documentation 0085 // 0086 /** Used for normal comments. */ 0087 dsComment, 0088 /** Used for comments that reflect API documentation. */ 0089 dsDocumentation, 0090 /** Used for annotations in comments, e.g. \@param in Doxygen or JavaDoc. */ 0091 dsAnnotation, 0092 /** Used to refer to variables in a comment, e.g. after \@param in Doxygen or JavaDoc. */ 0093 dsCommentVar, 0094 /** Used for region markers, typically defined by BEGIN/END. */ 0095 dsRegionMarker, 0096 /** Used for information, e.g. the keyword \@note in Doxygen. */ 0097 dsInformation, 0098 /** Used for warnings, e.g. the keyword \@warning in Doxygen. */ 0099 dsWarning, 0100 /** Used for comment specials TODO and WARNING in comments. */ 0101 dsAlert, 0102 0103 // 0104 // Misc 0105 // 0106 /** Used for attributes that do not match any of the other default styles. */ 0107 dsOthers, 0108 /** Used to indicate wrong syntax. */ 0109 dsError 0110 }; 0111 0112 /** 0113 * \returns the number of default styles. 0114 * 0115 * \sa DefaultStyle 0116 */ 0117 int defaultStyleCount(); 0118 0119 /** 0120 * \class Attribute attribute.h <KTextEditor/Attribute> 0121 * 0122 * \brief A class which provides customized text decorations. 0123 * 0124 * The Attribute class extends QTextCharFormat, the class which Qt 0125 * uses internally to provide formatting information to characters 0126 * in a text document. 0127 * 0128 * In addition to its inherited properties, it provides support for: 0129 * \li several customized text formatting properties 0130 * \li dynamic highlighting of associated ranges of text 0131 * \li binding of actions with associated ranges of text (note: not currently implemented) 0132 * 0133 * Implementations are not required to support all properties. 0134 * In particular, several properties are not supported for dynamic 0135 * highlighting (notably: font() and fontBold()). 0136 * 0137 * Unfortunately, as QTextFormat's setProperty() is not virtual, 0138 * changes that are made to this attribute cannot automatically be 0139 * redrawn. Once you have finished changing properties, you should 0140 * call changed() to force redrawing of affected ranges of text. 0141 * 0142 * \sa MovingInterface 0143 * 0144 * \author Hamish Rodda \<rodda@kde.org\> 0145 */ 0146 class KTEXTEDITOR_EXPORT Attribute : public QTextCharFormat, public QSharedData 0147 { 0148 public: 0149 /** 0150 * Shared data pointer for Attribute 0151 */ 0152 typedef QExplicitlySharedDataPointer<Attribute> Ptr; 0153 0154 /** 0155 * Default constructor. 0156 * The resulting Attribute has no properties set to begin with. 0157 */ 0158 Attribute(); 0159 0160 /** 0161 * Construct attribute with given name & default style properties. 0162 * @param name attribute name 0163 * @param style attribute default style 0164 */ 0165 Attribute(const QString &name, DefaultStyle style); 0166 0167 /** 0168 * Copy constructor. 0169 */ 0170 Attribute(const Attribute &a); 0171 0172 /** 0173 * Virtual destructor. 0174 */ 0175 virtual ~Attribute(); 0176 0177 // BEGIN custom properties 0178 0179 /** 0180 * \name Custom properties 0181 * 0182 * The following functions provide custom properties which can be set for 0183 * rendering by editor implementations. 0184 * \{ 0185 */ 0186 0187 /** 0188 * Attribute name 0189 * 0190 * \return attribute name 0191 */ 0192 QString name() const; 0193 0194 /** 0195 * Set attribute name 0196 * 0197 * \param name new attribute name 0198 */ 0199 void setName(const QString &name); 0200 0201 /** 0202 * Default style of this attribute 0203 * 0204 * \return default style 0205 */ 0206 DefaultStyle defaultStyle() const; 0207 0208 /** 0209 * Set default style of this attribute 0210 * 0211 * \param style new default style 0212 */ 0213 void setDefaultStyle(DefaultStyle style); 0214 0215 /** 0216 * Should spellchecking be skipped? 0217 * 0218 * \return skip spellchecking? 0219 */ 0220 bool skipSpellChecking() const; 0221 0222 /** 0223 * Set if we should spellchecking be skipped? 0224 * 0225 * @param skipspellchecking should spellchecking be skipped? 0226 */ 0227 void setSkipSpellChecking(bool skipspellchecking); 0228 0229 /** 0230 * Find out if the font weight is set to QFont::Bold. 0231 * 0232 * \return \c true if the font weight is exactly QFont::Bold, otherwise \c false 0233 * 0234 * \see QTextCharFormat::fontWeight() 0235 */ 0236 bool fontBold() const; 0237 0238 /** 0239 * Set the font weight to QFont::Bold. If \a bold is \p false, the weight will be set to 0 (normal). 0240 * 0241 * \param bold whether the font weight should be bold or not. 0242 * 0243 * \see QTextCharFormat::setFontWeight() 0244 */ 0245 void setFontBold(bool bold = true); 0246 0247 /** 0248 * Get the brush used to draw an outline around text, if any. 0249 * 0250 * \return brush to be used to draw an outline, or Qt::NoBrush if no outline is set. 0251 */ 0252 QBrush outline() const; 0253 0254 /** 0255 * Set a brush to be used to draw an outline around text. 0256 * 0257 * Use \p clearProperty(Outline) to clear. 0258 * 0259 * \param brush brush to be used to draw an outline. 0260 */ 0261 void setOutline(const QBrush &brush); 0262 0263 /** 0264 * Get the brush used to draw text when it is selected, if any. 0265 * 0266 * \return brush to be used to draw selected text, or Qt::NoBrush if not set 0267 */ 0268 QBrush selectedForeground() const; 0269 0270 /** 0271 * Set a brush to be used to draw selected text. 0272 * 0273 * Use \p clearProperty(SelectedForeground) to clear. 0274 * 0275 * \param foreground brush to be used to draw selected text. 0276 */ 0277 void setSelectedForeground(const QBrush &foreground); 0278 0279 /** 0280 * Get the brush used to draw the background of selected text, if any. 0281 * 0282 * \return brush to be used to draw the background of selected text, or Qt::NoBrush if not set 0283 */ 0284 QBrush selectedBackground() const; 0285 0286 /** 0287 * Set a brush to be used to draw the background of selected text, if any. 0288 * 0289 * Use \p clearProperty(SelectedBackground) to clear. 0290 * 0291 * \param brush brush to be used to draw the background of selected text 0292 */ 0293 void setSelectedBackground(const QBrush &brush); 0294 0295 /** 0296 * Determine whether background color is drawn over whitespace. Defaults to true if not set. 0297 * 0298 * \return whether the background color should be drawn over whitespace 0299 */ 0300 bool backgroundFillWhitespace() const; 0301 0302 /** 0303 * Set whether background color is drawn over whitespace. Defaults to true if not set. 0304 * 0305 * Use \p clearProperty(BackgroundFillWhitespace) to clear. 0306 * 0307 * \param fillWhitespace whether the background should be drawn over whitespace. 0308 */ 0309 void setBackgroundFillWhitespace(bool fillWhitespace); 0310 0311 /** 0312 * Clear all set properties. 0313 */ 0314 void clear(); 0315 0316 /** 0317 * Determine if any properties are set. 0318 * 0319 * \return \e true if any properties are set, otherwise \e false 0320 */ 0321 bool hasAnyProperty() const; 0322 0323 // END 0324 0325 // BEGIN Dynamic highlighting 0326 0327 /** 0328 * \name Dynamic highlighting 0329 * 0330 * The following functions allow for text to be highlighted dynamically based on 0331 * several events. 0332 * \{ 0333 */ 0334 0335 /** 0336 * Several automatic activation mechanisms exist for associated attributes. 0337 * Using this you can conveniently have your ranges highlighted when either 0338 * the mouse or cursor enter the range. 0339 */ 0340 enum ActivationType { 0341 /// Activate attribute on mouse in 0342 ActivateMouseIn = 0, 0343 /// Activate attribute on caret in 0344 ActivateCaretIn 0345 }; 0346 0347 /** 0348 * Return the attribute to use when the event referred to by \a type occurs. 0349 * 0350 * \param type the activation type for which to return the Attribute. 0351 * 0352 * \returns the attribute to be used for events specified by \a type, or null if none is set. 0353 */ 0354 Attribute::Ptr dynamicAttribute(ActivationType type) const; 0355 0356 /** 0357 * Set the attribute to use when the event referred to by \a type occurs. 0358 * 0359 * \note Nested dynamic attributes are ignored. 0360 * 0361 * \param type the activation type to set the attribute for 0362 * \param attribute the attribute to assign. As attribute is refcounted, ownership is not an issue. 0363 */ 0364 void setDynamicAttribute(ActivationType type, Attribute::Ptr attribute); 0365 0366 //!\} 0367 0368 // END 0369 0370 /** 0371 * Addition assignment operator. Use this to merge another Attribute with this Attribute. 0372 * Where both attributes have a particular property set, the property in \a a will 0373 * be used. 0374 * 0375 * \param a attribute to merge into this attribute. 0376 */ 0377 Attribute &operator+=(const Attribute &a); 0378 0379 /** 0380 * Replacement assignment operator. Use this to overwrite this Attribute with another Attribute. 0381 * 0382 * \param a attribute to assign to this attribute. 0383 */ 0384 Attribute &operator=(const Attribute &a); 0385 0386 private: 0387 /** 0388 * Private d-pointer 0389 */ 0390 class AttributePrivate *const d; 0391 }; 0392 0393 /** 0394 * @brief Attribute%s of a part of a line. 0395 * 0396 * An AttributeBlock represents an Attribute spanning the interval 0397 * [start, start + length) of a given line. An AttributeBlock is 0398 * obtained by calling KTextEditor::View::lineAttributes(). 0399 * 0400 * \see KTextEditor::View::lineAttributes() 0401 */ 0402 class AttributeBlock 0403 { 0404 public: 0405 /** 0406 * Constructor of AttributeBlock. 0407 */ 0408 AttributeBlock(int _start, int _length, const Attribute::Ptr &_attribute) 0409 : start(_start) 0410 , length(_length) 0411 , attribute(_attribute) 0412 { 0413 } 0414 0415 /** 0416 * The column this attribute starts at. 0417 */ 0418 int start; 0419 0420 /** 0421 * The number of columns this attribute spans. 0422 */ 0423 int length; 0424 0425 /** 0426 * The attribute for the current range. 0427 */ 0428 Attribute::Ptr attribute; 0429 }; 0430 0431 } 0432 0433 Q_DECLARE_TYPEINFO(KTextEditor::AttributeBlock, Q_MOVABLE_TYPE); 0434 0435 #endif