#include <QKeyEvent>
#include <QWebView>
#include <QWebFrame>
+#include <QApplication>
+#include <QClipboard>
//#include "PDFWidget.mpp"
#define prefix_
prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QNetworkAccessManager * manager,
QWidget * parent)
- : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0)
+ : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0), rubberBand_ (0)
{
QWebView * webView (dynamic_cast<QWebView*>(parent));
prefix_ pykit::PDFWidget::PDFWidget(QString const & id, QString const & document,
QNetworkAccessManager * manager, QWidget * parent)
- : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0)
+ : QLabel(parent), id_ (id), manager_ (manager), currentPage_ (0), rubberBand_ (0)
{
setFocusPolicy(Qt::WheelFocus);
documentSetup();
}
+prefix_ pykit::PDFWidget::~PDFWidget()
+{
+ if (rubberBand_)
+ delete rubberBand_;
+}
+
+
prefix_ void pykit::PDFWidget::load(QUrl const & url)
{
QNetworkRequest request (url);
return;
QSizeF pageSize (document_->page(currentPage_)->pageSizeF());
double n = 72.0 * width() / pageSize.width();
- if (n != dpi_) {
+ if (n != dpi_) {
dpi_ = n;
showPage();
}
}
+prefix_ void pykit::PDFWidget::mousePressEvent(QMouseEvent * event)
+{
+ origin_ = event->pos();
+ if (! rubberBand_)
+ rubberBand_ = new QRubberBand(QRubberBand::Rectangle, this);
+ rubberBand_->setGeometry(QRect(origin_, QSize()));
+ rubberBand_->show();
+}
+
+prefix_ void pykit::PDFWidget::mouseMoveEvent(QMouseEvent * event)
+{
+ if (rubberBand_)
+ rubberBand_->setGeometry(QRect(origin_, event->pos()).normalized());
+}
+
+prefix_ void pykit::PDFWidget::mouseReleaseEvent(QMouseEvent * event)
+{
+ if (rubberBand_) {
+ QMatrix matrix (dpi_ / 72.0, 0, 0, dpi_ / 72.0, 0, 0);
+ QRectF rect (matrix.inverted().mapRect(QRect(rubberBand_->pos(), rubberBand_->size())));
+ QString text = document_->page(currentPage_)->text(rect);
+ if (! text.isEmpty())
+ QApplication::clipboard()->setText(text);
+ }
+}
+
prefix_ void pykit::PDFWidget::netLoadDocument()
{
QNetworkReply * reply = static_cast<QNetworkReply*>(sender());
#include <QWidget>
#include <QNetworkAccessManager>
#include <QUrl>
+#include <QRubberBand>
//#include "PDFWidget.mpp"
///////////////////////////////hh.p////////////////////////////////////////
QWidget * parent = 0);
PDFWidget(QString const & id, QString const & document, QNetworkAccessManager * manager,
QWidget * parent = 0);
+ ~PDFWidget();
void load(QUrl const & url);
protected:
virtual void resizeEvent(QResizeEvent * event);
+ virtual void mousePressEvent(QMouseEvent * event);
+ virtual void mouseMoveEvent(QMouseEvent * event);
+ virtual void mouseReleaseEvent(QMouseEvent * event);
+
private slots:
void netLoadDocument();
boost::scoped_ptr<Poppler::Document> document_;
int currentPage_;
double dpi_;
+ QRubberBand * rubberBand_;
+ QPoint origin_;
};
}