From 768822f63c5e8086543438765450d8d20ce0a0fe Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 24 Jan 2018 12:24:09 -0500 Subject: Fix up the rendering quality of the lumina-pdf pages. Also get the new backend working properly with the next/previous page system and presentation mode. --- src-qt5/desktop-utils/lumina-pdf/PrintWidget.h | 182 +++++++++++++------------ 1 file changed, 94 insertions(+), 88 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/PrintWidget.h') diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h index 62543e45..f18f8ace 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h @@ -20,26 +20,62 @@ #include #include -namespace { -class PageItem : public QGraphicsItem -{ +class PageItem : public QGraphicsItem { public: - PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize) - : pageNum(_pageNum), pagePicture(_pagePicture), - paperSize(_paperSize) - { - brect = QRectF(QPointF(-25, -25), - QSizeF(paperSize)+QSizeF(50, 50)); - setCacheMode(DeviceCoordinateCache); - } - - QRectF boundingRect() const Q_DECL_OVERRIDE - { return brect; } - - inline int pageNumber() const - { return pageNum; } + PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize) + : pageNum(_pageNum), pagePicture(_pagePicture), paperSize(_paperSize) + { + brect = QRectF(QPointF(-25, -25), + QSizeF(paperSize)+QSizeF(50, 50)); + setCacheMode(DeviceCoordinateCache); + } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) Q_DECL_OVERRIDE; + QRectF boundingRect() const Q_DECL_OVERRIDE + { return brect; } + + inline int pageNumber() const + { return pageNum; } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE + { + Q_UNUSED(widget); + //Ensure all the antialiasing/smoothing options are turned on + painter->setRenderHint(QPainter::Antialiasing); + painter->setRenderHint(QPainter::TextAntialiasing); + painter->setRenderHint(QPainter::SmoothPixmapTransform); + + QRectF paperRect(0,0, paperSize.width(), paperSize.height()); + + // Draw shadow + painter->setClipRect(option->exposedRect); + qreal shWidth = paperRect.width()/100; + QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth), + paperRect.bottomRight() + QPointF(shWidth, 0)); + QLinearGradient rgrad(rshadow.topLeft(), rshadow.topRight()); + rgrad.setColorAt(0.0, QColor(0,0,0,255)); + rgrad.setColorAt(1.0, QColor(0,0,0,0)); + painter->fillRect(rshadow, QBrush(rgrad)); + QRectF bshadow(paperRect.bottomLeft() + QPointF(shWidth, 0), + paperRect.bottomRight() + QPointF(0, shWidth)); + QLinearGradient bgrad(bshadow.topLeft(), bshadow.bottomLeft()); + bgrad.setColorAt(0.0, QColor(0,0,0,255)); + bgrad.setColorAt(1.0, QColor(0,0,0,0)); + painter->fillRect(bshadow, QBrush(bgrad)); + QRectF cshadow(paperRect.bottomRight(), + paperRect.bottomRight() + QPointF(shWidth, shWidth)); + QRadialGradient cgrad(cshadow.topLeft(), shWidth, cshadow.topLeft()); + cgrad.setColorAt(0.0, QColor(0,0,0,255)); + cgrad.setColorAt(1.0, QColor(0,0,0,0)); + painter->fillRect(cshadow, QBrush(cgrad)); + + painter->setClipRect(paperRect & option->exposedRect); + painter->fillRect(paperRect, Qt::white); + if (pagePicture.isNull()){ + qDebug() << "NULL"; + return; + } + painter->drawImage(QPoint(0,0), pagePicture); + } private: int pageNum; @@ -48,49 +84,11 @@ private: QRectF brect; }; -void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(widget); - QRectF paperRect(0,0, paperSize.width(), paperSize.height()); - - // Draw shadow - painter->setClipRect(option->exposedRect); - qreal shWidth = paperRect.width()/100; - QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth), - paperRect.bottomRight() + QPointF(shWidth, 0)); - QLinearGradient rgrad(rshadow.topLeft(), rshadow.topRight()); - rgrad.setColorAt(0.0, QColor(0,0,0,255)); - rgrad.setColorAt(1.0, QColor(0,0,0,0)); - painter->fillRect(rshadow, QBrush(rgrad)); - QRectF bshadow(paperRect.bottomLeft() + QPointF(shWidth, 0), - paperRect.bottomRight() + QPointF(0, shWidth)); - QLinearGradient bgrad(bshadow.topLeft(), bshadow.bottomLeft()); - bgrad.setColorAt(0.0, QColor(0,0,0,255)); - bgrad.setColorAt(1.0, QColor(0,0,0,0)); - painter->fillRect(bshadow, QBrush(bgrad)); - QRectF cshadow(paperRect.bottomRight(), - paperRect.bottomRight() + QPointF(shWidth, shWidth)); - QRadialGradient cgrad(cshadow.topLeft(), shWidth, cshadow.topLeft()); - cgrad.setColorAt(0.0, QColor(0,0,0,255)); - cgrad.setColorAt(1.0, QColor(0,0,0,0)); - painter->fillRect(cshadow, QBrush(cgrad)); - - painter->setClipRect(paperRect & option->exposedRect); - painter->fillRect(paperRect, Qt::white); - if (pagePicture.isNull()){ - qDebug() << "NULL"; - return; - } - painter->drawImage(QPoint(0,0), pagePicture); -} -} class PrintWidget : public QGraphicsView { Q_OBJECT public: - PrintWidget(QWidget *parent = 0); - ~PrintWidget(); enum ViewMode { SinglePageView, FacingPagesView, @@ -103,33 +101,57 @@ public: FitInView }; - double getZoomFactor() const { return this->zoomFactor; }; - ZoomMode getZoomMode() const { return this->zoomMode; }; - int currentPage() const { return curPage; }; - void setPictures(QHash*); +private: + void generatePreview(); + void layoutPages(); + void populateScene(); + void setViewMode(ViewMode); + void setZoomMode(ZoomMode); + + QGraphicsScene *scene; + + int curPage, publicPageNum; + ViewMode viewMode; + ZoomMode zoomMode; + QPageLayout::Orientation orientation; + double zoomFactor; + bool initialized, fitting; + QList pages; + QHash *pictures; + +public: + PrintWidget(QWidget *parent = 0); + ~PrintWidget(); + + double getZoomFactor() const { return this->zoomFactor; }; + ZoomMode getZoomMode() const { return this->zoomMode; }; + int currentPage() const { return publicPageNum; }; + void setPictures(QHash*); signals: void resized(); void customContextMenuRequested(const QPoint&); + public slots: void zoomIn(double factor=1.2); - void zoomOut(double factor=1.2); - void setCurrentPage(int); - void setVisible(bool) Q_DECL_OVERRIDE; - void setOrientation(QPageLayout::Orientation); - void highlightText(int, QRectF); + void zoomOut(double factor=1.2); + void setCurrentPage(int); + void setVisible(bool) Q_DECL_OVERRIDE; + void setOrientation(QPageLayout::Orientation); + void highlightText(int, QRectF); - void updatePreview(); + void updatePreview(); void fitView(); - void fitToWidth(); - void setAllPagesViewMode(); - void setSinglePageViewMode(); - void setFacingPagesViewMode(); + void fitToWidth(); + void setAllPagesViewMode(); + void setSinglePageViewMode(); + void setFacingPagesViewMode(); private slots: void updateCurrentPage(); - int calcCurrentPage(); - void fit(bool doFitting=false); + int calcCurrentPage(); + void fit(bool doFitting=false); + protected: void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE { /*{ @@ -144,21 +166,5 @@ protected: QGraphicsView::showEvent(e); emit resized(); } -private: - void generatePreview(); - void layoutPages(); - void populateScene(); - void setViewMode(ViewMode); - void setZoomMode(ZoomMode); - QGraphicsScene *scene; - - int curPage; - ViewMode viewMode; - ZoomMode zoomMode; - QPageLayout::Orientation orientation; - double zoomFactor; - bool initialized, fitting; - QList pages; - QHash *pictures; }; #endif -- cgit