-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewHighlighter.cc
More file actions
44 lines (37 loc) · 1.26 KB
/
Copy pathPreviewHighlighter.cc
File metadata and controls
44 lines (37 loc) · 1.26 KB
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
42
43
44
#include "PreviewHighlighter.h"
#include "FieldStripper.h"
PreviewHighlighter::PreviewHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent)
{
}
void PreviewHighlighter::highlightBlock(const QString & text)
{
QTextCharFormat foundText;
foundText.setFontWeight(QFont::Bold);
foundText.setForeground(Qt::red);
QColor green;
green.setNamedColor("#00CC66");
QTextCharFormat extractedText;
extractedText.setFontWeight(QFont::Bold);
extractedText.setForeground(Qt::white);
extractedText.setBackground(green);
// Pass the search fields and text to FieldStripper:
FieldStripper f;
FieldStripper::StringTable st;
f.strip(searchFields_, text, st);
foreach(auto row, st)
{
for(int i=0; i<row.length(); i++)
{
FieldStripper::FoundText ft=row[i];
if(!ft.first.isEmpty())
{
setFormat(ft.second, searchFields_[i].searchText().length(), foundText);
setFormat(ft.second+searchFields_[i].searchText().length(), searchFields_[i].fieldLength(), extractedText);
}
}
}
}
void PreviewHighlighter::setSearchFields(const SearchFields& searchFields)
{
searchFields_ = searchFields;
}