From: Stefan Bund Date: Sat, 4 May 2013 21:49:34 +0000 (+0200) Subject: delay PDF highlighting X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=485c7b2fc01f837dcc5e9b590993b1457b22bd0a;p=pykit.git delay PDF highlighting --- diff --git a/PDFWidget.cc b/PDFWidget.cc index 7203d30..b7ac623 100644 --- a/PDFWidget.cc +++ b/PDFWidget.cc @@ -31,7 +31,7 @@ prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QNetworkAccessManager * { QWebView * webView (dynamic_cast(parent)); if (webView && !id_.isEmpty()) - webView->page()->mainFrame()->addToJavaScriptWindowObject(id_,this); + webView->page()->mainFrame()->addToJavaScriptWindowObject(id_, this); } prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QString const & document, @@ -43,7 +43,7 @@ prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QString const & document document_.reset(Poppler::Document::load(document)); QWebView * webView (dynamic_cast(parent)); if (webView && !id_.isEmpty()) - webView->page()->mainFrame()->addToJavaScriptWindowObject(id_,this); + webView->page()->mainFrame()->addToJavaScriptWindowObject(id_, this); documentSetup(); } @@ -118,18 +118,23 @@ prefix_ void pykit::PDFWidget::documentSetup() document_->setRenderHint(Poppler::Document::TextAntialiasing, true); document_->setRenderHint(Poppler::Document::TextHinting, false); resizeEvent(0); + Poppler::Page::SearchDirection dir (Poppler::Page::FromTop); + highlightAreas_.clear(); + BOOST_FOREACH(QString const & str, highlightStrings_) { + QRectF highlightArea; + while (document_->page(currentPage_)->search(str, highlightArea, dir, + Poppler::Page::CaseInsensitive)) { + highlightAreas_.push_back(highlightArea); + dir = Poppler::Page::NextResult; + } + } showPage(); } prefix_ void pykit::PDFWidget::highlightString(QString const & str) { - QRectF highlightArea; - Poppler::Page::SearchDirection dir (Poppler::Page::FromTop); - while (document_->page(currentPage_)->search(str, highlightArea, dir, - Poppler::Page::CaseInsensitive)) { - highlightAreas_.push_back(highlightArea); - dir = Poppler::Page::NextResult; - } + highlightStrings_.append(str); + documentSetup(); } prefix_ void pykit::PDFWidget::showPage() diff --git a/PDFWidget.hh b/PDFWidget.hh index 1104b48..97c6a5a 100644 --- a/PDFWidget.hh +++ b/PDFWidget.hh @@ -59,6 +59,7 @@ namespace pykit { double dpi_; QRubberBand * rubberBand_; QPoint origin_; + QStringList highlightStrings_; std::vector highlightAreas_; };