| 1 | /* | 
 
 
 
 
 | 2 | * | 
 
 
 
 
 | 3 | The MIT License (MIT) | 
 
 
 
 
 | 4 |  | 
 
 
 
 
 | 5 | Copyright (c) 2015 Dmitry Ivanov | 
 
 
 
 
 | 6 |  | 
 
 
 
 
 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy | 
 
 
 
 
 | 8 | of this software and associated documentation files (the "Software"), to deal | 
 
 
 
 
 | 9 | in the Software without restriction, including without limitation the rights | 
 
 
 
 
 | 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
 
 
 
 
 | 11 | copies of the Software, and to permit persons to whom the Software is | 
 
 
 
 
 | 12 | furnished to do so, subject to the following conditions: | 
 
 
 
 
 | 13 |  | 
 
 
 
 
 | 14 | The above copyright notice and this permission notice shall be included in | 
 
 
 
 
 | 15 | all copies or substantial portions of the Software. | 
 
 
 
 
 | 16 |  | 
 
 
 
 
 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
 
 
 
 
 | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
 
 
 
 
 | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
 
 
 
 
 | 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
 
 
 
 
 | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
 
 
 
 
 | 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
 
 
 
 
 | 23 | THE SOFTWARE. | 
 
 
 
 
 | 24 | * | 
 
 
 
 
 | 25 | */ | 
 
 
 
 
 | 26 |  | 
 
 
 
 
 | 27 | // This XML highligter is the same from Dmitry Ivanov available here: | 
 
 
 
 
 | 28 | // https://github.com/d1vanov/basic-xml-syntax-highlighter | 
 
 
 
 
 | 29 | // with some slightly modifications by random-guy (https://github.com/random-guy) | 
 
 
 
 
 | 30 | // (like different colors, and remove of unneeded constructors) | 
 
 
 
 
 | 31 |  | 
 
 
 
 
 | 32 | #ifndef BASIC_XML_SYNTAX_HIGHLIGHTER_H | 
 
 
 
 
 | 33 | #define BASIC_XML_SYNTAX_HIGHLIGHTER_H | 
 
 
 
 
 | 34 |  | 
 
 
 
 
 | 35 | #include <QSyntaxHighlighter> | 
 
 
 
 
 | 36 | #include <QTextEdit> | 
 
 
 
 
 | 37 |  | 
 
 
 
 
 | 38 | class BasicXMLSyntaxHighlighter : public QSyntaxHighlighter | 
 
 
 
 
 | 39 | { | 
 
 
 
 
 | 40 | Q_OBJECT | 
 
 
 
 
 | 41 | public: | 
 
 
 
 
 | 42 | BasicXMLSyntaxHighlighter(QTextDocument * parent = nullptr); | 
 
 
 
 
 | 43 |  | 
 
 
 
 
 | 44 | protected: | 
 
 
 
 
 | 45 | virtual void highlightBlock(const QString & text); | 
 
 
 
 
 | 46 |  | 
 
 
 
 
 | 47 | private: | 
 
 
 
 
 | 48 | void highlightByRegex(const QTextCharFormat & format, | 
 
 
 
 
 | 49 | const QRegExp & regex, const QString & text); | 
 
 
 
 
 | 50 |  | 
 
 
 
 
 | 51 | void setRegexes(); | 
 
 
 
 
 | 52 | void setFormats(); | 
 
 
 
 
 | 53 |  | 
 
 
 
 
 | 54 | private: | 
 
 
 
 
 | 55 | QTextCharFormat     m_xmlKeywordFormat; | 
 
 
 
 
 | 56 | QTextCharFormat     m_xmlElementFormat; | 
 
 
 
 
 | 57 | QTextCharFormat     m_xmlAttributeFormat; | 
 
 
 
 
 | 58 | QTextCharFormat     m_xmlValueFormat; | 
 
 
 
 
 | 59 | QTextCharFormat     m_xmlCommentFormat; | 
 
 
 
 
 | 60 |  | 
 
 
 
 
 | 61 | QList<QRegExp>      m_xmlKeywordRegexes; | 
 
 
 
 
 | 62 | QRegExp             m_xmlElementRegex; | 
 
 
 
 
 | 63 | QRegExp             m_xmlAttributeRegex; | 
 
 
 
 
 | 64 | QRegExp             m_xmlValueRegex; | 
 
 
 
 
 | 65 | QRegExp             m_xmlCommentRegex; | 
 
 
 
 
 | 66 | }; | 
 
 
 
 
 | 67 |  | 
 
 
 
 
 | 68 | #endif // BASIC_XML_SYNTAX_HIGHLIGHTER_H |