qscilexerxml.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // This module implements the QsciLexerXML 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. #include "Qsci/qscilexerxml.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerXML::QsciLexerXML(QObject *parent)
  25. : QsciLexerHTML(parent), scripts(true)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerXML::~QsciLexerXML()
  30. {
  31. }
  32. // Returns the language name.
  33. const char *QsciLexerXML::language() const
  34. {
  35. return "XML";
  36. }
  37. // Returns the lexer name.
  38. const char *QsciLexerXML::lexer() const
  39. {
  40. return "xml";
  41. }
  42. // Returns the foreground colour of the text for a style.
  43. QColor QsciLexerXML::defaultColor(int style) const
  44. {
  45. switch (style)
  46. {
  47. case Default:
  48. return QColor(0x00,0x00,0x00);
  49. case Tag:
  50. case UnknownTag:
  51. case XMLTagEnd:
  52. case SGMLDefault:
  53. case SGMLCommand:
  54. return QColor(0x00,0x00,0x80);
  55. case Attribute:
  56. case UnknownAttribute:
  57. return QColor(0x00,0x80,0x80);
  58. case HTMLNumber:
  59. return QColor(0x00,0x7f,0x7f);
  60. case HTMLDoubleQuotedString:
  61. case HTMLSingleQuotedString:
  62. return QColor(0x7f,0x00,0x7f);
  63. case OtherInTag:
  64. case Entity:
  65. case XMLStart:
  66. case XMLEnd:
  67. return QColor(0x80,0x00,0x80);
  68. case HTMLComment:
  69. case SGMLComment:
  70. return QColor(0x80,0x80,0x00);
  71. case CDATA:
  72. case PHPStart:
  73. case SGMLDoubleQuotedString:
  74. case SGMLError:
  75. return QColor(0x80,0x00,0x00);
  76. case HTMLValue:
  77. return QColor(0x60,0x80,0x60);
  78. case SGMLParameter:
  79. return QColor(0x00,0x66,0x00);
  80. case SGMLSingleQuotedString:
  81. return QColor(0x99,0x33,0x00);
  82. case SGMLSpecial:
  83. return QColor(0x33,0x66,0xff);
  84. case SGMLEntity:
  85. return QColor(0x33,0x33,0x33);
  86. case SGMLBlockDefault:
  87. return QColor(0x00,0x00,0x66);
  88. }
  89. return QsciLexerHTML::defaultColor(style);
  90. }
  91. // Returns the end-of-line fill for a style.
  92. bool QsciLexerXML::defaultEolFill(int style) const
  93. {
  94. if (style == CDATA)
  95. return true;
  96. return QsciLexerHTML::defaultEolFill(style);
  97. }
  98. // Returns the font of the text for a style.
  99. QFont QsciLexerXML::defaultFont(int style) const
  100. {
  101. QFont f;
  102. switch (style)
  103. {
  104. case Default:
  105. case Entity:
  106. case CDATA:
  107. #if defined(Q_OS_WIN)
  108. f = QFont("Times New Roman",11);
  109. #elif defined(Q_OS_MAC)
  110. f = QFont("Times New Roman", 12);
  111. #else
  112. f = QFont("Bitstream Charter",10);
  113. #endif
  114. break;
  115. case XMLStart:
  116. case XMLEnd:
  117. case SGMLCommand:
  118. f = QsciLexer::defaultFont(style);
  119. f.setBold(true);
  120. break;
  121. default:
  122. f = QsciLexerHTML::defaultFont(style);
  123. }
  124. return f;
  125. }
  126. // Returns the set of keywords.
  127. const char *QsciLexerXML::keywords(int set) const
  128. {
  129. if (set == 6)
  130. return QsciLexerHTML::keywords(set);
  131. return 0;
  132. }
  133. // Returns the background colour of the text for a style.
  134. QColor QsciLexerXML::defaultPaper(int style) const
  135. {
  136. switch (style)
  137. {
  138. case CDATA:
  139. return QColor(0xff,0xf0,0xf0);
  140. case SGMLDefault:
  141. case SGMLCommand:
  142. case SGMLParameter:
  143. case SGMLDoubleQuotedString:
  144. case SGMLSingleQuotedString:
  145. case SGMLSpecial:
  146. case SGMLEntity:
  147. case SGMLComment:
  148. return QColor(0xef,0xef,0xff);
  149. case SGMLError:
  150. return QColor(0xff,0x66,0x66);
  151. case SGMLBlockDefault:
  152. return QColor(0xcc,0xcc,0xe0);
  153. }
  154. return QsciLexerHTML::defaultPaper(style);
  155. }
  156. // Refresh all properties.
  157. void QsciLexerXML::refreshProperties()
  158. {
  159. setScriptsProp();
  160. }
  161. // Read properties from the settings.
  162. bool QsciLexerXML::readProperties(QSettings &qs, const QString &prefix)
  163. {
  164. int rc = QsciLexerHTML::readProperties(qs, prefix);
  165. scripts = qs.value(prefix + "scriptsstyled", true).toBool();
  166. return rc;
  167. }
  168. // Write properties to the settings.
  169. bool QsciLexerXML::writeProperties(QSettings &qs, const QString &prefix) const
  170. {
  171. int rc = QsciLexerHTML::writeProperties(qs, prefix);
  172. qs.setValue(prefix + "scriptsstyled", scripts);
  173. return rc;
  174. }
  175. // Return true if scripts are styled.
  176. bool QsciLexerXML::scriptsStyled() const
  177. {
  178. return scripts;
  179. }
  180. // Set if scripts are styled.
  181. void QsciLexerXML::setScriptsStyled(bool styled)
  182. {
  183. scripts = styled;
  184. setScriptsProp();
  185. }
  186. // Set the "lexer.xml.allow.scripts" property.
  187. void QsciLexerXML::setScriptsProp()
  188. {
  189. emit propertyChanged("lexer.xml.allow.scripts",(scripts ? "1" : "0"));
  190. }