aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp354
1 files changed, 177 insertions, 177 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
index 4ccae28c..9515e719 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
@@ -1,8 +1,8 @@
#include "PrintWidget.h"
PrintWidget::PrintWidget(Renderer *backend, QWidget *parent) :
- QGraphicsView(parent), scene(0), curPage(1), viewMode(SinglePageView),
- zoomMode(FitInView), zoomFactor(1), initialized(false), fitting(true), BACKEND(backend) {
+ QGraphicsView(parent), scene(0), curPage(1), viewMode(SinglePageView),
+ zoomMode(FitInView), zoomFactor(1), initialized(false), fitting(true), BACKEND(backend) {
this->setMouseTracking(true);
QList<QWidget*> children = this->findChildren<QWidget*>("",Qt::FindChildrenRecursively);
@@ -10,24 +10,24 @@ PrintWidget::PrintWidget(Renderer *backend, QWidget *parent) :
children[i]->setContextMenuPolicy(Qt::CustomContextMenu);
connect(children[i], SIGNAL(customContextMenuRequested(const QPoint&)), this, SIGNAL(customContextMenuRequested(const QPoint&)) );
}
- this->setInteractive(false);
- this->setDragMode(QGraphicsView::ScrollHandDrag);
- this->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+ 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(this, SIGNAL(resized()), this, SLOT(fit()));
+ QObject::connect(this->verticalScrollBar(), SIGNAL(valueChanged(int)),
+ this, SLOT(updateCurrentPage()));
+ QObject::connect(this, SIGNAL(resized()), this, SLOT(fit()));
- scene = new QGraphicsScene(this);
- scene->setBackgroundBrush(Qt::gray);
- this->setScene(scene);
+ scene = new QGraphicsScene(this);
+ scene->setBackgroundBrush(Qt::gray);
+ this->setScene(scene);
this->degrees = 0;
this->rotMatrix = QMatrix(1, 0, 0, 1, 0 ,0);
- /*QVBoxLayout *layout = new QVBoxLayout;
- setLayout(layout);
- layout->setContentsMargins(0, 0, 0, 0);
- layout->addWidget(this);*/
+ /*QVBoxLayout *layout = new QVBoxLayout;
+ setLayout(layout);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(this);*/
}
PrintWidget::~PrintWidget() {
@@ -49,8 +49,8 @@ void PrintWidget::fitToWidth() {
void PrintWidget::setZoomMode(ZoomMode mode) {
zoomMode = mode;
- fitting = true;
- fit(true);
+ fitting = true;
+ fit(true);
}
void PrintWidget::setAllPagesViewMode() {
@@ -66,31 +66,31 @@ void PrintWidget::setFacingPagesViewMode() {
}
void PrintWidget::setViewMode(ViewMode mode) {
- viewMode = mode;
- layoutPages();
- if (viewMode == AllPagesView) {
- this->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
- fitting = false;
- zoomMode = CustomZoom;
- //zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY());
- } else {
- fitting = true;
- fit();
- }
+ viewMode = mode;
+ layoutPages();
+ if (viewMode == AllPagesView) {
+ this->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
+ fitting = false;
+ zoomMode = CustomZoom;
+ //zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY());
+ } else {
+ fitting = true;
+ fit();
+ }
}
void PrintWidget::zoomIn(double factor) {
- fitting = false;
- zoomMode = CustomZoom;
- zoomFactor *= factor;
- this->scale(factor, factor);
+ fitting = false;
+ zoomMode = CustomZoom;
+ zoomFactor *= factor;
+ this->scale(factor, factor);
}
void PrintWidget::zoomOut(double factor) {
- fitting = false;
- zoomMode = CustomZoom;
- zoomFactor *= factor;
- this->scale(1/factor, 1/factor);
+ fitting = false;
+ zoomMode = CustomZoom;
+ zoomFactor *= factor;
+ this->scale(1/factor, 1/factor);
}
void PrintWidget::updatePreview() {
@@ -100,31 +100,31 @@ void PrintWidget::updatePreview() {
}
void PrintWidget::setVisible(bool visible) {
- if(visible and !initialized)
- updatePreview();
- QGraphicsView::setVisible(visible);
+ if(visible and !initialized)
+ updatePreview();
+ QGraphicsView::setVisible(visible);
}
void PrintWidget::setCurrentPage(int pageNumber) {
- if(pageNumber < 0 || pageNumber > (pages.count()+1) ){ return; }
- publicPageNum = pageNumber; //publicly requested page number (+/- 1 from actual page range)
- emit currentPageChanged();
- if(pageNumber < 1 || pageNumber > pages.count())
- return;
- int lastPage = curPage;
- curPage = pageNumber;
-
- if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) {
- if (zoomMode != FitInView) {
- 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 {
- this->centerOn(pages.at(curPage-1));
- }
- }
+ if(pageNumber < 0 || pageNumber > (pages.count()+1) ){ return; }
+ publicPageNum = pageNumber; //publicly requested page number (+/- 1 from actual page range)
+ emit currentPageChanged();
+ if(pageNumber < 1 || pageNumber > pages.count())
+ return;
+ int lastPage = curPage;
+ curPage = pageNumber;
+
+ if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) {
+ if (zoomMode != FitInView) {
+ 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 {
+ this->centerOn(pages.at(curPage-1));
+ }
+ }
}
void PrintWidget::highlightText(TextData *text) {
@@ -132,19 +132,19 @@ void PrintWidget::highlightText(TextData *text) {
if(!text->highlighted()) {
double pageHeight = pages.at(text->page()-1)->boundingRect().height();
QRectF rect = text->loc();
- if(degrees != 0) {
- QSize center = BACKEND->imageHash(text->page()-1).size()/2;
- //Rotates the rectangle by the page's center
- double cx = center.width(), cy = center.height();
- rect.adjust(-cx, -cy, -cx, -cy);
- rect = rotMatrix.mapRect(rect);
- if(degrees == 180)
- rect.adjust(cx, cy, cx, cy);
- else
- rect.adjust(cy, cx, cy, cx);
- }
- //Moves the rectangle onto the right page
- rect.moveTop(rect.y() + pageHeight*(text->page()-1));
+ if(degrees != 0) {
+ QSize center = BACKEND->imageHash(text->page()-1).size()/2;
+ //Rotates the rectangle by the page's center
+ double cx = center.width(), cy = center.height();
+ rect.adjust(-cx, -cy, -cx, -cy);
+ rect = rotMatrix.mapRect(rect);
+ if(degrees == 180)
+ rect.adjust(cx, cy, cx, cy);
+ else
+ rect.adjust(cy, cx, cy, cx);
+ }
+ //Moves the rectangle onto the right page
+ rect.moveTop(rect.y() + pageHeight*(text->page()-1));
QBrush highlightFill(QColor(255, 255, 177, 100));
QPen highlightOutline(QColor(255, 255, 100, 125));
scene->addRect(rect, highlightOutline, highlightFill);
@@ -155,24 +155,24 @@ void PrintWidget::highlightText(TextData *text) {
//Private functions
void PrintWidget::generatePreview() {
- qDebug() << "Generating Preview";
- populateScene(); // i.e. setPreviewPrintedPictures() e.l.
- layoutPages();
- curPage = qBound(1, curPage, pages.count());
- publicPageNum = curPage;
- emit currentPageChanged();
- if (fitting){ fit(); }
+ qDebug() << "Generating Preview";
+ populateScene(); // i.e. setPreviewPrintedPictures() e.l.
+ layoutPages();
+ curPage = qBound(1, curPage, pages.count());
+ publicPageNum = curPage;
+ emit currentPageChanged();
+ if (fitting){ fit(); }
}
void PrintWidget::layoutPages() {
- int numPages = pages.count();
- if (numPages < 1)
- return;
-
- int numPagePlaces = numPages;
- int cols = 1; // singleMode and default
- QSize pageSize = BACKEND->imageHash(0).size();
- if (viewMode == AllPagesView) {
+ int numPages = pages.count();
+ if (numPages < 1)
+ return;
+
+ int numPagePlaces = numPages;
+ int cols = 1; // singleMode and default
+ QSize pageSize = BACKEND->imageHash(0).size();
+ if (viewMode == AllPagesView) {
cols = pageSize.width() > pageSize.height() ? qFloor(qSqrt(numPages)) : qCeil(qSqrt(numPages));
cols += cols % 2; // Nicer with an even number of cols
} else if (viewMode == FacingPagesView) {
@@ -191,16 +191,16 @@ void PrintWidget::layoutPages() {
pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight));
pageNum++;
}
- }
- }
- scene->setSceneRect(scene->itemsBoundingRect());
- qDebug() << "Finished Page Layout";
+ }
+ }
+ scene->setSceneRect(scene->itemsBoundingRect());
+ qDebug() << "Finished Page Layout";
}
void PrintWidget::populateScene()
{
for (int i = 0; i < pages.size(); i++){
- scene->removeItem(pages.at(i));
+ scene->removeItem(pages.at(i));
}
qDeleteAll(pages);
pages.clear();
@@ -210,13 +210,13 @@ void PrintWidget::populateScene()
for (int i = 0; i < numPages; i++) {
QImage pagePicture = BACKEND->imageHash(i);
- //qDebug() << "Loading Image:" << i;
+ //qDebug() << "Loading Image:" << i;
- QSize paperSize = BACKEND->imageHash(i).size();
+ QSize paperSize = BACKEND->imageHash(i).size();
- //Changes the paper orientation if rotated by 90 or 270 degrees
- if(degrees == 90 or degrees == 270)
- paperSize.transpose();
+ //Changes the paper orientation if rotated by 90 or 270 degrees
+ if(degrees == 90 or degrees == 270)
+ paperSize.transpose();
if(degrees != 0) {
pagePicture = pagePicture.transformed(rotMatrix, Qt::SmoothTransformation);
@@ -226,102 +226,102 @@ void PrintWidget::populateScene()
qDebug() << "NULL IMAGE ON PAGE " << i;
continue;
}
- PageItem* item = new PageItem(i+1, pagePicture, paperSize);
- scene->addItem(item);
- pages.append(item);
+ PageItem* item = new PageItem(i+1, pagePicture, paperSize);
+ scene->addItem(item);
+ pages.append(item);
}
}
//Private Slots
void PrintWidget::updateCurrentPage() {
- if (viewMode == AllPagesView)
- return;
-
- int newPage = calcCurrentPage();
- if (newPage != curPage) {
- curPage = newPage;
- publicPageNum = curPage;
- emit currentPageChanged();
- }
+ if (viewMode == AllPagesView)
+ return;
+
+ int newPage = calcCurrentPage();
+ if (newPage != curPage) {
+ curPage = newPage;
+ publicPageNum = curPage;
+ emit currentPageChanged();
+ }
}
int PrintWidget::calcCurrentPage() {
- int maxArea = 0;
- int newPage = curPage;
- 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 = this->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect;
- int area = overlap.width() * overlap.height();
- if (area > maxArea) {
- maxArea = area;
- newPage = pg->pageNumber();
- } else if (area == maxArea && pg->pageNumber() < newPage) {
- newPage = pg->pageNumber();
- }
- }
- return newPage;
+ int maxArea = 0;
+ int newPage = curPage;
+ 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 = this->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect;
+ int area = overlap.width() * overlap.height();
+ if (area > maxArea) {
+ maxArea = area;
+ newPage = pg->pageNumber();
+ } else if (area == maxArea && pg->pageNumber() < newPage) {
+ newPage = pg->pageNumber();
+ }
+ }
+ return newPage;
}
void PrintWidget::fit(bool doFitting) {
- if (curPage < 1 || curPage > pages.count())
- return;
- if (!doFitting && !fitting)
- return;
-
- if (doFitting && fitting) {
- QRect viewRect = this->viewport()->rect();
- if (zoomMode == FitInView) {
- QList<QGraphicsItem*> containedItems = this->items(viewRect, Qt::ContainsItemBoundingRect);
- foreach(QGraphicsItem* item, containedItems) {
- PageItem* pg = static_cast<PageItem*>(item);
- if (pg->pageNumber() == curPage)
- return;
- }
- }
-
- int newPage = calcCurrentPage();
- if (newPage != curPage)
- curPage = newPage;
- }
-
- QRectF target = pages.at(curPage-1)->sceneBoundingRect();
- if (viewMode == FacingPagesView) {
- if (curPage % 2)
- target.setLeft(target.left() - target.width());
- else
- target.setRight(target.right() + target.width());
- } else if (viewMode == AllPagesView) {
- target = scene->itemsBoundingRect();
- }
-
- if (zoomMode == FitToWidth) {
- QTransform t;
- qreal scale = this->viewport()->width() / target.width();
- t.scale(scale, scale);
- this->setTransform(t);
- if (doFitting && fitting) {
- QRectF viewSceneRect = this->viewportTransform().mapRect(this->viewport()->rect());
- viewSceneRect.moveTop(target.top());
- this->ensureVisible(viewSceneRect); // Nah...
- }
- } else {
- this->fitInView(target, Qt::KeepAspectRatio);
- if (zoomMode == FitInView) {
- int step = qRound(this->matrix().mapRect(target).height());
- this->verticalScrollBar()->setSingleStep(step);
- this->verticalScrollBar()->setPageStep(step);
- }
- }
-
- //zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY());
+ if (curPage < 1 || curPage > pages.count())
+ return;
+ if (!doFitting && !fitting)
+ return;
+
+ if (doFitting && fitting) {
+ QRect viewRect = this->viewport()->rect();
+ if (zoomMode == FitInView) {
+ QList<QGraphicsItem*> containedItems = this->items(viewRect, Qt::ContainsItemBoundingRect);
+ foreach(QGraphicsItem* item, containedItems) {
+ PageItem* pg = static_cast<PageItem*>(item);
+ if (pg->pageNumber() == curPage)
+ return;
+ }
+ }
+
+ int newPage = calcCurrentPage();
+ if (newPage != curPage)
+ curPage = newPage;
+ }
+
+ QRectF target = pages.at(curPage-1)->sceneBoundingRect();
+ if (viewMode == FacingPagesView) {
+ if (curPage % 2)
+ target.setLeft(target.left() - target.width());
+ else
+ target.setRight(target.right() + target.width());
+ } else if (viewMode == AllPagesView) {
+ target = scene->itemsBoundingRect();
+ }
+
+ if (zoomMode == FitToWidth) {
+ QTransform t;
+ qreal scale = this->viewport()->width() / target.width();
+ t.scale(scale, scale);
+ this->setTransform(t);
+ if (doFitting && fitting) {
+ QRectF viewSceneRect = this->viewportTransform().mapRect(this->viewport()->rect());
+ viewSceneRect.moveTop(target.top());
+ this->ensureVisible(viewSceneRect); // Nah...
+ }
+ } else {
+ this->fitInView(target, Qt::KeepAspectRatio);
+ if (zoomMode == FitInView) {
+ int step = qRound(this->matrix().mapRect(target).height());
+ this->verticalScrollBar()->setSingleStep(step);
+ this->verticalScrollBar()->setPageStep(step);
+ }
+ }
+
+ //zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY());
}
//Makes sure degrees is between 0 and 360 then rotates the matrix and
void PrintWidget::setDegrees(int degrees) {
//Mods by 360, but adds and remods because of how C++ treats negative mods
this->degrees = ( ( ( this->degrees + degrees ) % 360 ) + 360 ) % 360;
- rotMatrix.rotate(degrees);
- this->updatePreview();
+ rotMatrix.rotate(degrees);
+ this->updatePreview();
}
bgstack15