// Custom includes
#include <iostream>
+#include <boost/foreach.hpp>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QKeyEvent>
rubberBand_->setGeometry(QRect(origin_, event->pos()).normalized());
}
-prefix_ void pykit::PDFWidget::mouseReleaseEvent(QMouseEvent * event)
+prefix_ void pykit::PDFWidget::mouseReleaseEvent(QMouseEvent *)
{
if (rubberBand_) {
QMatrix matrix (dpi_ / 72.0, 0, 0, dpi_ / 72.0, 0, 0);
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;
+ }
+}
+
prefix_ void pykit::PDFWidget::showPage()
{
if (! document_)
return;
QImage image (document_->page(currentPage_)->renderToImage(
dpi_, dpi_, 0, 0, width(), height()));
+ QMatrix matrix (dpi_ / 72.0, 0, 0, dpi_ / 72.0, 0, 0);
+
+ BOOST_FOREACH(QRectF const & highlightArea, highlightAreas_) {
+ QRect highlightRect = matrix.mapRect(highlightArea).toRect();
+ highlightRect.adjust(-2, -2, 2, 2);
+ QImage highlight = image.copy(highlightRect);
+ QPainter painter;
+ painter.begin(&image);
+ painter.fillRect(image.rect(), QColor(0, 0, 0, 32));
+ painter.drawImage(highlightRect, highlight);
+ painter.end();
+ }
+
setPixmap(QPixmap::fromImage(image));
}
#define HH_PyKit_PDFWidget_ 1
// Custom includes
+#include <vector>
#include <poppler/qt4/poppler-qt4.h>
#include <boost/scoped_ptr.hpp>
#include <QLabel>
~PDFWidget();
void load(QUrl const & url);
+ Q_INVOKABLE void highlightString(QString const & str);
protected:
virtual void resizeEvent(QResizeEvent * event);
double dpi_;
QRubberBand * rubberBand_;
QPoint origin_;
+ std::vector<QRectF> highlightAreas_;
};
}
// c-file-style: "j32"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
-// compile-command: "scons -U"
+// compile-command: "make"
// End: