qscilexerproperties.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // This module implements the QsciLexerProperties 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/qscilexerproperties.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerProperties::QsciLexerProperties(QObject *parent)
  25. : QsciLexer(parent), fold_compact(true), initial_spaces(true)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerProperties::~QsciLexerProperties()
  30. {
  31. }
  32. // Returns the language name.
  33. const char *QsciLexerProperties::language() const
  34. {
  35. return "Properties";
  36. }
  37. // Returns the lexer name.
  38. const char *QsciLexerProperties::lexer() const
  39. {
  40. return "props";
  41. }
  42. // Return the string of characters that comprise a word.
  43. const char *QsciLexerProperties::wordCharacters() const
  44. {
  45. return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";
  46. }
  47. // Returns the foreground colour of the text for a style.
  48. QColor QsciLexerProperties::defaultColor(int style) const
  49. {
  50. switch (style)
  51. {
  52. case Comment:
  53. return QColor(0x00,0x7f,0x7f);
  54. case Section:
  55. return QColor(0x7f,0x00,0x7f);
  56. case Assignment:
  57. return QColor(0xb0,0x60,0x00);
  58. case DefaultValue:
  59. return QColor(0x7f,0x7f,0x00);
  60. }
  61. return QsciLexer::defaultColor(style);
  62. }
  63. // Returns the end-of-line fill for a style.
  64. bool QsciLexerProperties::defaultEolFill(int style) const
  65. {
  66. if (style == Section)
  67. return true;
  68. return QsciLexer::defaultEolFill(style);
  69. }
  70. // Returns the font of the text for a style.
  71. QFont QsciLexerProperties::defaultFont(int style) const
  72. {
  73. QFont f;
  74. if (style == Comment)
  75. #if defined(Q_OS_WIN)
  76. f = QFont("Comic Sans MS",9);
  77. #elif defined(Q_OS_MAC)
  78. f = QFont("Comic Sans MS", 12);
  79. #else
  80. f = QFont("Bitstream Vera Serif",9);
  81. #endif
  82. else
  83. f = QsciLexer::defaultFont(style);
  84. return f;
  85. }
  86. // Returns the user name of a style.
  87. QString QsciLexerProperties::description(int style) const
  88. {
  89. switch (style)
  90. {
  91. case Default:
  92. return tr("Default");
  93. case Comment:
  94. return tr("Comment");
  95. case Section:
  96. return tr("Section");
  97. case Assignment:
  98. return tr("Assignment");
  99. case DefaultValue:
  100. return tr("Default value");
  101. case Key:
  102. return tr("Key");
  103. }
  104. return QString();
  105. }
  106. // Returns the background colour of the text for a style.
  107. QColor QsciLexerProperties::defaultPaper(int style) const
  108. {
  109. if (style == Section)
  110. return QColor(0xe0,0xf0,0xf0);
  111. return QsciLexer::defaultPaper(style);
  112. }
  113. // Refresh all properties.
  114. void QsciLexerProperties::refreshProperties()
  115. {
  116. setCompactProp();
  117. setInitialSpacesProp();
  118. }
  119. // Read properties from the settings.
  120. bool QsciLexerProperties::readProperties(QSettings &qs,const QString &prefix)
  121. {
  122. int rc = true;
  123. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  124. initial_spaces = qs.value(prefix + "initialspaces", true).toBool();
  125. return rc;
  126. }
  127. // Write properties to the settings.
  128. bool QsciLexerProperties::writeProperties(QSettings &qs,const QString &prefix) const
  129. {
  130. int rc = true;
  131. qs.setValue(prefix + "foldcompact", fold_compact);
  132. qs.setValue(prefix + "initialspaces", initial_spaces);
  133. return rc;
  134. }
  135. // Set if folds are compact
  136. void QsciLexerProperties::setFoldCompact(bool fold)
  137. {
  138. fold_compact = fold;
  139. setCompactProp();
  140. }
  141. // Set the "fold.compact" property.
  142. void QsciLexerProperties::setCompactProp()
  143. {
  144. emit propertyChanged("fold.compact", (fold_compact ? "1" : "0"));
  145. }
  146. // Set if initial spaces are allowed.
  147. void QsciLexerProperties::setInitialSpaces(bool enable)
  148. {
  149. initial_spaces = enable;
  150. setInitialSpacesProp();
  151. }
  152. // Set the "lexer.props.allow.initial.spaces" property.
  153. void QsciLexerProperties::setInitialSpacesProp()
  154. {
  155. emit propertyChanged("lexer.props.allow.initial.spaces", (fold_compact ? "1" : "0"));
  156. }