pdf preview: proper highlighting for quoted (inside ") queries
This commit is contained in:
父節點
afba31177c
當前提交
bdf235f21b
@ -217,14 +217,21 @@ void MainWindow::makePdfPreview()
|
|||||||
scaleText.chop(1);
|
scaleText.chop(1);
|
||||||
|
|
||||||
QVector<QString> wordsToHighlight;
|
QVector<QString> wordsToHighlight;
|
||||||
|
QRegularExpression extractor(R"#("([^"]*)"|(\w+))#");
|
||||||
for(const Token &token : this->currentQuery.getTokens())
|
for(const Token &token : this->currentQuery.getTokens())
|
||||||
{
|
{
|
||||||
if(token.type == FILTER_CONTENT_CONTAINS)
|
if(token.type == FILTER_CONTENT_CONTAINS)
|
||||||
{
|
{
|
||||||
auto splitted = token.value.split(" ");
|
QRegularExpressionMatchIterator i = extractor.globalMatch(token.value);
|
||||||
for(QString &str : splitted)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ struct Renderer
|
|||||||
QImage img = pdfPage->renderToImage(scaleX, scaleY);
|
QImage img = pdfPage->renderToImage(scaleX, scaleY);
|
||||||
for(QString &word : wordsToHighlight)
|
for(QString &word : wordsToHighlight)
|
||||||
{
|
{
|
||||||
QList<QRectF> rects = pdfPage->search(word);
|
QList<QRectF> rects = pdfPage->search(word, Poppler::Page::CaseInsensitive);
|
||||||
for(QRectF &rect : rects)
|
for(QRectF &rect : rects)
|
||||||
{
|
{
|
||||||
QPainter painter(&img);
|
QPainter painter(&img);
|
||||||
|
載入中…
新增問題並參考
Block a user