1 | /****************************************************************************
|
2 | **
|
3 | ** Copyright (C) 2016 The Qt Company Ltd.
|
4 | ** Contact: https://www.qt.io/licensing/
|
5 | **
|
6 | ** Copyright (C) 2021 Francesc Martinez
|
7 | ** LinkedIn: www.linkedin.com/in/cescmm/
|
8 | ** Web: www.francescmm.com
|
9 | **
|
10 | ** This file is part of the examples of the Qt Toolkit.
|
11 | **
|
12 | ** $QT_BEGIN_LICENSE:BSD$
|
13 | ** Commercial License Usage
|
14 | ** Licensees holding valid commercial Qt licenses may use this file in
|
15 | ** accordance with the commercial license agreement provided with the
|
16 | ** Software or, alternatively, in accordance with the terms contained in
|
17 | ** a written agreement between you and The Qt Company. For licensing terms
|
18 | ** and conditions see https://www.qt.io/terms-conditions. For further
|
19 | ** information use the contact form at https://www.qt.io/contact-us.
|
20 | **
|
21 | ** BSD License Usage
|
22 | ** Alternatively, you may use this file under the terms of the BSD license
|
23 | ** as follows:
|
24 | **
|
25 | ** "Redistribution and use in source and binary forms, with or without
|
26 | ** modification, are permitted provided that the following conditions are
|
27 | ** met:
|
28 | ** * Redistributions of source code must retain the above copyright
|
29 | ** notice, this list of conditions and the following disclaimer.
|
30 | ** * Redistributions in binary form must reproduce the above copyright
|
31 | ** notice, this list of conditions and the following disclaimer in
|
32 | ** the documentation and/or other materials provided with the
|
33 | ** distribution.
|
34 | ** * Neither the name of The Qt Company Ltd nor the names of its
|
35 | ** contributors may be used to endorse or promote products derived
|
36 | ** from this software without specific prior written permission.
|
37 | **
|
38 | **
|
39 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
40 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
41 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
42 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
43 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
44 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
45 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
46 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
47 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
48 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
49 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
50 | **
|
51 | ** $QT_END_LICENSE$
|
52 | **
|
53 | ****************************************************************************/
|
54 |
|
55 | #ifndef HIGHLIGHTER_H
|
56 | #define HIGHLIGHTER_H
|
57 |
|
58 | #include <QRegularExpression>
|
59 | #include <QSyntaxHighlighter>
|
60 | #include <QTextCharFormat>
|
61 |
|
62 | QT_BEGIN_NAMESPACE
|
63 | class QTextDocument;
|
64 | QT_END_NAMESPACE
|
65 |
|
66 | class Highlighter : public QSyntaxHighlighter
|
67 | {
|
68 | Q_OBJECT
|
69 |
|
70 | public:
|
71 | struct HighlightingRule
|
72 | {
|
73 | QRegularExpression pattern;
|
74 | QTextCharFormat format;
|
75 | };
|
76 |
|
77 | Highlighter(QTextDocument *parent = 0);
|
78 |
|
79 | protected:
|
80 | void highlightBlock(const QString &text) override;
|
81 |
|
82 | private:
|
83 | QRegularExpression ;
|
84 | QRegularExpression ;
|
85 | static QVector<HighlightingRule> highlightingRules;
|
86 |
|
87 | QTextCharFormat ;
|
88 | };
|
89 |
|
90 | #endif // HIGHLIGHTER_H
|
91 | |