aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-pdf
diff options
context:
space:
mode:
authorWeblate <noreply@weblate.org>2018-01-02 22:00:13 +0000
committerWeblate <noreply@weblate.org>2018-01-02 22:00:13 +0000
commit76f036e835d89572b92006c7f6d4918b7c799664 (patch)
treea80a82bda02e0fc740ea607767ad2409c8aeaa8d /src-qt5/desktop-utils/lumina-pdf
parentTranslated using Weblate (Portuguese (Brazil)) (diff)
parentMerge branch 'master' of github.com:trueos/lumina (diff)
downloadlumina-76f036e835d89572b92006c7f6d4918b7c799664.tar.gz
lumina-76f036e835d89572b92006c7f6d4918b7c799664.tar.bz2
lumina-76f036e835d89572b92006c7f6d4918b7c799664.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf')
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp49
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/PrintWidget.h43
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.cpp105
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.h8
4 files changed, 61 insertions, 144 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
index 7a25357a..be00e675 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp
@@ -1,9 +1,8 @@
#include "PrintWidget.h"
-PrintWidget::PrintWidget(QPrinter* printer, QWidget *parent) : QGraphicsView(parent), scene(0), curPage(1),
+PrintWidget::PrintWidget(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++){
@@ -68,7 +67,7 @@ void PrintWidget::setViewMode(ViewMode mode) {
this->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
fitting = false;
zoomMode = CustomZoom;
- zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY());
+ //zoomFactor = this->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY());
} else {
fitting = true;
fit();
@@ -121,23 +120,15 @@ void PrintWidget::setCurrentPage(int pageNumber) {
}
}
+void PrintWidget::highlightText(int pageNum, QRectF textBox) {
+ PageItem *item = static_cast<PageItem*>(pages[pageNum]);
+ QPainter painter(this);
+ painter.fillRect(textBox, QColor(255, 255, 177, 128));
+}
+
//Private functions
void PrintWidget::generatePreview() {
- 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->setEngines(pdfEngine, pdfEngine);
-
- qDebug() << "Populating Scene";
populateScene(); // i.e. setPreviewPrintedPictures() e.l.
layoutPages();
curPage = qBound(1, curPage, pages.count());
@@ -153,13 +144,9 @@ void PrintWidget::layoutPages() {
int numPagePlaces = numPages;
int cols = 1; // singleMode and default
if (viewMode == AllPagesView) {
- if (printer->orientation() == QPrinter::Portrait)
- cols = qCeil(qSqrt(numPages));
- else
- cols = qFloor(qSqrt(numPages));
+ cols = ((pictures->value(0)).width() > (pictures->value(0)).height()) ? qFloor(qSqrt(numPages)) : qCeil(qSqrt(numPages));
cols += cols % 2; // Nicer with an even number of cols
- }
- else if (viewMode == FacingPagesView) {
+ } else if (viewMode == FacingPagesView) {
cols = 2;
numPagePlaces += 1;
}
@@ -186,21 +173,19 @@ void PrintWidget::populateScene()
scene->removeItem(pages.at(i));
qDeleteAll(pages);
pages.clear();
- qDebug() << "Pages cleared";
int numPages = pictures->count();
- QSize paperSize = printer->pageLayout().fullRectPixels(printer->resolution()).size();
- QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution());
- qDebug() << "Fields set";
+ //Replace from loadingHash resolution
+ QSize paperSize = pictures->value(0).size();
+ qDebug() << "Image paperSize" << paperSize;
for (int i = 0; i < numPages; i++) {
- PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize, pageRect);
+ PageItem* item = new PageItem(i+1, (*pictures)[i], paperSize);
scene->addItem(item);
pages.append(item);
}
}
-
//Private Slots
void PrintWidget::updateCurrentPage() {
if (viewMode == AllPagesView)
@@ -282,9 +267,13 @@ void PrintWidget::fit(bool doFitting) {
}
}
- zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY());
+ //zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY());
}
void PrintWidget::setPictures(QHash<int, QImage> *hash) {
pictures = hash;
}
+
+void PrintWidget::setOrientation(QPageLayout::Orientation ori) {
+ this->orientation = ori;
+}
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
index 81e4e794..62543e45 100644
--- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
+++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h
@@ -18,18 +18,18 @@
#include <QScrollBar>
#include <QStyleOptionGraphicsItem>
#include <QtMath>
-#include <QPrinter>
+#include <QPageLayout>
+
namespace {
class PageItem : public QGraphicsItem
{
public:
- PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize, QRect _pageRect)
+ PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize)
: pageNum(_pageNum), pagePicture(_pagePicture),
- paperSize(_paperSize), pageRect(_pageRect)
+ paperSize(_paperSize)
{
- qreal border = qMax(paperSize.height(), paperSize.width()) / 25;
- brect = QRectF(QPointF(-border, -border),
- QSizeF(paperSize)+QSizeF(2*border, 2*border));
+ brect = QRectF(QPointF(-25, -25),
+ QSizeF(paperSize)+QSizeF(50, 50));
setCacheMode(DeviceCoordinateCache);
}
@@ -45,7 +45,6 @@ private:
int pageNum;
const QImage pagePicture;
QSize paperSize;
- QRect pageRect;
QRectF brect;
};
@@ -78,17 +77,11 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
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);
+ if (pagePicture.isNull()){
+ qDebug() << "NULL";
+ return;
+ }
+ painter->drawImage(QPoint(0,0), pagePicture);
}
}
@@ -96,7 +89,7 @@ class PrintWidget : public QGraphicsView
{
Q_OBJECT
public:
- PrintWidget(QPrinter *printer, QWidget *parent = 0);
+ PrintWidget(QWidget *parent = 0);
~PrintWidget();
enum ViewMode {
SinglePageView,
@@ -118,23 +111,25 @@ public:
signals:
void resized();
void customContextMenuRequested(const QPoint&);
- void paintRequested(QPrinter*);
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 updatePreview();
void fitView();
void fitToWidth();
void setAllPagesViewMode();
void setSinglePageViewMode();
void setFacingPagesViewMode();
+private slots:
void updateCurrentPage();
int calcCurrentPage();
void fit(bool doFitting=false);
- void updatePreview();
protected:
void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE {
/*{
@@ -156,16 +151,14 @@ private:
void setViewMode(ViewMode);
void setZoomMode(ZoomMode);
QGraphicsScene *scene;
- QPrinter *printer;
- QPreviewPaintEngine *previewEngine;
- QPdfPrintEngine *pdfEngine;
int curPage;
ViewMode viewMode;
ZoomMode zoomMode;
+ QPageLayout::Orientation orientation;
double zoomFactor;
bool initialized, fitting;
- QList<QGraphicsItem *> pages;
+ 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 4e65a766..57afbfe1 100644
--- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
@@ -27,13 +27,13 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
ui->setupUi(this);
this->setWindowTitle(tr("Lumina PDF Viewer"));
this->setWindowIcon( LXDG::findIcon("application-pdf","unknown"));
- this->highlight = false;
presentationLabel = 0;
CurrentPage = 1;
lastdir = QDir::homePath();
- Printer = new QPrinter();
//Create the interface widgets
- WIDGET = new PrintWidget(Printer, this);
+ WIDGET = new PrintWidget(this);
+ WIDGET->setVisible(false);
+ WIDGET->setContextMenuPolicy(Qt::CustomContextMenu);
clockTimer = new QTimer(this);
clockTimer->setInterval(1000); //1-second updates to clock
connect(clockTimer, SIGNAL(timeout()), this, SLOT(updateClock()) );
@@ -52,13 +52,11 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
this->setCentralWidget(WIDGET);
WIDGET->setContextMenuPolicy(Qt::CustomContextMenu);
connect(WIDGET, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(showContextMenu(const QPoint&)) );
- connect(WIDGET, &PrintWidget::paintRequested, this,
- [=](QPrinter *printer) { this->paintOnWidget(printer, this->highlight); });
DOC = 0;
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
@@ -231,17 +229,15 @@ void MainUI::loadFile(QString path){
Poppler::Page *PAGE = DOC->page(0);
if(PAGE!=0){
lastdir = path.section("/",0,-2); //save this for later
- 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;
+ WIDGET->setOrientation(QPageLayout::Landscape); break;
default:
- Printer->setOrientation(QPrinter::Portrait);
+ WIDGET->setOrientation(QPageLayout::Portrait);
}
delete PAGE;
qDebug() << " - Document Setup : start loading pages now";
- startLoadingPages(Printer);
+ startLoadingPages();
//QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview
}
@@ -253,7 +249,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();
@@ -263,7 +259,6 @@ void MainUI::loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, Q
//qDebug() << " - Raw Image Size:" << raw.size();
loadingHash.insert(num, raw.scaled(scalefactor*page.width(), scalefactor*page.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) );
raw = QImage(); //clear it
- //qDebug() << "Page Label:" << num << PAGE->label();
/*
QList<Annotation*> anno = PAGE->annotations(Annotations::AText );
QStringList annoS;
@@ -382,7 +377,7 @@ void MainUI::endPresentation(){
this->releaseKeyboard();
}
-void MainUI::startLoadingPages(QPrinter *printer){
+void MainUI::startLoadingPages(){
if(numPages>0){ return; } //currently loaded[ing]
qDebug() << " - Start Loading Pages";
numPages = DOC->numPages();
@@ -390,17 +385,18 @@ void MainUI::startLoadingPages(QPrinter *printer){
progress->setRange(0,numPages);
progress->setValue(0);
progAct->setVisible(true);
- QRectF pageSize = printer->pageRect(QPrinter::DevicePixel);
- QSize DPI(printer->resolution(),printer->resolution());
+ QSizeF pageSize = DOC->page(0)->pageSizeF()*2;
+ //QSize DPI(loadingHash[0]->resolution(),loadingHash[0]->resolution());
+ QSize DPI(76,76);
/*qDebug() << "Screen Resolutions:";
QList<QScreen*> screens = QApplication::screens();
for(int i=0; i<screens.length(); i++){
qDebug() << screens[i]->name() << screens[i]->logicalDotsPerInchX() << screens[i]->logicalDotsPerInchY();
}*/
+ qDebug() << "Poppler pageSize: " << pageSize;
for(int i=0; i<numPages; i++){
- qDebug() << " - Kickoff page load:" << i;
- //this->ccw = 0;
- QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize.size());
+ //qDebug() << " - Kickoff page load:" << i;
+ QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize);
}
}
@@ -412,7 +408,8 @@ void MainUI::slotPageLoaded(int page){
progAct->setVisible(false);
qDebug() << "Setting Pictures";
WIDGET->setPictures(&loadingHash);
- QTimer::singleShot(10, WIDGET, SLOT(updatePreview()));
+ WIDGET->setVisible(true);
+ //QTimer::singleShot(10, WIDGET, SLOT(updatePreview()));
//qDebug() << "Updating";
ui->actionStop_Presentation->setEnabled(false);
ui->actionStart_Here->setEnabled(true);
@@ -426,52 +423,6 @@ void MainUI::slotPageLoaded(int page){
startPresentation(act == ui->actionAt_Beginning);
}*/
-void MainUI::paintOnWidget(QPrinter *PRINTER, bool highlight){
- static bool first = true;
- static bool shrunk = false;
- if(DOC==0){ return; }
- if(loadingHash.keys().length() != numPages){ startLoadingPages(PRINTER); return; }
- //Increase the resolution of the page to match the image to prevent downscaling
- if(first)
- PRINTER->setPageSize(QPageSize(PRINTER->pageRect().size()*2));
- qDebug() << PRINTER->pageRect().size() << loadingHash[0].size() << WIDGET->size();
- QPainter painter(PRINTER);
- painter.setPen(Qt::NoPen);
- if(ui->findGroup->isVisible()) {
- QSize size = PRINTER->pageRect().size();
- size = QSize(size.width(), size.height()-ui->findGroup->height());
- PRINTER->setPageSize(QPageSize(size));
- shrunk = true;
- }else if(shrunk){
- QSize size = PRINTER->pageRect().size();
- size = QSize(size.width(), size.height()+ui->findGroup->height());
- PRINTER->setPageSize(QPageSize(size));
- shrunk = false;
- }
- if(highlight) {
- Poppler::TextBox *currentText = results.keys()[currentHighlight];
- int pageNum = results.value(currentText), i;
-
- for(i = 0; i <= pageNum; i++)
- if(i != 0){ PRINTER->newPage(); }
-
- qDebug() << pageNum << i;
- this->highlight=false;
- }else {
- for(int i=0; i<numPages; i++){
- if(i != 0){ PRINTER->newPage(); } //this is the start of the next page (not needed for first)
- if(loadingHash.contains(i)){
- painter.drawImage(0,0, loadingHash[i].scaled(PRINTER->pageRect().size(),
- Qt::KeepAspectRatio, Qt::SmoothTransformation));
- }
- else{ painter.drawImage(0,0, QImage()); }
- }
- WIDGET->setContextMenuPolicy(Qt::CustomContextMenu);
- //loadingHash.clear();
- first = false;
- }
-}
-
void MainUI::paintToPrinter(QPrinter *PRINTER){
if(loadingHash.keys().length() != numPages){ return; }
@@ -561,9 +512,8 @@ void MainUI::rotate(bool ccw) {
loadingHash.insert(i, image);
}
//Rotates the page as well as the image
- Printer->setOrientation((Printer->orientation() == QPrinter::Landscape) ?
- QPrinter::Portrait : QPrinter::Landscape);
-
+ //WIDGET->setOrientation((WIDGET->orientation() == QPageLayout::Landscape) ?
+ //QPageLayout::Portrait : QPageLayout::Landscape);
QTimer::singleShot(0, WIDGET, SLOT(updatePreview()));
}
@@ -664,9 +614,9 @@ void MainUI::find(QString text, bool forward) {
Poppler::TextBox *currentText = results.keys()[currentHighlight];
WIDGET->setCurrentPage(results.value(currentText));
+ WIDGET->highlightText(currentHighlight, currentText->boundingBox());
- QTimer::singleShot(0, WIDGET, SLOT(updatePreview()));
- this->highlight = true;
+ QTimer::singleShot(10, WIDGET, SLOT(updatePreview()));
}else{
//Print "No results found"
}
@@ -705,16 +655,3 @@ void MainUI::resizeEvent(QResizeEvent *event) {
}
QMainWindow::resizeEvent(event);
}
-
-void MainUI::highlightText(QPrinter *PRINTER) {
- Poppler::TextBox *currentText = results.keys()[currentHighlight];
- QPainter painter(PRINTER);
- painter.setPen(Qt::NoPen);
- int pageNum = results.value(currentText), i;
-
- for(i = 0; i <= pageNum; i++)
- if(i != 0){ PRINTER->newPage(); }
-
- qDebug() << pageNum << i;
- this->highlight=false;
-}
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h
index b3ad38f1..2d23b402 100644
--- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h
+++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h
@@ -41,10 +41,9 @@ private:
PrintWidget *WIDGET;
Ui::MainUI *ui;
PropDialog *PROPDIALOG;
- QPrinter* Printer;
QPrintDialog *PrintDLG;
QString lastdir;
- bool matchCase, highlight;
+ bool matchCase;
QMap<Poppler::TextBox*, int> results;
int currentHighlight;
@@ -62,7 +61,6 @@ private:
int numPages;
void loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page);
- void highlightText(QPrinter *PRINTER);
//Functions/variables for the presentation mode
PresentationLabel *presentationLabel;
@@ -73,7 +71,7 @@ private:
void endPresentation();
private slots:
- void startLoadingPages(QPrinter *printer);
+ void startLoadingPages();
void slotPageLoaded(int);
//void slotStartPresentation(QAction *act);
@@ -85,12 +83,12 @@ private slots:
void startPresentationHere(){ startPresentation(false); }
void startPresentationBeginning(){ startPresentation(true); }
void closePresentation(){ endPresentation(); }
+
void showInformation();
void find(QString text, bool forward);
void enableFind();
void showBookmarks();
- void paintOnWidget(QPrinter*, bool);
void paintToPrinter(QPrinter *PRINTER);
//Button Slots
bgstack15