File indexing completed on 2025-03-09 03:57:04

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-19
0007  * Description : syntax highlighter for AdvancedRename utility
0008  *
0009  * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_HIGH_LIGHTER_H
0016 #define DIGIKAM_HIGH_LIGHTER_H
0017 
0018 // Qt includes
0019 
0020 #include <QSyntaxHighlighter>
0021 #include <QRegularExpression>
0022 
0023 class QTextDocument;
0024 
0025 namespace Digikam
0026 {
0027 
0028 class Parser;
0029 
0030 class Highlighter : public QSyntaxHighlighter
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035 
0036     Highlighter(QTextDocument* const document,
0037                 Parser* const _parser);
0038     ~Highlighter()                           override;
0039 
0040 protected:
0041 
0042     void highlightBlock(const QString& text) override;
0043 
0044 private:
0045 
0046     Highlighter(const Highlighter&);
0047     Highlighter& operator=(const Highlighter&);
0048 
0049     void setupHighlightingGrammar();
0050 
0051 private:
0052 
0053     enum PatternType
0054     {
0055         OptionPattern = 0,
0056         ModifierPattern,
0057         QuotedTextPattern,
0058         ParameterPattern
0059     };
0060 
0061     struct HighlightingRule
0062     {
0063         PatternType                type;
0064         QRegularExpression         pattern;
0065         QTextCharFormat            format;
0066     };
0067 
0068 private:
0069 
0070     QVector<HighlightingRule> highlightingRules;
0071     HighlightingRule          quotationRule;
0072 
0073     QTextCharFormat           optionFormat;
0074     QTextCharFormat           parameterFormat;
0075     QTextCharFormat           modifierFormat;
0076     QTextCharFormat           quotationFormat;
0077     QTextCharFormat           errorFormat;
0078 
0079     Parser* const             parser;
0080 };
0081 
0082 } // namespace Digikam
0083 
0084 #endif // DIGIKAM_HIGH_LIGHTER_H