Akonadi Search

akonadisearchsyntaxhighlighter.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "akonadisearchsyntaxhighlighter.h"
8using namespace Akonadi::Search;
9
10AkonadiSearchSyntaxHighlighter::AkonadiSearchSyntaxHighlighter(QTextDocument *doc)
12{
13 init();
14}
15
16AkonadiSearchSyntaxHighlighter::~AkonadiSearchSyntaxHighlighter() = default;
17
18void AkonadiSearchSyntaxHighlighter::highlightBlock(const QString &text)
19{
20 for (const Rule &rule : std::as_const(m_rules)) {
21 QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
22 while (matchIterator.hasNext()) {
24 setFormat(match.capturedStart(), match.capturedLength(), rule.format);
25 }
26 }
27}
28
29void AkonadiSearchSyntaxHighlighter::init()
30{
32 testFormat.setForeground(Qt::black);
33 testFormat.setFontWeight(QFont::Bold);
35 // Collection
36 testType << QStringLiteral("C\\d+");
37
38 // Emails:
39 // From
40 testType << QStringLiteral("\\bF");
41 // To
42 testType << QStringLiteral("\\bT");
43 // CC
44 testType << QStringLiteral("\\bCC");
45 // BC
46 testType << QStringLiteral("\\bBC");
47 // Organization
48 testType << QStringLiteral("\\bO");
49 // Reply To
50 testType << QStringLiteral("\\bRT");
51 // Resent-from
52 testType << QStringLiteral("\\bRF");
53 // List Id
54 testType << QStringLiteral("\\bLI");
55 // X-Loop
56 testType << QStringLiteral("\\bXL");
57 // X-Mailing-List
58 testType << QStringLiteral("\\bXML");
59 // X-Spam-Flag
60 testType << QStringLiteral("\\bXSF");
61 // BO body element
62 testType << QStringLiteral("\\bBO");
63
64 // Contacts:
65 // Name
66 testType << QStringLiteral("\\bNA");
67 // NickName
68 testType << QStringLiteral("\\bNI");
69
70 // Calendar
71 testType << QStringLiteral("\\bO");
72 testType << QStringLiteral("\\bPS");
73 testType << QStringLiteral("\\bS");
74 testType << QStringLiteral("\\bL");
75 for (const QString &s : std::as_const(testType)) {
77 m_rules.append(Rule(regex, testFormat));
78 }
79}
80
81#include "moc_akonadisearchsyntaxhighlighter.cpp"
Akonadi search infrastructure.
Definition core/query.h:21
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
QCA_EXPORT void init()
void append(QList< T > &&value)
T qobject_cast(QObject *object)
void setFormat(int start, int count, const QColor &color)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.