qscilexerbatch.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // This module implements the QsciLexerBatch 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/qscilexerbatch.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerBatch::QsciLexerBatch(QObject *parent)
  25. : QsciLexer(parent)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerBatch::~QsciLexerBatch()
  30. {
  31. }
  32. // Returns the language name.
  33. const char *QsciLexerBatch::language() const
  34. {
  35. return "Batch";
  36. }
  37. // Returns the lexer name.
  38. const char *QsciLexerBatch::lexer() const
  39. {
  40. return "batch";
  41. }
  42. // Return the string of characters that comprise a word.
  43. const char *QsciLexerBatch::wordCharacters() const
  44. {
  45. return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";
  46. }
  47. // Returns the foreground colour of the text for a style.
  48. QColor QsciLexerBatch::defaultColor(int style) const
  49. {
  50. switch (style)
  51. {
  52. case Default:
  53. case Operator:
  54. return QColor(0x00,0x00,0x00);
  55. case Comment:
  56. return QColor(0x00,0x7f,0x00);
  57. case Keyword:
  58. case ExternalCommand:
  59. return QColor(0x00,0x00,0x7f);
  60. case Label:
  61. return QColor(0x7f,0x00,0x7f);
  62. case HideCommandChar:
  63. return QColor(0x7f,0x7f,0x00);
  64. case Variable:
  65. return QColor(0x80,0x00,0x80);
  66. }
  67. return QsciLexer::defaultColor(style);
  68. }
  69. // Returns the end-of-line fill for a style.
  70. bool QsciLexerBatch::defaultEolFill(int style) const
  71. {
  72. switch (style)
  73. {
  74. case Label:
  75. return true;
  76. }
  77. return QsciLexer::defaultEolFill(style);
  78. }
  79. // Returns the font of the text for a style.
  80. QFont QsciLexerBatch::defaultFont(int style) const
  81. {
  82. QFont f;
  83. switch (style)
  84. {
  85. case Comment:
  86. #if defined(Q_OS_WIN)
  87. f = QFont("Comic Sans MS",9);
  88. #elif defined(Q_OS_MAC)
  89. f = QFont("Comic Sans MS", 12);
  90. #else
  91. f = QFont("Bitstream Vera Serif",9);
  92. #endif
  93. break;
  94. case Keyword:
  95. f = QsciLexer::defaultFont(style);
  96. f.setBold(true);
  97. break;
  98. case ExternalCommand:
  99. #if defined(Q_OS_WIN)
  100. f = QFont("Courier New",10);
  101. #elif defined(Q_OS_MAC)
  102. f = QFont("Courier", 12);
  103. #else
  104. f = QFont("Bitstream Vera Sans Mono",9);
  105. #endif
  106. f.setBold(true);
  107. break;
  108. default:
  109. f = QsciLexer::defaultFont(style);
  110. }
  111. return f;
  112. }
  113. // Returns the set of keywords.
  114. const char *QsciLexerBatch::keywords(int set) const
  115. {
  116. if (set == 1)
  117. return
  118. "rem set if exist errorlevel for in do break call "
  119. "chcp cd chdir choice cls country ctty date del "
  120. "erase dir echo exit goto loadfix loadhigh mkdir md "
  121. "move path pause prompt rename ren rmdir rd shift "
  122. "time type ver verify vol com con lpt nul";
  123. return 0;
  124. }
  125. // Return the case sensitivity.
  126. bool QsciLexerBatch::caseSensitive() const
  127. {
  128. return false;
  129. }
  130. // Returns the user name of a style.
  131. QString QsciLexerBatch::description(int style) const
  132. {
  133. switch (style)
  134. {
  135. case Default:
  136. return tr("Default");
  137. case Comment:
  138. return tr("Comment");
  139. case Keyword:
  140. return tr("Keyword");
  141. case Label:
  142. return tr("Label");
  143. case HideCommandChar:
  144. return tr("Hide command character");
  145. case ExternalCommand:
  146. return tr("External command");
  147. case Variable:
  148. return tr("Variable");
  149. case Operator:
  150. return tr("Operator");
  151. }
  152. return QString();
  153. }
  154. // Returns the background colour of the text for a style.
  155. QColor QsciLexerBatch::defaultPaper(int style) const
  156. {
  157. switch (style)
  158. {
  159. case Label:
  160. return QColor(0x60,0x60,0x60);
  161. }
  162. return QsciLexer::defaultPaper(style);
  163. }