qscilexercustom.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // This defines the interface to the QsciLexerCustom 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. #ifndef QSCILEXERCUSTOM_H
  20. #define QSCILEXERCUSTOM_H
  21. #include <Qsci/qsciglobal.h>
  22. #include <Qsci/qscilexer.h>
  23. class QsciScintilla;
  24. class QsciStyle;
  25. //! \brief The QsciLexerCustom class is an abstract class used as a base for
  26. //! new language lexers.
  27. //!
  28. //! The advantage of implementing a new lexer this way (as opposed to adding
  29. //! the lexer to the underlying Scintilla code) is that it does not require the
  30. //! QScintilla library to be re-compiled. It also makes it possible to
  31. //! integrate external lexers.
  32. //!
  33. //! All that is necessary to implement a new lexer is to define appropriate
  34. //! styles and to re-implement the styleText() method.
  35. class QSCINTILLA_EXPORT QsciLexerCustom : public QsciLexer
  36. {
  37. Q_OBJECT
  38. public:
  39. //! Construct a QsciLexerCustom with parent \a parent. \a parent is
  40. //! typically the QsciScintilla instance.
  41. QsciLexerCustom(QObject *parent = 0);
  42. //! Destroy the QSciLexerCustom.
  43. virtual ~QsciLexerCustom();
  44. //! The next \a length characters starting from the current styling
  45. //! position have their style set to style number \a style. The current
  46. //! styling position is moved. The styling position is initially set by
  47. //! calling startStyling().
  48. //!
  49. //! \sa startStyling(), styleText()
  50. void setStyling(int length, int style);
  51. //! The next \a length characters starting from the current styling
  52. //! position have their style set to style \a style. The current styling
  53. //! position is moved. The styling position is initially set by calling
  54. //! startStyling().
  55. //!
  56. //! \sa startStyling(), styleText()
  57. void setStyling(int length, const QsciStyle &style);
  58. //! The styling position is set to \a start. \a styleBits is unused.
  59. //!
  60. //! \sa setStyling(), styleBitsNeeded(), styleText()
  61. void startStyling(int pos, int styleBits = 0);
  62. //! This is called when the section of text beginning at position \a start
  63. //! and up to position \a end needs to be styled. \a start will always be
  64. //! at the start of a line. The text is styled by calling startStyling()
  65. //! followed by one or more calls to setStyling(). It must be
  66. //! re-implemented by a sub-class.
  67. //!
  68. //! \sa setStyling(), startStyling(), QsciScintilla::bytes(),
  69. //! QsciScintilla::text()
  70. virtual void styleText(int start, int end) = 0;
  71. //! \reimp
  72. virtual void setEditor(QsciScintilla *editor);
  73. //! \reimp This re-implementation returns 5 as the number of style bits
  74. //! needed.
  75. virtual int styleBitsNeeded() const;
  76. private slots:
  77. void handleStyleNeeded(int pos);
  78. private:
  79. QsciLexerCustom(const QsciLexerCustom &);
  80. QsciLexerCustom &operator=(const QsciLexerCustom &);
  81. };
  82. #endif