qscilexermatlab.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // This module implements the QsciLexerMatlab 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/qscilexermatlab.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. // The ctor.
  23. QsciLexerMatlab::QsciLexerMatlab(QObject *parent)
  24. : QsciLexer(parent)
  25. {
  26. }
  27. // The dtor.
  28. QsciLexerMatlab::~QsciLexerMatlab()
  29. {
  30. }
  31. // Returns the language name.
  32. const char *QsciLexerMatlab::language() const
  33. {
  34. return "Matlab";
  35. }
  36. // Returns the lexer name.
  37. const char *QsciLexerMatlab::lexer() const
  38. {
  39. return "matlab";
  40. }
  41. // Returns the foreground colour of the text for a style.
  42. QColor QsciLexerMatlab::defaultColor(int style) const
  43. {
  44. switch (style)
  45. {
  46. case Default:
  47. case Operator:
  48. return QColor(0x00,0x00,0x00);
  49. case Comment:
  50. return QColor(0x00,0x7f,0x00);
  51. case Command:
  52. return QColor(0x7f,0x7f,0x00);
  53. case Number:
  54. return QColor(0x00,0x7f,0x7f);
  55. case Keyword:
  56. return QColor(0x00,0x00,0x7f);
  57. case SingleQuotedString:
  58. case DoubleQuotedString:
  59. return QColor(0x7f,0x00,0x7f);
  60. }
  61. return QsciLexer::defaultColor(style);
  62. }
  63. // Returns the font of the text for a style.
  64. QFont QsciLexerMatlab::defaultFont(int style) const
  65. {
  66. QFont f;
  67. switch (style)
  68. {
  69. case Comment:
  70. #if defined(Q_OS_WIN)
  71. f = QFont("Comic Sans MS",9);
  72. #elif defined(Q_OS_MAC)
  73. f = QFont("Comic Sans MS", 12);
  74. #else
  75. f = QFont("Bitstream Vera Serif",9);
  76. #endif
  77. break;
  78. case Keyword:
  79. case Operator:
  80. f = QsciLexer::defaultFont(style);
  81. f.setBold(true);
  82. break;
  83. default:
  84. f = QsciLexer::defaultFont(style);
  85. }
  86. return f;
  87. }
  88. // Returns the set of keywords.
  89. const char *QsciLexerMatlab::keywords(int set) const
  90. {
  91. if (set == 1)
  92. return
  93. "break case catch continue else elseif end for function "
  94. "global if otherwise persistent return switch try while";
  95. return 0;
  96. }
  97. // Returns the user name of a style.
  98. QString QsciLexerMatlab::description(int style) const
  99. {
  100. switch (style)
  101. {
  102. case Default:
  103. return tr("Default");
  104. case Comment:
  105. return tr("Comment");
  106. case Command:
  107. return tr("Command");
  108. case Number:
  109. return tr("Number");
  110. case Keyword:
  111. return tr("Keyword");
  112. case SingleQuotedString:
  113. return tr("Single-quoted string");
  114. case Operator:
  115. return tr("Operator");
  116. case Identifier:
  117. return tr("Identifier");
  118. case DoubleQuotedString:
  119. return tr("Double-quoted string");
  120. }
  121. return QString();
  122. }