qscilexerpo.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // This module implements the QsciLexerPO 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/qscilexerpo.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. // The ctor.
  24. QsciLexerPO::QsciLexerPO(QObject *parent)
  25. : QsciLexer(parent), fold_comments(false), fold_compact(true)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerPO::~QsciLexerPO()
  30. {
  31. }
  32. // Returns the language name.
  33. const char *QsciLexerPO::language() const
  34. {
  35. return "PO";
  36. }
  37. // Returns the lexer name.
  38. const char *QsciLexerPO::lexer() const
  39. {
  40. return "po";
  41. }
  42. // Returns the foreground colour of the text for a style.
  43. QColor QsciLexerPO::defaultColor(int style) const
  44. {
  45. switch (style)
  46. {
  47. case Comment:
  48. return QColor(0x00, 0x7f, 0x00);
  49. }
  50. return QsciLexer::defaultColor(style);
  51. }
  52. // Returns the font of the text for a style.
  53. QFont QsciLexerPO::defaultFont(int style) const
  54. {
  55. QFont f;
  56. switch (style)
  57. {
  58. case Comment:
  59. #if defined(Q_OS_WIN)
  60. f = QFont("Comic Sans MS", 9);
  61. #elif defined(Q_OS_MAC)
  62. f = QFont("Georgia", 13);
  63. #else
  64. f = QFont("Bitstream Vera Serif", 9);
  65. #endif
  66. break;
  67. default:
  68. f = QsciLexer::defaultFont(style);
  69. }
  70. return f;
  71. }
  72. // Returns the user name of a style.
  73. QString QsciLexerPO::description(int style) const
  74. {
  75. switch (style)
  76. {
  77. case Default:
  78. return tr("Default");
  79. case Comment:
  80. return tr("Comment");
  81. case MessageId:
  82. return tr("Message identifier");
  83. case MessageIdText:
  84. return tr("Message identifier text");
  85. case MessageString:
  86. return tr("Message string");
  87. case MessageStringText:
  88. return tr("Message string text");
  89. case MessageContext:
  90. return tr("Message context");
  91. case MessageContextText:
  92. return tr("Message context text");
  93. case Fuzzy:
  94. return tr("Fuzzy flag");
  95. case ProgrammerComment:
  96. return tr("Programmer comment");
  97. case Reference:
  98. return tr("Reference");
  99. case Flags:
  100. return tr("Flags");
  101. case MessageIdTextEOL:
  102. return tr("Message identifier text end-of-line");
  103. case MessageStringTextEOL:
  104. return tr("Message string text end-of-line");
  105. case MessageContextTextEOL:
  106. return tr("Message context text end-of-line");
  107. }
  108. return QString();
  109. }
  110. // Refresh all properties.
  111. void QsciLexerPO::refreshProperties()
  112. {
  113. setCommentProp();
  114. setCompactProp();
  115. }
  116. // Read properties from the settings.
  117. bool QsciLexerPO::readProperties(QSettings &qs,const QString &prefix)
  118. {
  119. int rc = true;
  120. fold_comments = qs.value(prefix + "foldcomments", false).toBool();
  121. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  122. return rc;
  123. }
  124. // Write properties to the settings.
  125. bool QsciLexerPO::writeProperties(QSettings &qs,const QString &prefix) const
  126. {
  127. int rc = true;
  128. qs.setValue(prefix + "foldcomments", fold_comments);
  129. qs.setValue(prefix + "foldcompact", fold_compact);
  130. return rc;
  131. }
  132. // Return true if comments can be folded.
  133. bool QsciLexerPO::foldComments() const
  134. {
  135. return fold_comments;
  136. }
  137. // Set if comments can be folded.
  138. void QsciLexerPO::setFoldComments(bool fold)
  139. {
  140. fold_comments = fold;
  141. setCommentProp();
  142. }
  143. // Set the "fold.comment" property.
  144. void QsciLexerPO::setCommentProp()
  145. {
  146. emit propertyChanged("fold.comment",(fold_comments ? "1" : "0"));
  147. }
  148. // Return true if folds are compact.
  149. bool QsciLexerPO::foldCompact() const
  150. {
  151. return fold_compact;
  152. }
  153. // Set if folds are compact
  154. void QsciLexerPO::setFoldCompact(bool fold)
  155. {
  156. fold_compact = fold;
  157. setCompactProp();
  158. }
  159. // Set the "fold.compact" property.
  160. void QsciLexerPO::setCompactProp()
  161. {
  162. emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
  163. }