diff options
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp | 15 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/PrintWidget.h | 36 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 33 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-pdf/mainUI.h | 6 |
4 files changed, 49 insertions, 41 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index d2f2cd46..145ce311 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -16,6 +16,7 @@ PrintWidget::PrintWidget(QWidget *parent) : QGraphicsView(parent), scene(0), cur QObject::connect(this->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateCurrentPage())); QObject::connect(this, SIGNAL(resized()), this, SLOT(fit())); + QObject::connect(parent, SIGNAL(sendDocument(Poppler::Document*)), this, SLOT(receiveDocument(Poppler::Document*))); scene = new QGraphicsScene(this); scene->setBackgroundBrush(Qt::gray); @@ -125,7 +126,7 @@ void PrintWidget::setCurrentPage(int pageNumber) { } void PrintWidget::highlightText(int pageNum, QRectF textBox) { - PageItem *item = static_cast<PageItem*>(pages[pageNum]); + //PageItem *item = static_cast<PageItem*>(pages[pageNum]); QPainter painter(this); painter.fillRect(textBox, QColor(255, 255, 177, 128)); } @@ -185,7 +186,7 @@ void PrintWidget::populateScene() qDebug() << "Image paperSize" << paperSize; for (int i = 0; i < numPages; i++) { - PageItem* item = new PageItem(i+1, (*pictures)[i].scaled( paperSize, Qt::KeepAspectRatio, Qt::SmoothTransformation), paperSize); + PageItem* item = new PageItem(i+1, (*pictures)[i].scaled( paperSize, Qt::KeepAspectRatio, Qt::SmoothTransformation), paperSize, degrees); scene->addItem(item); pages.append(item); } @@ -281,6 +282,12 @@ void PrintWidget::setPictures(QHash<int, QImage> *hash) { pictures = hash; } -void PrintWidget::setOrientation(QPageLayout::Orientation ori) { - this->orientation = ori; +void PrintWidget::receiveDocument(Poppler::Document *DOC) { + this->doc = DOC; + this->setVisible(true); +} + +void PrintWidget::setDegrees(int degrees) { + this->degrees = degrees; + this->updatePreview(); } diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h index 0bc2dbac..da0dc8d3 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h @@ -20,10 +20,12 @@ #include <QtMath> #include <QPageLayout> +#include <poppler/qt5/poppler-qt5.h> + class PageItem : public QGraphicsItem { public: - PageItem(int _pageNum, const QImage _pagePicture, QSize _paperSize) - : pageNum(_pageNum), pagePicture(_pagePicture), paperSize(_paperSize) + PageItem(int _pageNum, QImage _pagePicture, QSize _paperSize, int _degrees) + : pageNum(_pageNum), pagePicture(_pagePicture), paperSize(_paperSize), degrees(_degrees) { brect = QRectF(QPointF(-25, -25), QSizeF(paperSize)+QSizeF(50, 50)); @@ -68,20 +70,37 @@ public: cgrad.setColorAt(1.0, QColor(0,0,0,0)); painter->fillRect(cshadow, QBrush(cgrad)); + QMatrix matrix; + switch(degrees) { + case -90: + matrix = QMatrix(0, -1, 1, 0, 0, 0); + break; + case 90: + matrix = QMatrix(0, 1, -1, 0, 0, 0); + break; + default: + matrix = QMatrix(1, 0, 0, 1, 0 ,0); + } + painter->setClipRect(paperRect & option->exposedRect); painter->fillRect(paperRect, Qt::white); if (pagePicture.isNull()){ qDebug() << "NULL"; return; } + + if(degrees != 0) + pagePicture = pagePicture.transformed(matrix, Qt::SmoothTransformation); + painter->drawImage(QPoint(0,0), pagePicture); } private: - int pageNum; - const QImage pagePicture; - QSize paperSize; - QRectF brect; + int pageNum; + QImage pagePicture; + QSize paperSize; + QRectF brect; + int degrees; }; @@ -118,6 +137,8 @@ private: bool initialized, fitting; QList<QGraphicsItem*> pages; QHash<int, QImage> *pictures; + Poppler::Document *doc; + int degrees; public: PrintWidget(QWidget *parent = 0); @@ -138,8 +159,9 @@ public slots: void zoomOut(double factor=1.2); void setCurrentPage(int); void setVisible(bool) Q_DECL_OVERRIDE; - void setOrientation(QPageLayout::Orientation); void highlightText(int, QRectF); + void receiveDocument(Poppler::Document*); + void setDegrees(int); void updatePreview(); void fitView(); diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index fc7c1105..c358d0a1 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -106,8 +106,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ //connect(ui->actionSelect_Mode, &QAction::triggered, this, [&] { this->setScroll(false); }); connect(ui->actionZoom_In, &QAction::triggered, WIDGET, [&] { WIDGET->zoomIn(1.2); }); connect(ui->actionZoom_Out, &QAction::triggered, WIDGET, [&] { WIDGET->zoomOut(1.2); }); - connect(ui->actionRotate_Counterclockwise, &QAction::triggered, this, [&] { this->rotate(true); }); - connect(ui->actionRotate_Clockwise, &QAction::triggered, this, [&] { this->rotate(false); }); + connect(ui->actionRotate_Counterclockwise, &QAction::triggered, this, [&] { WIDGET->setDegrees(-90); }); + connect(ui->actionRotate_Clockwise, &QAction::triggered, this, [&] { WIDGET->setDegrees(90); }); connect(ui->actionZoom_In_2, &QAction::triggered, WIDGET, [&] { WIDGET->zoomIn(1.2); }); connect(ui->actionZoom_Out_2, &QAction::triggered, WIDGET, [&] { WIDGET->zoomOut(1.2); }); connect(ui->actionFirst_Page, SIGNAL(triggered()), this, SLOT(firstPage()) ); @@ -237,12 +237,12 @@ void MainUI::loadFile(QString path){ Poppler::Page *PAGE = DOC->page(0); if(PAGE!=0){ lastdir = path.section("/",0,-2); //save this for later - switch(PAGE->orientation()){ + /*switch(PAGE->orientation()){ case Poppler::Page::Landscape: WIDGET->setOrientation(QPageLayout::Landscape); break; default: WIDGET->setOrientation(QPageLayout::Portrait); - } + }*/ delete PAGE; qDebug() << " - Document Setup : start loading pages now"; startLoadingPages(); @@ -422,11 +422,8 @@ void MainUI::slotPageLoaded(int page){ //qDebug() << " - finished:" << finished; if(finished == numPages){ progAct->setVisible(false); - //qDebug() << "Setting Pictures"; WIDGET->setPictures(&loadingHash); - WIDGET->setVisible(true); - QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); - //qDebug() << "Updating"; + emit sendDocument(DOC); ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(true); ui->actionStart_Begin->setEnabled(true); @@ -526,29 +523,13 @@ void MainUI::updatePageNumber(){ label_page->setText( text.arg( QString::number(WIDGET->currentPage()), QString::number(numPages) )); } -void MainUI::setScroll(bool tog) { +/*void MainUI::setScroll(bool tog) { if(tog) { QApplication::setOverrideCursor(Qt::OpenHandCursor); }else{ QApplication::setOverrideCursor(Qt::IBeamCursor); } -} - -void MainUI::rotate(bool ccw) { - for(int i = 0; i < numPages; i++) { - QImage image = loadingHash[i]; - qDebug() << "Page rotating: " << i; - //Setup a rotation matrix that rotates 90 degrees clockwise or counterclockwise - QMatrix matrix = (ccw) ? QMatrix(0, -1, 1, 0, 0, 0) : QMatrix(0, 1, -1, 0, 0, 0); - image = image.transformed(matrix, Qt::SmoothTransformation); - //Updates the image in the hash - loadingHash.insert(i, image); - } - //Rotates the page as well as the image - //WIDGET->setOrientation((WIDGET->orientation() == QPageLayout::Landscape) ? - //QPageLayout::Portrait : QPageLayout::Landscape); - QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); -} +}*/ void MainUI::updateContextMenu(){ contextMenu->clear(); diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 5a22905a..399404a1 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -98,13 +98,11 @@ private slots: void updatePageNumber(); void showContextMenu(const QPoint&){ contextMenu->popup(QCursor::pos()); } void updateContextMenu(); - - void setScroll(bool); - void rotate(bool); - + //void setScroll(bool); signals: void PageLoaded(int); + void sendDocument(Poppler::Document*); protected: void keyPressEvent(QKeyEvent*); |