Show webfinger if displayName is unknown for an author.
[larjonas-pumpa.git] / src / fancyhighlighter.cpp
blob62abc12774cd74533fe082acac29f593a374efe3
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include "fancyhighlighter.h"
22 #include <QRegExp>
24 //------------------------------------------------------------------------------
26 FancyHighlighter::FancyHighlighter(QTextDocument* doc, QASpell* checker) :
27 QSyntaxHighlighter(doc), m_checker(checker) {}
29 //------------------------------------------------------------------------------
31 void FancyHighlighter::highlightBlock(const QString& text) {
32 QTextCharFormat urlHighlightFormat;
33 urlHighlightFormat.setForeground(QBrush(Qt::blue));
35 #ifdef USE_ASPELL
36 int index;
38 QTextCharFormat spellErrorFormat;
39 spellErrorFormat.setFontUnderline(true);
40 spellErrorFormat.setUnderlineColor(Qt::red);
41 spellErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
43 QRegExp rxa("(^|\\s)(\\w[\\w']*\\w)");
45 index = text.indexOf(rxa);
46 while (index >= 0) {
47 int length = rxa.matchedLength();
48 int offset = rxa.cap(1).count();
49 int s = index+offset;
50 int l = length-offset;
52 if (!m_checker->checkWord(rxa.cap(2)))
53 setFormat(s, l, spellErrorFormat);
54 index = text.indexOf(rxa, index + length);
56 #endif // USE_ASPELL