• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • adblock
adblocksyntaxhighlighter.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "adblocksyntaxhighlighter.h"
19 
20 using namespace MessageViewer;
21 
22 AdBlockSyntaxHighlighter::AdBlockSyntaxHighlighter(QTextDocument *doc)
23  : QSyntaxHighlighter(doc)
24 {
25  init();
26 }
27 
28 AdBlockSyntaxHighlighter::~AdBlockSyntaxHighlighter()
29 {
30 }
31 
32 void AdBlockSyntaxHighlighter::highlightBlock(const QString &text)
33 {
34  Q_FOREACH (const Rule &rule, m_rules) {
35  const QRegExp expression(rule.pattern);
36  int index = expression.indexIn(text);
37  int length = 0;
38  while (index >= 0 && ( length = expression.matchedLength() ) > 0 ) {
39  setFormat(index, length, rule.format);
40  index = expression.indexIn(text, index + length);
41  }
42  }
43 }
44 
45 void AdBlockSyntaxHighlighter::init()
46 {
47  QTextCharFormat commentFormat;
48  commentFormat.setForeground( Qt::darkYellow );
49  QRegExp commentRegex( QLatin1String( "^!.*" ) );
50  m_rules.append( Rule( commentRegex, commentFormat ) );
51 
52  QTextCharFormat exceptionFormat;
53  exceptionFormat.setForeground( Qt::magenta );
54  QRegExp exceptionRegex( QLatin1String( "^@@.*" ) );
55  m_rules.append( Rule( exceptionRegex, exceptionFormat ) );
56 
57  QTextCharFormat headerFormat;
58  headerFormat.setForeground( Qt::red );
59  QRegExp headerRegex( QLatin1String( "^\\[.*" ) );
60  m_rules.append( Rule( headerRegex, headerFormat ) );
61 
62  QTextCharFormat elementFormat;
63  elementFormat.setForeground( Qt::blue );
64  QRegExp elementRegex( QLatin1String( ".*##.*" ) );
65  m_rules.append( Rule( elementRegex, elementFormat ) );
66 }
67 
68 #include "adblocksyntaxhighlighter.moc"
adblocksyntaxhighlighter.h
MessageViewer::AdBlockSyntaxHighlighter::AdBlockSyntaxHighlighter
AdBlockSyntaxHighlighter(QTextDocument *doc)
Definition: adblocksyntaxhighlighter.cpp:22
MessageViewer::AdBlockSyntaxHighlighter::~AdBlockSyntaxHighlighter
~AdBlockSyntaxHighlighter()
Definition: adblocksyntaxhighlighter.cpp:28
QSyntaxHighlighter
MessageViewer::AdBlockSyntaxHighlighter::highlightBlock
void highlightBlock(const QString &text)
Definition: adblocksyntaxhighlighter.cpp:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal