qscilexercss.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // This defines the interface to the QsciLexerCSS class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #ifndef QSCILEXERCSS_H
  20. #define QSCILEXERCSS_H
  21. #include <QObject>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qscilexer.h>
  24. //! \brief The QsciLexerCSS class encapsulates the Scintilla CSS lexer.
  25. class QSCINTILLA_EXPORT QsciLexerCSS : public QsciLexer
  26. {
  27. Q_OBJECT
  28. public:
  29. //! This enum defines the meanings of the different styles used by the
  30. //! CSS lexer.
  31. enum {
  32. //! The default.
  33. Default = 0,
  34. //! A tag.
  35. Tag = 1,
  36. //! A class selector.
  37. ClassSelector = 2,
  38. //! A pseudo class. The list of pseudo classes is defined by keyword
  39. //! set 2.
  40. PseudoClass = 3,
  41. //! An unknown pseudo class.
  42. UnknownPseudoClass = 4,
  43. //! An operator.
  44. Operator = 5,
  45. //! A CSS1 property. The list of CSS1 properties is defined by keyword
  46. //! set 1.
  47. CSS1Property = 6,
  48. //! An unknown property.
  49. UnknownProperty = 7,
  50. //! A value.
  51. Value = 8,
  52. //! A comment.
  53. Comment = 9,
  54. //! An ID selector.
  55. IDSelector = 10,
  56. //! An important value.
  57. Important = 11,
  58. //! An @-rule.
  59. AtRule = 12,
  60. //! A double-quoted string.
  61. DoubleQuotedString = 13,
  62. //! A single-quoted string.
  63. SingleQuotedString = 14,
  64. //! A CSS2 property. The list of CSS2 properties is defined by keyword
  65. //! set 3.
  66. CSS2Property = 15,
  67. //! An attribute.
  68. Attribute = 16,
  69. //! A CSS3 property. The list of CSS3 properties is defined by keyword
  70. //! set 4.
  71. CSS3Property = 17,
  72. //! A pseudo element. The list of pseudo elements is defined by
  73. //! keyword set 5.
  74. PseudoElement = 18,
  75. //! An extended (browser specific) CSS property. The list of extended
  76. //! CSS properties is defined by keyword set 6.
  77. ExtendedCSSProperty = 19,
  78. //! An extended (browser specific) pseudo class. The list of extended
  79. //! pseudo classes is defined by keyword set 7.
  80. ExtendedPseudoClass = 20,
  81. //! An extended (browser specific) pseudo element. The list of
  82. //! extended pseudo elements is defined by keyword set 8.
  83. ExtendedPseudoElement = 21,
  84. //! A media rule.
  85. MediaRule = 22,
  86. //! A variable.
  87. Variable = 23,
  88. };
  89. //! Construct a QsciLexerCSS with parent \a parent. \a parent is typically
  90. //! the QsciScintilla instance.
  91. QsciLexerCSS(QObject *parent = 0);
  92. //! Destroys the QsciLexerCSS instance.
  93. virtual ~QsciLexerCSS();
  94. //! Returns the name of the language.
  95. const char *language() const;
  96. //! Returns the name of the lexer. Some lexers support a number of
  97. //! languages.
  98. const char *lexer() const;
  99. //! \internal Returns a space separated list of words or characters in
  100. //! a particular style that define the end of a block for
  101. //! auto-indentation. The styles is returned via \a style.
  102. const char *blockEnd(int *style = 0) const;
  103. //! \internal Returns a space separated list of words or characters in
  104. //! a particular style that define the start of a block for
  105. //! auto-indentation. The styles is returned via \a style.
  106. const char *blockStart(int *style = 0) const;
  107. //! Returns the string of characters that comprise a word.
  108. const char *wordCharacters() const;
  109. //! Returns the foreground colour of the text for style number \a style.
  110. QColor defaultColor(int style) const;
  111. //! Returns the font for style number \a style.
  112. QFont defaultFont(int style) const;
  113. //! Returns the set of keywords for the keyword set \a set recognised
  114. //! by the lexer as a space separated string.
  115. const char *keywords(int set) const;
  116. //! Returns the descriptive name for style number \a style. If the
  117. //! style is invalid for this language then an empty QString is returned.
  118. //! This is intended to be used in user preference dialogs.
  119. QString description(int style) const;
  120. //! Causes all properties to be refreshed by emitting the
  121. //! propertyChanged() signal as required.
  122. void refreshProperties();
  123. //! Returns true if multi-line comment blocks can be folded.
  124. //!
  125. //! \sa setFoldComments()
  126. bool foldComments() const;
  127. //! Returns true if trailing blank lines are included in a fold block.
  128. //!
  129. //! \sa setFoldCompact()
  130. bool foldCompact() const;
  131. //! If \a enabled is true then support for HSS is enabled. The default is
  132. //! false.
  133. //!
  134. //! \sa HSSLanguage()
  135. void setHSSLanguage(bool enabled);
  136. //! Returns true if support for HSS is enabled.
  137. //!
  138. //! \sa setHSSLanguage()
  139. bool HSSLanguage() const {return hss_language;}
  140. //! If \a enabled is true then support for Less CSS is enabled. The
  141. //! default is false.
  142. //!
  143. //! \sa LessLanguage()
  144. void setLessLanguage(bool enabled);
  145. //! Returns true if support for Less CSS is enabled.
  146. //!
  147. //! \sa setLessLanguage()
  148. bool LessLanguage() const {return less_language;}
  149. //! If \a enabled is true then support for Sassy CSS is enabled. The
  150. //! default is false.
  151. //!
  152. //! \sa SCSSLanguage()
  153. void setSCSSLanguage(bool enabled);
  154. //! Returns true if support for Sassy CSS is enabled.
  155. //!
  156. //! \sa setSCSSLanguage()
  157. bool SCSSLanguage() const {return scss_language;}
  158. public slots:
  159. //! If \a fold is true then multi-line comment blocks can be folded.
  160. //! The default is false.
  161. //!
  162. //! \sa foldComments()
  163. virtual void setFoldComments(bool fold);
  164. //! If \a fold is true then trailing blank lines are included in a fold
  165. //! block. The default is true.
  166. //!
  167. //! \sa foldCompact()
  168. virtual void setFoldCompact(bool fold);
  169. protected:
  170. //! The lexer's properties are read from the settings \a qs. \a prefix
  171. //! (which has a trailing '/') should be used as a prefix to the key of
  172. //! each setting. true is returned if there is no error.
  173. //!
  174. bool readProperties(QSettings &qs,const QString &prefix);
  175. //! The lexer's properties are written to the settings \a qs.
  176. //! \a prefix (which has a trailing '/') should be used as a prefix to
  177. //! the key of each setting. true is returned if there is no error.
  178. //!
  179. bool writeProperties(QSettings &qs,const QString &prefix) const;
  180. private:
  181. void setCommentProp();
  182. void setCompactProp();
  183. void setHSSProp();
  184. void setLessProp();
  185. void setSCSSProp();
  186. bool fold_comments;
  187. bool fold_compact;
  188. bool hss_language;
  189. bool less_language;
  190. bool scss_language;
  191. QsciLexerCSS(const QsciLexerCSS &);
  192. QsciLexerCSS &operator=(const QsciLexerCSS &);
  193. };
  194. #endif