delay PDF highlighting
Stefan Bund [Sat, 4 May 2013 21:49:34 +0000 (23:49 +0200)]
PDFWidget.cc
PDFWidget.hh

index 7203d30..b7ac623 100644 (file)
@@ -31,7 +31,7 @@ prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QNetworkAccessManager *
 {
     QWebView * webView (dynamic_cast<QWebView*>(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<QWebView*>(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()
index 1104b48..97c6a5a 100644 (file)
@@ -59,6 +59,7 @@ namespace pykit {
         double dpi_;
         QRubberBand * rubberBand_;
         QPoint origin_;
+        QStringList highlightStrings_;
         std::vector<QRectF> highlightAreas_;
     };