pdf preview: proper highlighting for quoted (inside ") queries

This commit is contained in:
Albert S. 2019-08-19 19:43:05 +02:00
bovenliggende 3d241ad30a
commit 83535960f9
2 gewijzigde bestanden met toevoegingen van 12 en 4 verwijderingen

Bestand weergeven

@ -212,14 +212,22 @@ void MainWindow::makePdfPreview()
scaleText.chop(1);
QVector<QString> wordsToHighlight;
QRegularExpression extractor(R"#("([^"]*)"|(\w+))#");
for(const Token &token : this->currentQuery.getTokens())
{
if(token.type == FILTER_CONTENT_CONTAINS)
{
auto splitted = token.value.split(" ");
for(QString &str : splitted)
QRegularExpressionMatchIterator i = extractor.globalMatch(token.value);
while(i.hasNext())
{
wordsToHighlight.append(str);
QRegularExpressionMatch m = i.next();
QString value = m.captured(1);
if(value.isEmpty())
{
value = m.captured(2);
}
wordsToHighlight.append(value);
}
}
}

Bestand weergeven

@ -88,7 +88,7 @@ struct Renderer
QImage img = pdfPage->renderToImage(scaleX, scaleY);
for(QString & word : wordsToHighlight)
{
QList<QRectF> rects = pdfPage->search(word);
QList<QRectF> rects = pdfPage->search(word, Poppler::Page::CaseInsensitive);
for(QRectF &rect : rects)
{
QPainter painter(&img);