aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-pdf
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf')
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp232
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.h157
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.cpp41
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.h1
4 files changed, 210 insertions, 221 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
index 3fa87367..7a25357a 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
@@ -1,114 +1,46 @@
#include "PrintWidget.h"
-class PageItem : public QGraphicsItem
-{
-public:
- PageItem(int _pageNum, const QPicture* _pagePicture, QSize _paperSize, QRect _pageRect)
- : pageNum(_pageNum), pagePicture(_pagePicture),
- paperSize(_paperSize), pageRect(_pageRect)
- {
- qreal border = qMax(paperSize.height(), paperSize.width()) / 25;
- brect = QRectF(QPointF(-border, -border),
- QSizeF(paperSize)+QSizeF(2*border, 2*border));
- setCacheMode(DeviceCoordinateCache);
- }
-
- QRectF boundingRect() const Q_DECL_OVERRIDE
- { return brect; }
-
- inline int pageNumber() const
- { return pageNum; }
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) Q_DECL_OVERRIDE;
-
-private:
- int pageNum;
- const QPicture* pagePicture;
- QSize paperSize;
- QRect pageRect;
- 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)
- return;
- painter->drawPicture(pageRect.topLeft(), *pagePicture);
-
- // Effect: make anything drawn in the margins look washed out.
- QPainterPath path;
- path.addRect(paperRect);
- path.addRect(pageRect);
- painter->setPen(QPen(Qt::NoPen));
- painter->setBrush(QColor(255, 255, 255, 180));
- painter->drawPath(path);
-}
-PrintWidget::PrintWidget(QPrinter *printer, QWidget *parent) : QWidget(parent), scene(0), curPage(1), viewMode(SinglePageView), zoomMode(FitInView), zoomFactor(1), initialized(false), fitting(true) {
- this->printer = printer;
+PrintWidget::PrintWidget(QPrinter* printer, QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1),
+ viewMode(SinglePageView), zoomMode(FitInView), zoomFactor(1), initialized(false), fitting(true) {
+
+ this->printer = printer;
this->setMouseTracking(true);
QList<QWidget*> children = this->findChildren<QWidget*>("",Qt::FindChildrenRecursively);
for(int i=0; i<children.length(); i++){
children[i]->setContextMenuPolicy(Qt::CustomContextMenu);
connect(children[i], SIGNAL(customContextMenuRequested(const QPoint&)), this, SIGNAL(customContextMenuRequested(const QPoint&)) );
}
- graphicsView = new GraphicsView;
- graphicsView->setInteractive(false);
- graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
- graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
- QObject::connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),
+ this->setInteractive(false);
+ this->setDragMode(QGraphicsView::ScrollHandDrag);
+ this->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+ this->setFocusPolicy(Qt::NoFocus);
+ QObject::connect(this->verticalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(updateCurrentPage()));
- QObject::connect(graphicsView, SIGNAL(resized()), this, SLOT(fit()));
+ QObject::connect(this, SIGNAL(resized()), this, SLOT(fit()));
- scene = new QGraphicsScene(graphicsView);
+ scene = new QGraphicsScene(this);
scene->setBackgroundBrush(Qt::gray);
- graphicsView->setScene(scene);
+ this->setScene(scene);
- QVBoxLayout *layout = new QVBoxLayout;
+ /*QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
layout->setContentsMargins(0, 0, 0, 0);
- layout->addWidget(graphicsView);
+ layout->addWidget(this);*/
}
PrintWidget::~PrintWidget() {
- //Nothing here for now
+ //delete scene;
+ //delete items in pages(?)
}
//Public Slots
-void PrintWidget::fitInView() {
- setZoomMode(FitToWidth);
+void PrintWidget::fitView() {
+ setZoomMode(FitInView);
}
-void PrintWidget::fitToWidget() {
- setZoomMode(FitInView);
+void PrintWidget::fitToWidth() {
+ setZoomMode(FitToWidth);
}
void PrintWidget::setZoomMode(ZoomMode mode) {
@@ -133,11 +65,10 @@ void PrintWidget::setViewMode(ViewMode mode) {
viewMode = mode;
layoutPages();
if (viewMode == AllPagesView) {
- graphicsView->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
+ this->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
fitting = false;
zoomMode = CustomZoom;
- zoomFactor = graphicsView->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY());
- emit previewChanged();
+ zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY());
} else {
fitting = true;
fit();
@@ -148,31 +79,26 @@ void PrintWidget::zoomIn(double factor) {
fitting = false;
zoomMode = CustomZoom;
zoomFactor *= factor;
- graphicsView->scale(factor, factor);
+ this->scale(factor, factor);
}
void PrintWidget::zoomOut(double factor) {
fitting = false;
zoomMode = CustomZoom;
zoomFactor *= factor;
- graphicsView->scale(1/factor, 1/factor);
+ this->scale(1/factor, 1/factor);
}
void PrintWidget::updatePreview() {
initialized = true;
generatePreview();
- graphicsView->updateGeometry();
-}
-
-void PrintWidget::setOrientation(QPrinter::Orientation orientation) {
- printer->setOrientation(orientation);
- generatePreview();
+ this->updateGeometry();
}
void PrintWidget::setVisible(bool visible) {
if(visible and !initialized)
updatePreview();
- QWidget::setVisible(visible);
+ QGraphicsView::setVisible(visible);
}
void PrintWidget::setCurrentPage(int pageNumber) {
@@ -184,13 +110,13 @@ void PrintWidget::setCurrentPage(int pageNumber) {
if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) {
if (zoomMode != FitInView) {
- QScrollBar *hsc = graphicsView->horizontalScrollBar();
- QScrollBar *vsc = graphicsView->verticalScrollBar();
- QPointF pt = graphicsView->transform().map(pages.at(curPage-1)->pos());
+ QScrollBar *hsc = this->horizontalScrollBar();
+ QScrollBar *vsc = this->verticalScrollBar();
+ QPointF pt = this->transform().map(pages.at(curPage-1)->pos());
vsc->setValue(int(pt.y()) - 10);
hsc->setValue(int(pt.x()) - 10);
} else {
- graphicsView->centerOn(pages.at(curPage-1));
+ this->centerOn(pages.at(curPage-1));
}
}
}
@@ -198,16 +124,25 @@ void PrintWidget::setCurrentPage(int pageNumber) {
//Private functions
void PrintWidget::generatePreview() {
- //printer->d_func()->setPreviewMode(true);
+ qDebug() << "generating preview";
+ if(!previewEngine)
+ previewEngine = new QPreviewPaintEngine();
+ if(!pdfEngine)
+ pdfEngine = new QPdfPrintEngine(QPrinter::HighResolution);
+
+ printer->setEngines(previewEngine, previewEngine);
+ previewEngine->setProxyEngines(pdfEngine, pdfEngine);
+
emit paintRequested(printer);
- //printer->d_func()->setPreviewMode(false);
- //pictures = printer->previewPages();
+
+ printer->setEngines(pdfEngine, pdfEngine);
+
+ qDebug() << "Populating Scene";
populateScene(); // i.e. setPreviewPrintedPictures() e.l.
layoutPages();
curPage = qBound(1, curPage, pages.count());
if (fitting)
fit();
- emit previewChanged();
}
void PrintWidget::layoutPages() {
@@ -220,27 +155,26 @@ void PrintWidget::layoutPages() {
if (viewMode == AllPagesView) {
if (printer->orientation() == QPrinter::Portrait)
cols = qCeil(qSqrt(numPages));
- else
- cols = qFloor(qSqrt(numPages));
- cols += cols % 2; // Nicer with an even number of cols
- }
- else if (viewMode == FacingPagesView) {
- cols = 2;
- numPagePlaces += 1;
- }
- int rows = qCeil(double(numPagePlaces) / cols);
-
- double itemWidth = pages.at(0)->boundingRect().width();
- double itemHeight = pages.at(0)->boundingRect().height();
- int pageNum = 1;
- for (int i = 0; i < rows && pageNum <= numPages; i++) {
- for (int j = 0; j < cols && pageNum <= numPages; j++) {
- if (!i && !j && viewMode == FacingPagesView) {
- continue;
- } else {
- pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight));
- pageNum++;
- }
+ else
+ cols = qFloor(qSqrt(numPages));
+ cols += cols % 2; // Nicer with an even number of cols
+ }
+ else if (viewMode == FacingPagesView) {
+ cols = 2;
+ numPagePlaces += 1;
+ }
+ int rows = qCeil(double(numPagePlaces) / cols);
+
+ double itemWidth = pages.at(0)->boundingRect().width();
+ double itemHeight = pages.at(0)->boundingRect().height();
+ int pageNum = 1; for (int i = 0; i < rows && pageNum <= numPages; i++) {
+ for (int j = 0; j < cols && pageNum <= numPages; j++) {
+ if (!i && !j && viewMode == FacingPagesView) {
+ continue;
+ } else {
+ pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight));
+ pageNum++;
+ }
}
}
scene->setSceneRect(scene->itemsBoundingRect());
@@ -252,13 +186,15 @@ void PrintWidget::populateScene()
scene->removeItem(pages.at(i));
qDeleteAll(pages);
pages.clear();
+ qDebug() << "Pages cleared";
- int numPages = pictures.count();
+ int numPages = pictures->count();
QSize paperSize = printer->pageLayout().fullRectPixels(printer->resolution()).size();
QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution());
+ qDebug() << "Fields set";
for (int i = 0; i < numPages; i++) {
- PageItem* item = new PageItem(i+1, pictures.at(i), paperSize, pageRect);
+ PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize, pageRect);
scene->addItem(item);
pages.append(item);
}
@@ -273,18 +209,17 @@ void PrintWidget::updateCurrentPage() {
int newPage = calcCurrentPage();
if (newPage != curPage) {
curPage = newPage;
- emit previewChanged();
}
}
int PrintWidget::calcCurrentPage() {
int maxArea = 0;
int newPage = curPage;
- QRect viewRect = graphicsView->viewport()->rect();
- QList<QGraphicsItem*> items = graphicsView->items(viewRect);
+ QRect viewRect = this->viewport()->rect();
+ QList<QGraphicsItem*> items = this->items(viewRect);
for (int i=0; i<items.size(); ++i) {
PageItem* pg = static_cast<PageItem*>(items.at(i));
- QRect overlap = graphicsView->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect;
+ QRect overlap = this->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect;
int area = overlap.width() * overlap.height();
if (area > maxArea) {
maxArea = area;
@@ -303,9 +238,9 @@ void PrintWidget::fit(bool doFitting) {
return;
if (doFitting && fitting) {
- QRect viewRect = graphicsView->viewport()->rect();
+ QRect viewRect = this->viewport()->rect();
if (zoomMode == FitInView) {
- QList<QGraphicsItem*> containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect);
+ QList<QGraphicsItem*> containedItems = this->items(viewRect, Qt::ContainsItemBoundingRect);
foreach(QGraphicsItem* item, containedItems) {
PageItem* pg = static_cast<PageItem*>(item);
if (pg->pageNumber() == curPage)
@@ -330,23 +265,26 @@ void PrintWidget::fit(bool doFitting) {
if (zoomMode == FitToWidth) {
QTransform t;
- qreal scale = graphicsView->viewport()->width() / target.width();
+ qreal scale = this->viewport()->width() / target.width();
t.scale(scale, scale);
- graphicsView->setTransform(t);
+ this->setTransform(t);
if (doFitting && fitting) {
- QRectF viewSceneRect = graphicsView->viewportTransform().mapRect(graphicsView->viewport()->rect());
+ QRectF viewSceneRect = this->viewportTransform().mapRect(this->viewport()->rect());
viewSceneRect.moveTop(target.top());
- graphicsView->ensureVisible(viewSceneRect); // Nah...
+ this->ensureVisible(viewSceneRect); // Nah...
}
} else {
- graphicsView->fitInView(target, Qt::KeepAspectRatio);
+ this->fitInView(target, Qt::KeepAspectRatio);
if (zoomMode == FitInView) {
- int step = qRound(graphicsView->matrix().mapRect(target).height());
- graphicsView->verticalScrollBar()->setSingleStep(step);
- graphicsView->verticalScrollBar()->setPageStep(step);
+ int step = qRound(this->matrix().mapRect(target).height());
+ this->verticalScrollBar()->setSingleStep(step);
+ this->verticalScrollBar()->setPageStep(step);
}
}
- zoomFactor = graphicsView->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY());
- emit previewChanged();
+ zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY());
}
+
+void PrintWidget::setPictures(QHash<int, QImage> *hash) {
+ pictures = hash;
+}
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
index 061aef49..81e4e794 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
@@ -7,8 +7,8 @@
// Simple subclass of QPrintPreviewWidget to provide
// notification when a context menu is requested
//===========================================
-#ifndef _PRINT_PREVIEW_WIDGET_H
-#define _PRINT_PREVIEW_WIDGET_H
+#ifndef _PRINT_GRAPHICS_H
+#define _PRINT_GRAPHICS_H
#include <QMouseEvent>
#include <QDebug>
@@ -19,33 +19,85 @@
#include <QStyleOptionGraphicsItem>
#include <QtMath>
#include <QPrinter>
-
-class GraphicsView : public QGraphicsView
+namespace {
+class PageItem : public QGraphicsItem
{
- Q_OBJECT
public:
- GraphicsView(QWidget *parent = 0) : QGraphicsView(parent) { }
-signals:
- void resized();
-protected:
- void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE {
- /*{
- const QSignalBlocker blocker(verticalScrollBar()); // Don't change page, QTBUG-14517
- QGraphicsView::resizeEvent(e);
- }*/
- QGraphicsView::resizeEvent(e);
- emit resized();
- }
+ PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize, QRect _pageRect)
+ : pageNum(_pageNum), pagePicture(_pagePicture),
+ paperSize(_paperSize), pageRect(_pageRect)
+ {
+ qreal border = qMax(paperSize.height(), paperSize.width()) / 25;
+ brect = QRectF(QPointF(-border, -border),
+ QSizeF(paperSize)+QSizeF(2*border, 2*border));
+ setCacheMode(DeviceCoordinateCache);
+ }
- void showEvent(QShowEvent* e) Q_DECL_OVERRIDE {
- QGraphicsView::showEvent(e);
- emit resized();
- }
+ QRectF boundingRect() const Q_DECL_OVERRIDE
+ { return brect; }
+
+ inline int pageNumber() const
+ { return pageNum; }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) Q_DECL_OVERRIDE;
+
+private:
+ int pageNum;
+ const QImage pagePicture;
+ QSize paperSize;
+ QRect pageRect;
+ QRectF brect;
};
-class PrintWidget: public QWidget{
+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())
+ return;
+ painter->drawImage(pageRect.topLeft(), pagePicture);
+
+ // Effect: make anything drawn in the margins look washed out.
+ QPainterPath path;
+ path.addRect(paperRect);
+ path.addRect(pageRect);
+ painter->setPen(QPen(Qt::NoPen));
+ painter->setBrush(QColor(255, 255, 255, 180));
+ painter->drawPath(path);
+}
+}
+
+class PrintWidget : public QGraphicsView
+{
Q_OBJECT
public:
+ PrintWidget(QPrinter *printer, QWidget *parent = 0);
+ ~PrintWidget();
enum ViewMode {
SinglePageView,
FacingPagesView,
@@ -58,57 +110,62 @@ public:
FitInView
};
- PrintWidget(QPrinter *printer = 0, QWidget *parent = 0);
- ~PrintWidget();
-
- int currentPage() const { return curPage; };
double getZoomFactor() const { return this->zoomFactor; };
- QPrinter::Orientation orientation() const { return printer->orientation(); };
ZoomMode getZoomMode() const { return this->zoomMode; };
- void setVisible(bool);
+ int currentPage() const { return curPage; };
+ void setPictures(QHash<int, QImage>*);
+signals:
+ void resized();
+ void customContextMenuRequested(const QPoint&);
+ void paintRequested(QPrinter*);
public slots:
- void zoomIn(double factor=1.2);
+ void zoomIn(double factor=1.2);
void zoomOut(double factor=1.2);
- void setOrientation(QPrinter::Orientation);
void setCurrentPage(int);
+ void setVisible(bool) Q_DECL_OVERRIDE;
- void fitInView();
- void fitToWidget();
+ void fitView();
+ void fitToWidth();
void setAllPagesViewMode();
void setSinglePageViewMode();
void setFacingPagesViewMode();
- void updatePreview();
-
-private slots:
- void updateCurrentPage();
+ void updateCurrentPage();
int calcCurrentPage();
void fit(bool doFitting=false);
+ void updatePreview();
+protected:
+ void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE {
+ /*{
+ const QSignalBlocker blocker(verticalScrollBar()); // Don't change page, QTBUG-14517
+ QGraphicsView::resizeEvent(e);
+ }*/
+ QGraphicsView::resizeEvent(e);
+ emit resized();
+ }
-signals:
- void customContextMenuRequested(const QPoint&);
- void paintRequested(QPrinter*);
- void previewChanged();
-
+ void showEvent(QShowEvent* e) Q_DECL_OVERRIDE {
+ QGraphicsView::showEvent(e);
+ emit resized();
+ }
private:
void generatePreview();
void layoutPages();
void populateScene();
- void setViewMode(ViewMode viewMode);
- void setZoomMode(ZoomMode viewMode);
-
- QPrinter *printer;
- GraphicsView *graphicsView;
+ void setViewMode(ViewMode);
+ void setZoomMode(ZoomMode);
QGraphicsScene *scene;
- int curPage;
- QList<const QPicture *> pictures;
- QList<QGraphicsItem *> pages;
+ QPrinter *printer;
+ QPreviewPaintEngine *previewEngine;
+ QPdfPrintEngine *pdfEngine;
+ int curPage;
ViewMode viewMode;
ZoomMode zoomMode;
double zoomFactor;
bool initialized, fitting;
+ QList<QGraphicsItem *> pages;
+ QHash<int, QImage> *pictures;
};
-
#endif
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
index 6c5b762c..4e65a766 100644
--- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
@@ -29,11 +29,11 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
this->setWindowIcon( LXDG::findIcon("application-pdf","unknown"));
this->highlight = false;
presentationLabel = 0;
- CurrentPage = 0;
+ CurrentPage = 1;
lastdir = QDir::homePath();
Printer = new QPrinter();
//Create the interface widgets
- WIDGET = new PrintWidget(Printer,this);
+ WIDGET = new PrintWidget(Printer, this);
clockTimer = new QTimer(this);
clockTimer->setInterval(1000); //1-second updates to clock
connect(clockTimer, SIGNAL(timeout()), this, SLOT(updateClock()) );
@@ -51,7 +51,6 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
qDebug() << "Setting central widget";
this->setCentralWidget(WIDGET);
WIDGET->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(newFocus(QWidget*, QWidget*)));
connect(WIDGET, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(showContextMenu(const QPoint&)) );
connect(WIDGET, &PrintWidget::paintRequested, this,
[=](QPrinter *printer) { this->paintOnWidget(printer, this->highlight); });
@@ -59,7 +58,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
connect(this, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) );
PrintDLG = new QPrintDialog(this);
- connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) );
+ //connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) );
//connect(ui->menuStart_Presentation, SIGNAL(triggered(QAction*)), this, SLOT(slotStartPresentation(QAction*)) );
//Create the other interface widgets
@@ -91,7 +90,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()) );
connect(ui->actionPrint, SIGNAL(triggered()), PrintDLG, SLOT(open()) );
connect(ui->actionFit_Width, SIGNAL(triggered()), WIDGET, SLOT(fitToWidth()) );
- connect(ui->actionFit_Page, SIGNAL(triggered()), WIDGET, SLOT(fitInView()) );
+ connect(ui->actionFit_Page, SIGNAL(triggered()), WIDGET, SLOT(fitView()) );
connect(ui->actionOpen_PDF, SIGNAL(triggered()), this, SLOT(OpenNewFile()) );
connect(ui->actionSingle_Page, SIGNAL(triggered()), WIDGET, SLOT(setSinglePageViewMode()) );
connect(ui->actionDual_Pages, SIGNAL(triggered()), WIDGET, SLOT(setFacingPagesViewMode()) );
@@ -235,14 +234,15 @@ void MainUI::loadFile(QString path){
Printer->setPageSize( QPageSize(PAGE->pageSize(), QPageSize::Point) );
Printer->setPageMargins(QMarginsF(0,0,0,0), QPageLayout::Point);
switch(PAGE->orientation()){
- case Poppler::Page::Landscape:
- Printer->setOrientation(QPrinter::Landscape); break;
- default:
- Printer->setOrientation(QPrinter::Portrait);
+ case Poppler::Page::Landscape:
+ Printer->setOrientation(QPrinter::Landscape); break;
+ default:
+ Printer->setOrientation(QPrinter::Portrait);
}
delete PAGE;
qDebug() << " - Document Setup : start loading pages now";
- QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview
+ startLoadingPages(Printer);
+ //QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview
}
}
@@ -253,7 +253,7 @@ void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, Q
// Using Qt to scale the image (adjust page value) smooths out the image quite a bit without a lot of performance loss (but cannot scale up without pixelization)
// The best approach seams to be to increase the DPI a bit, but match that with the same scaling on the page size (smoothing)
- //qDebug() << " - Render Page:" << num;
+ qDebug() << " - Render Page:" << num;
Poppler::Page *PAGE = doc->page(num);
if(PAGE!=0){
//qDebug() << "DPI:" << dpi << "Size:" << page << "Page Size (pt):" << PAGE->pageSize();
@@ -352,7 +352,7 @@ void MainUI::ShowPage(int page){
endPresentation();
return; //invalid - no document loaded or invalid page specified
}
- WIDGET->setCurrentPage(page+1); //page numbers start at 1 for this widget
+ WIDGET->setCurrentPage(page); //page numbers start at 1 for this widget
//Stop here if no presentation currently running
if(presentationLabel == 0 || !presentationLabel->isVisible()){ return; }
CurrentPage = page;
@@ -410,7 +410,9 @@ void MainUI::slotPageLoaded(int page){
int finished = loadingHash.keys().length();
if(finished == numPages){
progAct->setVisible(false);
- QTimer::singleShot(0, WIDGET, SLOT(updatePreview()));
+ qDebug() << "Setting Pictures";
+ WIDGET->setPictures(&loadingHash);
+ QTimer::singleShot(10, WIDGET, SLOT(updatePreview()));
//qDebug() << "Updating";
ui->actionStop_Presentation->setEnabled(false);
ui->actionStart_Here->setEnabled(true);
@@ -559,9 +561,10 @@ void MainUI::rotate(bool ccw) {
loadingHash.insert(i, image);
}
//Rotates the page as well as the image
- WIDGET->setOrientation((WIDGET->orientation() == QPrinter::Landscape) ?
+ Printer->setOrientation((Printer->orientation() == QPrinter::Landscape) ?
QPrinter::Portrait : QPrinter::Landscape);
- WIDGET->updatePreview();
+
+ QTimer::singleShot(0, WIDGET, SLOT(updatePreview()));
}
void MainUI::updateContextMenu(){
@@ -616,14 +619,6 @@ void MainUI::wheelEvent(QWheelEvent *event) {
QMainWindow::wheelEvent(event);
}
-void MainUI::newFocus(QWidget *oldW, QWidget *newW) {
- //qDebug() << "NEW: " << newW << "OLD: " << oldW;
- if(!oldW && newW != this) {
- newW->setFocusPolicy(Qt::NoFocus);
- this->setFocus();
- }
-}
-
void MainUI::showInformation() {
PROPDIALOG = new PropDialog(DOC);
PROPDIALOG->show();
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h
index cce04cd4..b3ad38f1 100644
--- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h
+++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h
@@ -90,7 +90,6 @@ private slots:
void enableFind();
void showBookmarks();
- void newFocus(QWidget*, QWidget*);
void paintOnWidget(QPrinter*, bool);
void paintToPrinter(QPrinter *PRINTER);
bgstack15