blob: 6565b0603c850b57304cc9e5e42eb411a945fe79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/*
* Copyright (c) 2014 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/QtUI/QtSpellCheckHighlighter.h>
#include <SwifTools/SpellChecker.h>
#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QtSpellCheckHighlighter::QtSpellCheckHighlighter(QTextDocument* parent, SpellChecker* spellChecker) : QSyntaxHighlighter(parent), checker_(spellChecker) {
}
QtSpellCheckHighlighter::~QtSpellCheckHighlighter() {
}
void QtSpellCheckHighlighter::highlightBlock(const QString& text) {
misspelledPositions_.clear();
std::string fragment = Q2PSTRING(text);
checker_->checkFragment(fragment, misspelledPositions_);
QTextCharFormat spellingErrorFormat;
spellingErrorFormat.setUnderlineColor(QColor(Qt::red));
spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
foreach (PositionPair position, misspelledPositions_) {
setFormat(boost::get<0>(position), boost::get<1>(position) - boost::get<0>(position), spellingErrorFormat);
};
}
PositionPairList QtSpellCheckHighlighter::getMisspelledPositions() const {
return misspelledPositions_;
}
}
|