digiKam
highlighter.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2009-11-19
7  * Description : syntax highlighter for AdvancedRename utility
8  *
9  * Copyright (C) 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_HIGH_LIGHTER_H
25 #define DIGIKAM_HIGH_LIGHTER_H
26 
27 // Qt includes
28 
29 #include <QSyntaxHighlighter>
30 #include <QRegularExpression>
31 
32 class QTextDocument;
33 
34 namespace Digikam
35 {
36 
37 class Parser;
38 
39 class Highlighter : public QSyntaxHighlighter
40 {
41  Q_OBJECT
42 
43 public:
44 
45  Highlighter(QTextDocument* const document,
46  Parser* const _parser);
47  ~Highlighter() override;
48 
49 protected:
50 
51  void highlightBlock(const QString& text) override;
52 
53 private:
54 
55  Highlighter(const Highlighter&);
56  Highlighter& operator=(const Highlighter&);
57 
58  void setupHighlightingGrammar();
59 
60 private:
61 
62  enum PatternType
63  {
64  OptionPattern = 0,
65  ModifierPattern,
66  QuotedTextPattern,
67  ParameterPattern
68  };
69 
70  struct HighlightingRule
71  {
72  PatternType type;
73  QRegularExpression pattern;
74  QTextCharFormat format;
75  };
76 
77 private:
78 
79  QVector<HighlightingRule> highlightingRules;
80  HighlightingRule quotationRule;
81 
82  QTextCharFormat optionFormat;
83  QTextCharFormat parameterFormat;
84  QTextCharFormat modifierFormat;
85  QTextCharFormat quotationFormat;
86  QTextCharFormat errorFormat;
87 
88  Parser* const parser;
89 };
90 
91 } // namespace Digikam
92 
93 #endif // DIGIKAM_HIGH_LIGHTER_H
Definition: highlighter.h:40
void highlightBlock(const QString &text) override
Definition: highlighter.cpp:49
Highlighter(QTextDocument *const document, Parser *const _parser)
Definition: highlighter.cpp:37
~Highlighter() override
Definition: highlighter.cpp:45
Definition: parser.h:45
Definition: datefolderview.cpp:43