qscistyle.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // This module implements the QsciStyle 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/qscistyle.h"
  20. #include <qapplication.h>
  21. #include "Qsci/qsciscintillabase.h"
  22. // A ctor.
  23. QsciStyle::QsciStyle(int style)
  24. {
  25. init(style);
  26. QPalette pal = QApplication::palette();
  27. setColor(pal.text().color());
  28. setPaper(pal.base().color());
  29. setFont(QApplication::font());
  30. setEolFill(false);
  31. }
  32. // A ctor.
  33. QsciStyle::QsciStyle(int style, const QString &description,
  34. const QColor &color, const QColor &paper, const QFont &font,
  35. bool eolFill)
  36. {
  37. init(style);
  38. setDescription(description);
  39. setColor(color);
  40. setPaper(paper);
  41. setFont(font);
  42. setEolFill(eolFill);
  43. }
  44. // Initialisation common to all ctors.
  45. void QsciStyle::init(int style)
  46. {
  47. // The next style number to allocate. The initial values corresponds to
  48. // the amount of space that Scintilla initially creates for styles.
  49. static int next_style_nr = 63;
  50. // See if a new style should be allocated. Note that we allow styles to be
  51. // passed in that are bigger than STYLE_MAX because the styles used for
  52. // annotations are allowed to be.
  53. if (style < 0)
  54. {
  55. // Note that we don't deal with the situation where the newly allocated
  56. // style number has already been used explicitly.
  57. if (next_style_nr > QsciScintillaBase::STYLE_LASTPREDEFINED)
  58. style = next_style_nr--;
  59. }
  60. style_nr = style;
  61. // Initialise the minor attributes.
  62. setTextCase(QsciStyle::OriginalCase);
  63. setVisible(true);
  64. setChangeable(true);
  65. setHotspot(false);
  66. }
  67. // Apply the style to a particular editor.
  68. void QsciStyle::apply(QsciScintillaBase *sci) const
  69. {
  70. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETFORE, style_nr,
  71. style_color);
  72. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETBACK, style_nr,
  73. style_paper);
  74. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETFONT, style_nr,
  75. style_font.family().toLatin1().data());
  76. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETSIZEFRACTIONAL, style_nr,
  77. long(style_font.pointSizeF() * QsciScintillaBase::SC_FONT_SIZE_MULTIPLIER));
  78. // Pass the Qt weight via the back door.
  79. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETWEIGHT, style_nr,
  80. -style_font.weight());
  81. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETITALIC, style_nr,
  82. style_font.italic());
  83. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETUNDERLINE, style_nr,
  84. style_font.underline());
  85. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETEOLFILLED, style_nr,
  86. style_eol_fill);
  87. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETCASE, style_nr,
  88. (long)style_case);
  89. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETVISIBLE, style_nr,
  90. style_visible);
  91. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETCHANGEABLE, style_nr,
  92. style_changeable);
  93. sci->SendScintilla(QsciScintillaBase::SCI_STYLESETHOTSPOT, style_nr,
  94. style_hotspot);
  95. }
  96. // Set the color attribute.
  97. void QsciStyle::setColor(const QColor &color)
  98. {
  99. style_color = color;
  100. }
  101. // Set the paper attribute.
  102. void QsciStyle::setPaper(const QColor &paper)
  103. {
  104. style_paper = paper;
  105. }
  106. // Set the font attribute.
  107. void QsciStyle::setFont(const QFont &font)
  108. {
  109. style_font = font;
  110. }
  111. // Set the eol fill attribute.
  112. void QsciStyle::setEolFill(bool eolFill)
  113. {
  114. style_eol_fill = eolFill;
  115. }
  116. // Set the text case attribute.
  117. void QsciStyle::setTextCase(QsciStyle::TextCase text_case)
  118. {
  119. style_case = text_case;
  120. }
  121. // Set the visible attribute.
  122. void QsciStyle::setVisible(bool visible)
  123. {
  124. style_visible = visible;
  125. }
  126. // Set the changeable attribute.
  127. void QsciStyle::setChangeable(bool changeable)
  128. {
  129. style_changeable = changeable;
  130. }
  131. // Set the hotspot attribute.
  132. void QsciStyle::setHotspot(bool hotspot)
  133. {
  134. style_hotspot = hotspot;
  135. }
  136. // Refresh the style. Note that since we had to add apply() then this can't do
  137. // anything useful so we leave it as a no-op.
  138. void QsciStyle::refresh()
  139. {
  140. }