1 /* 2 This file is part of Lokalize 3 4 SPDX-FileCopyrightText: 2007-2009 Nick Shaforostoff <shafff@ukr.net> 5 SPDX-FileCopyrightText: 2018-2019 Simon Depiets <sdepiets@gmail.com> 6 7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 8 */ 9 10 #ifndef HIGHLIGHTER_H 11 #define HIGHLIGHTER_H 12 13 #include <QSyntaxHighlighter> 14 #include <sonnet/highlighter.h> 15 #include <sonnet/speller.h> 16 #include <kcolorscheme.h> 17 18 #include <QHash> 19 #include <QTextCharFormat> 20 21 22 class QTextEdit; 23 24 class SyntaxHighlighter : public Sonnet::Highlighter 25 { 26 Q_OBJECT 27 28 public: 29 explicit SyntaxHighlighter(QTextEdit *parent); 30 ~SyntaxHighlighter() override = default; 31 setApprovementState(bool a)32 void setApprovementState(bool a) 33 { 34 m_approved = a; 35 } setSourceString(const QString & s)36 void setSourceString(const QString& s) 37 { 38 m_sourceString = s; 39 } 40 41 protected: 42 void highlightBlock(const QString &text) override; 43 44 void setMisspelled(int start, int count) override; 45 void unsetMisspelled(int start, int count) override; 46 47 private Q_SLOTS: 48 void settingsChanged(); 49 50 // void setFormatRetainingUnderlines(int start, int count, QTextCharFormat format); 51 private: 52 struct HighlightingRule { 53 QRegExp pattern; 54 QTextCharFormat format; 55 }; 56 QVector<HighlightingRule> highlightingRules; 57 58 // bool fromDocbook; 59 QTextCharFormat tagFormat; 60 KStatefulBrush tagBrush; 61 bool m_approved; 62 QString m_sourceString; 63 }; 64 65 #endif 66