From 6c5a1d42db02985ed64ca744215bb23fca276143 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Mon, 18 Dec 2017 16:05:27 -0500 Subject: Finished rotation and working on changing keys in lumina-pdf --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 136 ++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 29 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index ce2707c9..b4847609 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -28,7 +28,6 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ this->setWindowIcon( LXDG::findIcon("application-pdf","unknown")); presentationLabel = 0; CurrentPage = 0; - ccw = 0; lastdir = QDir::homePath(); Printer = new QPrinter(); //Create the interface widgets @@ -91,8 +90,10 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ connect(ui->actionScroll_Mode, SIGNAL(toggled(bool)), this, SLOT(setScroll(bool)) ); 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(Printer, true); }); - connect(ui->actionRotate_Clockwise, &QAction::triggered, this, [&] { this->rotate(Printer, false); }); + connect(ui->actionRotate_Counterclockwise, &QAction::triggered, this, [&] { this->rotate(true); }); + connect(ui->actionRotate_Clockwise, &QAction::triggered, this, [&] { this->rotate(false); }); + connect(ui->actionZoom_In_2, &QAction::triggered, WIDGET, [&] { WIDGET->zoomIn(1.2); }); + connect(ui->actionZoom_Out_2, &QAction::triggered, WIDGET, [&] { WIDGET->zoomOut(1.2); }); //Setup all the icons ui->actionPrint->setIcon( LXDG::findIcon("document-print","")); @@ -106,6 +107,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->actionScroll_Mode->setIcon(LXDG::findIcon("cursor-pointer","")); ui->actionZoom_In->setIcon(LXDG::findIcon("zoom-in","")); ui->actionZoom_Out->setIcon(LXDG::findIcon("zoom-out","")); + ui->actionZoom_In_2->setIcon(LXDG::findIcon("zoom-in","")); + ui->actionZoom_Out_2->setIcon(LXDG::findIcon("zoom-out","")); ui->actionRotate_Counterclockwise->setIcon(LXDG::findIcon("object-rotate-left","")); ui->actionRotate_Clockwise->setIcon(LXDG::findIcon("object-rotate-right","")); @@ -311,8 +314,6 @@ void MainUI::startLoadingPages(QPrinter *printer){ progress->setValue(0); progAct->setVisible(true); QRectF pageSize = printer->pageRect(QPrinter::DevicePixel); - printer->setPageSize(QPageSize(QSize(pageSize.width()*2, pageSize.height()*2))); - qDebug() << "Starting size" << pageSize.size(); QSize DPI(printer->resolution(),printer->resolution()); /*qDebug() << "Screen Resolutions:"; QList screens = QApplication::screens(); @@ -321,7 +322,7 @@ void MainUI::startLoadingPages(QPrinter *printer){ }*/ for(int i=0; iccw = 0; + //this->ccw = 0; QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize.size()); } } @@ -332,7 +333,7 @@ void MainUI::slotPageLoaded(int page){ if(finished == numPages){ progAct->setVisible(false); QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); - qDebug() << "Updating"; + //qDebug() << "Updating"; ui->actionStop_Presentation->setEnabled(false); ui->menuStart_Presentation->setEnabled(true); }else{ @@ -346,24 +347,19 @@ void MainUI::slotStartPresentation(QAction *act){ void MainUI::paintOnWidget(QPrinter *PRINTER){ if(DOC==0){ return; } - //this->show(); - qDebug() << "Painting"; - qDebug() << numPages << loadingHash.keys().length(); if(loadingHash.keys().length() != numPages){ startLoadingPages(PRINTER); return; } + //Increase the resolution of the page to match the image to prevent downscaling + PRINTER->setPageSize(QPageSize(PRINTER->pageRect().size()*2)); + qDebug() << PRINTER->pageRect().size() << loadingHash[0].size(); QPainter painter(PRINTER); - for(int i=0; inewPage(); } //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)); qDebug() << PRINTER->pageRect().size();} - else{ painter.drawImage(0,0, QImage()); } - if(ccw != 0) { - QTransform transform; - transform.rotate((ccw-1) ? 270 : 90); - painter.setTransform(transform); - //painter.rotate((ccw-1) ? 270 : 90); - } - } + for(int i=0; inewPage(); } //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(); } void MainUI::paintToPrinter(QPrinter *PRINTER){ @@ -403,7 +399,6 @@ void MainUI::paintToPrinter(QPrinter *PRINTER){ } } //qDebug() << "Final Page Range:" << pageCount; - //return; //Generate the sizing information for the printer QSize sz(PRINTER->pageRect().width(), PRINTER->pageRect().height()); bool landscape = PRINTER->orientation()==QPrinter::Landscape; @@ -443,15 +438,20 @@ void MainUI::setScroll(bool tog) { }else{ QApplication::setOverrideCursor(Qt::IBeamCursor); } - //WIDGET-> } -void MainUI::rotate(QPrinter *printer, bool ccw) { - QRectF pageSize = printer->pageRect(QPrinter::DevicePixel); - QSize dpi(printer->resolution(),printer->resolution()); - this->ccw = ccw+1; - for(int i=0; i < numPages; i++) - QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, dpi, pageSize.size()); +void MainUI::rotate(bool ccw) { + for(int i = 0; i < numPages; i++) { + QImage image = loadingHash[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() == QPrinter::Landscape) ? QPrinter::Portrait : QPrinter::Landscape); + WIDGET->updatePreview(); } void MainUI::updateContextMenu(){ @@ -472,3 +472,81 @@ void MainUI::updateContextMenu(){ contextMenu->addAction(tr("Stop Presentation"), this, SLOT(closePresentation()) ); } } + +void MainUI::keyPressEvent(QKeyEvent *event){ + //See if this is one of the special hotkeys and act appropriately + bool inPresentation = (presentationLabel!=0); + /*QWheelEvent wEvent( WIDGET->mapFromGlobal(QCursor::pos()), QCursor::pos(),QPoint(0,0), QPoint(0,30), 0, Qt::Vertical, Qt::LeftButton, Qt::NoModifier); + qDebug() << "KeyPressed"; + switch(event->key()) { + case Qt::Key_Escape: + case Qt::Key_Backspace: + qDebug() << " - Escape/Backspace"; + if(inPresentation){ endPresentation(); } + break; + case Qt::Key_Right: + case Qt::Key_Space: + case Qt::Key_PageDown: + qDebug() << " - Right/Down/Spacebar" << inPresentation; + nextPage(); + break; + case Qt::Key_Left: + case Qt::Key_PageUp: + qDebug() << " - Left/Up"; + prevPage(); + break; + case Qt::Key_Home: + qDebug() << " - Home"; + firstPage(); + break; + case Qt::Key_End: + qDebug() << " - End"; + lastPage(); + break; + case Qt::Key_F11: + qDebug() << " - F11"; + if(inPresentation){ endPresentation(); } + else{ startPresentationHere(); } + break; + case Qt::Key_Up: + break; + case Qt::Key_Down: + qDebug() << "Send Wheel Event"; + QApplication::sendEvent(WIDGET, &wEvent); + //WIDGET->scrollDown(); + break; + default: + QMainWindow::keyPressEvent(event); + }*/ + if( event->key()==Qt::Key_Escape || event->key()==Qt::Key_Backspace){ + qDebug() << " - Escape/Backspace"; + if(inPresentation){ endPresentation(); } + }else if(event->key()==Qt::Key_Right || event->key()==Qt::Key_Space || event->key()==Qt::Key_PageDown){ + qDebug() << " - Right/Down/Spacebar" << inPresentation; + nextPage(); + }else if(event->key()==Qt::Key_Left || event->key()==Qt::Key_PageUp){ + qDebug() << " - Left/Up"; + prevPage(); + }else if(event->key()==Qt::Key_Home){ + qDebug() << " - Home"; + firstPage(); + }else if(event->key()==Qt::Key_End){ + qDebug() << " - End"; + lastPage(); + }else if(event->key()==Qt::Key_F11){ + qDebug() << " - F11"; + if(inPresentation){ endPresentation(); } + else{ startPresentationHere(); } + }else if(event->key() == Qt::Key_Up) { + qDebug() << " - KeyUp"; + + }else if(event->key() == Qt::Key_Down) { + /*qDebug() << "Send Wheel Event"; + QWheelEvent wEvent( WIDGET->mapFromGlobal(QCursor::pos()), QCursor::pos(),QPoint(0,0), QPoint(0,30), 0, Qt::Vertical, Qt::LeftButton, Qt::NoModifier); + QApplication::sendEvent(WIDGET, &wEvent);*/ + qDebug() << " - KeyDown"; + //WIDGET->scroll(0, 30); + }else{ + QMainWindow::keyPressEvent(event); + } +} -- cgit From f4d3efca1f72dd152db2128568117445ada07789 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Mon, 18 Dec 2017 19:05:35 -0500 Subject: Added missing icons and created actions for later implemented functions --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 75 ++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 18 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index b4847609..d16bef85 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -53,7 +53,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ PrintDLG = new QPrintDialog(this); connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) ); - connect(ui->menuStart_Presentation, SIGNAL(triggered(QAction*)), this, SLOT(slotStartPresentation(QAction*)) ); + //connect(ui->menuStart_Presentation, SIGNAL(triggered(QAction*)), this, SLOT(slotStartPresentation(QAction*)) ); //Create the other interface widgets progress = new QProgressBar(this); @@ -87,13 +87,36 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ connect(ui->actionSingle_Page, SIGNAL(triggered()), WIDGET, SLOT(setSinglePageViewMode()) ); connect(ui->actionDual_Pages, SIGNAL(triggered()), WIDGET, SLOT(setFacingPagesViewMode()) ); connect(ui->actionAll_Pages, SIGNAL(triggered()), WIDGET, SLOT(setAllPagesViewMode()) ); - connect(ui->actionScroll_Mode, SIGNAL(toggled(bool)), this, SLOT(setScroll(bool)) ); + //connect(ui->actionScroll_Mode, &QAction::triggered, this, [&] { this->setScroll(true); }); + //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->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()) ); + connect(ui->actionPrevious_Page, SIGNAL(triggered()), this, SLOT(prevPage()) ); + connect(ui->actionNext_Page, SIGNAL(triggered()), this, SLOT(nextPage()) ); + connect(ui->actionLast_Page, SIGNAL(triggered()), this, SLOT(lastPage()) ); + + //int curP = WIDGET->currentPage()-1; //currentPage reports pages starting at 1 + //int lastP = numPages-1; + ui->actionFirst_Page->setText(tr("First Page")); + ui->actionPrevious_Page->setText(tr("Previous Page")); + ui->actionNext_Page->setText(tr("Next Page")); + ui->actionLast_Page->setText(tr("Last Page")); + /*ui->actionFirst_Page->setEnabled(curP!=0); + ui->actionPrevious_Page->setEnabled(curP>0); + ui->actionNext_Page->setEnabled(curPactionLast_Page->setEnabled(curP!=lastP);*/ + + ui->actionStart_Here->setText(tr("Start Presentation (current slide)")); + connect(ui->actionStart_Here, SIGNAL(triggered()), this, SLOT(startPresentationHere()) ); + ui->actionStart_Begin->setText(tr("Start Presentation (at beginning)")); + connect(ui->actionStart_Begin, SIGNAL(triggered()), this, SLOT(startPresentationBeginning()) ); + ui->actionStop_Presentation->setText(tr("Stop Presentation")); + connect(ui->actionStop_Presentation, SIGNAL(triggered()), this, SLOT(closePresentation()) ); //Setup all the icons ui->actionPrint->setIcon( LXDG::findIcon("document-print","")); @@ -105,16 +128,31 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->actionDual_Pages->setIcon(LXDG::findIcon("format-view-grid-small","")); ui->actionAll_Pages->setIcon(LXDG::findIcon("format-view-grid-large","")); ui->actionScroll_Mode->setIcon(LXDG::findIcon("cursor-pointer","")); + ui->actionSelect_Mode->setIcon(LXDG::findIcon("cursor-text","")); ui->actionZoom_In->setIcon(LXDG::findIcon("zoom-in","")); ui->actionZoom_Out->setIcon(LXDG::findIcon("zoom-out","")); ui->actionZoom_In_2->setIcon(LXDG::findIcon("zoom-in","")); ui->actionZoom_Out_2->setIcon(LXDG::findIcon("zoom-out","")); ui->actionRotate_Counterclockwise->setIcon(LXDG::findIcon("object-rotate-left","")); ui->actionRotate_Clockwise->setIcon(LXDG::findIcon("object-rotate-right","")); + ui->actionFirst_Page->setIcon(LXDG::findIcon("go-first","")); + ui->actionPrevious_Page->setIcon(LXDG::findIcon("go-previous","")); + ui->actionNext_Page->setIcon(LXDG::findIcon("go-next","")); + ui->actionLast_Page->setIcon(LXDG::findIcon("go-last","")); + ui->actionStart_Here->setIcon(LXDG::findIcon("media-playback-start-circled","")); + ui->actionStart_Begin->setIcon(LXDG::findIcon("presentation-play","")); + ui->actionStop_Presentation->setIcon(LXDG::findIcon("media-playback-stop-circled","")); + ui->actionBookmarks->setIcon(LXDG::findIcon("bookmark-new","")); + ui->actionFind->setIcon(LXDG::findIcon("edit-find","")); + ui->actionFind_Next->setIcon(LXDG::findIcon("edit-find-next","")); + ui->actionFind_Previous->setIcon(LXDG::findIcon("edit-find-prev","")); + ui->actionProperties->setIcon(LXDG::findIcon("dialog-information","")); + ui->actionSettings->setIcon(LXDG::findIcon("document-properties","")); //Now set the default state of the menu's and actions - ui->menuStart_Presentation->setEnabled(false); ui->actionStop_Presentation->setEnabled(false); + ui->actionStart_Here->setEnabled(false); + ui->actionStart_Begin->setEnabled(false); } MainUI::~MainUI(){ @@ -259,7 +297,8 @@ void MainUI::startPresentation(bool atStart){ presentationLabel->showFullScreen(); ui->actionStop_Presentation->setEnabled(true); - ui->menuStart_Presentation->setEnabled(false); + ui->actionStart_Here->setEnabled(false); + ui->actionStart_Begin->setEnabled(false); updateClock(); clockAct->setVisible(true); clockTimer->start(); @@ -299,7 +338,8 @@ void MainUI::endPresentation(){ if(presentationLabel==0 || !presentationLabel->isVisible()){ return; } //not in presentation mode presentationLabel->hide(); //just hide this (no need to re-create the label for future presentations) ui->actionStop_Presentation->setEnabled(false); - ui->menuStart_Presentation->setEnabled(true); + ui->actionStart_Here->setEnabled(true); + ui->actionStart_Begin->setEnabled(true); clockTimer->stop(); clockAct->setVisible(false); this->releaseKeyboard(); @@ -335,15 +375,16 @@ void MainUI::slotPageLoaded(int page){ QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); //qDebug() << "Updating"; ui->actionStop_Presentation->setEnabled(false); - ui->menuStart_Presentation->setEnabled(true); + ui->actionStart_Here->setEnabled(true); + ui->actionStart_Begin->setEnabled(true); }else{ progress->setValue(finished); } } -void MainUI::slotStartPresentation(QAction *act){ +/*void MainUI::slotStartPresentation(QAction *act){ startPresentation(act == ui->actionAt_Beginning); -} +}*/ void MainUI::paintOnWidget(QPrinter *PRINTER){ if(DOC==0){ return; } @@ -456,20 +497,18 @@ void MainUI::rotate(bool ccw) { void MainUI::updateContextMenu(){ contextMenu->clear(); - int curP = WIDGET->currentPage()-1; //currentPage reports pages starting at 1 - int lastP = numPages-1; - contextMenu->addSection( QString(tr("Page %1 of %2")).arg(QString::number(curP+1), QString::number(lastP+1) ) ); - contextMenu->addAction(tr("Next Page"), this, SLOT(nextPage()))->setEnabled(curPaddAction(tr("Previous Page"), this, SLOT(prevPage()))->setEnabled( curP>0 ); + contextMenu->addSection( QString(tr("Page %1 of %2")).arg(QString::number(WIDGET->currentPage()), QString::number(numPages) ) ); + contextMenu->addAction(ui->actionPrevious_Page); + contextMenu->addAction(ui->actionNext_Page); contextMenu->addSeparator(); - contextMenu->addAction(tr("First Page"), this, SLOT(firstPage()))->setEnabled(curP!=0); - contextMenu->addAction(tr("Last Page"), this, SLOT(lastPage()))->setEnabled(curP!=lastP); + contextMenu->addAction(ui->actionFirst_Page); + contextMenu->addAction(ui->actionLast_Page); contextMenu->addSeparator(); if(presentationLabel==0 || !presentationLabel->isVisible()){ - contextMenu->addAction(tr("Start Presentation (current slide)"), this, SLOT(startPresentationHere()) ); - contextMenu->addAction(tr("Start Presentation (at beginning)"), this, SLOT(startPresentationBeginning()) ); + contextMenu->addAction(ui->actionStart_Begin); + contextMenu->addAction(ui->actionStart_Here); }else{ - contextMenu->addAction(tr("Stop Presentation"), this, SLOT(closePresentation()) ); + contextMenu->addAction(ui->actionStop_Presentation); } } -- cgit From a774d58cd478a5473d8328b2a9689bc53a37dbc1 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Wed, 20 Dec 2017 14:41:12 -0500 Subject: Fixed keyboard focus and added an information dialog to lumina-pdf --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 85 ++++++++++------------------- 1 file changed, 30 insertions(+), 55 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index d16bef85..f0429b9d 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -46,6 +46,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ //Now put the widgets into the UI 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, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); DOC = 0; @@ -99,6 +100,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ connect(ui->actionPrevious_Page, SIGNAL(triggered()), this, SLOT(prevPage()) ); connect(ui->actionNext_Page, SIGNAL(triggered()), this, SLOT(nextPage()) ); connect(ui->actionLast_Page, SIGNAL(triggered()), this, SLOT(lastPage()) ); + connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(showInformation())); //int curP = WIDGET->currentPage()-1; //currentPage reports pages starting at 1 //int lastP = numPages-1; @@ -368,6 +370,7 @@ void MainUI::startLoadingPages(QPrinter *printer){ } void MainUI::slotPageLoaded(int page){ + Q_UNUSED(page); //qDebug() << "Page Loaded:" << page; int finished = loadingHash.keys().length(); if(finished == numPages){ @@ -491,13 +494,15 @@ void MainUI::rotate(bool ccw) { loadingHash.insert(i, image); } //Rotates the page as well as the image - WIDGET->setOrientation((WIDGET->orientation() == QPrinter::Landscape) ? QPrinter::Portrait : QPrinter::Landscape); + WIDGET->setOrientation((WIDGET->orientation() == QPrinter::Landscape) ? + QPrinter::Portrait : QPrinter::Landscape); WIDGET->updatePreview(); } void MainUI::updateContextMenu(){ contextMenu->clear(); - contextMenu->addSection( QString(tr("Page %1 of %2")).arg(QString::number(WIDGET->currentPage()), QString::number(numPages) ) ); + contextMenu->addSection( QString(tr("Page %1 of %2")).arg(QString::number(WIDGET->currentPage()), + QString::number(numPages) ) ); contextMenu->addAction(ui->actionPrevious_Page); contextMenu->addAction(ui->actionNext_Page); contextMenu->addSeparator(); @@ -515,77 +520,47 @@ void MainUI::updateContextMenu(){ void MainUI::keyPressEvent(QKeyEvent *event){ //See if this is one of the special hotkeys and act appropriately bool inPresentation = (presentationLabel!=0); - /*QWheelEvent wEvent( WIDGET->mapFromGlobal(QCursor::pos()), QCursor::pos(),QPoint(0,0), QPoint(0,30), 0, Qt::Vertical, Qt::LeftButton, Qt::NoModifier); - qDebug() << "KeyPressed"; - switch(event->key()) { - case Qt::Key_Escape: - case Qt::Key_Backspace: - qDebug() << " - Escape/Backspace"; - if(inPresentation){ endPresentation(); } - break; - case Qt::Key_Right: - case Qt::Key_Space: - case Qt::Key_PageDown: - qDebug() << " - Right/Down/Spacebar" << inPresentation; - nextPage(); - break; - case Qt::Key_Left: - case Qt::Key_PageUp: - qDebug() << " - Left/Up"; - prevPage(); - break; - case Qt::Key_Home: - qDebug() << " - Home"; - firstPage(); - break; - case Qt::Key_End: - qDebug() << " - End"; - lastPage(); - break; - case Qt::Key_F11: - qDebug() << " - F11"; - if(inPresentation){ endPresentation(); } - else{ startPresentationHere(); } - break; - case Qt::Key_Up: - break; - case Qt::Key_Down: - qDebug() << "Send Wheel Event"; - QApplication::sendEvent(WIDGET, &wEvent); - //WIDGET->scrollDown(); - break; - default: - QMainWindow::keyPressEvent(event); - }*/ if( event->key()==Qt::Key_Escape || event->key()==Qt::Key_Backspace){ - qDebug() << " - Escape/Backspace"; if(inPresentation){ endPresentation(); } - }else if(event->key()==Qt::Key_Right || event->key()==Qt::Key_Space || event->key()==Qt::Key_PageDown){ - qDebug() << " - Right/Down/Spacebar" << inPresentation; + }else if(event->key()==Qt::Key_Right || event->key()==Qt::Key_Space || + event->key()==Qt::Key_PageDown){ nextPage(); }else if(event->key()==Qt::Key_Left || event->key()==Qt::Key_PageUp){ - qDebug() << " - Left/Up"; prevPage(); }else if(event->key()==Qt::Key_Home){ - qDebug() << " - Home"; firstPage(); }else if(event->key()==Qt::Key_End){ - qDebug() << " - End"; lastPage(); }else if(event->key()==Qt::Key_F11){ - qDebug() << " - F11"; if(inPresentation){ endPresentation(); } else{ startPresentationHere(); } }else if(event->key() == Qt::Key_Up) { - qDebug() << " - KeyUp"; - + //Scroll the widget up }else if(event->key() == Qt::Key_Down) { + //Scroll the widget down /*qDebug() << "Send Wheel Event"; QWheelEvent wEvent( WIDGET->mapFromGlobal(QCursor::pos()), QCursor::pos(),QPoint(0,0), QPoint(0,30), 0, Qt::Vertical, Qt::LeftButton, Qt::NoModifier); QApplication::sendEvent(WIDGET, &wEvent);*/ - qDebug() << " - KeyDown"; - //WIDGET->scroll(0, 30); }else{ QMainWindow::keyPressEvent(event); } } + +void MainUI::wheelEvent(QWheelEvent *event) { + //Scroll the window according to the mouse wheel + QMainWindow::wheelEvent(event); +} + +void MainUI::newFocus(QWidget *oldW, QWidget *newW) { + Q_UNUSED(oldW); + //qDebug() << "NEW: " << newW << "OLD: " << oldW; + if(newW and newW != this) { + newW->setFocusPolicy(Qt::NoFocus); + this->setFocus(); + } +} + +void MainUI::showInformation() { + PROPDIALOG = new PropDialog(DOC); + PROPDIALOG->show(); +} -- cgit From 5162021eb02f0004b77104fa14088ab7504cb66e Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Fri, 22 Dec 2017 20:30:23 -0500 Subject: Progress toward search functionality for lumina-pdf --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 98 ++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index f0429b9d..6045a1bc 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -44,6 +45,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ contextMenu = new QMenu(this); connect(contextMenu, SIGNAL(aboutToShow()), this, SLOT(updateContextMenu())); //Now put the widgets into the UI + ui->bookmarksFrame->setParent(WIDGET); + ui->findGroup->setParent(WIDGET); this->setCentralWidget(WIDGET); WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(newFocus(QWidget*, QWidget*))); @@ -101,6 +104,23 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ connect(ui->actionNext_Page, SIGNAL(triggered()), this, SLOT(nextPage()) ); connect(ui->actionLast_Page, SIGNAL(triggered()), this, SLOT(lastPage()) ); connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(showInformation())); + connect(ui->actionFind, SIGNAL(triggered()), this, SLOT(enableFind())); + connect(ui->actionFind_Next, &QAction::triggered, this, + [&] { find(ui->textEdit->toPlainText(), true); }); + connect(ui->actionFind_Previous, &QAction::triggered, this, + //[&] { find(ui->textEdit->toPlainText(), false); }); + [&] { find("Revision", false); }); + connect(ui->findNextB, &QPushButton::clicked, this, + [&] { find(ui->textEdit->toPlainText(), true); }); + connect(ui->findPrevB, &QPushButton::clicked, this, + [&] { find(ui->textEdit->toPlainText(), false); }); + connect(ui->matchCase, &QPushButton::clicked, this, + [&] (bool value) { this->matchCase = value; }); + connect(ui->closeFind, &QPushButton::clicked, this, + [&] { ui->findGroup->setVisible(false); this->setFocus(); }); + connect(ui->actionClearHighlights, &QAction::triggered, WIDGET, + [&] { clearHighlights = true; WIDGET->update(); }); + connect(ui->actionBookmarks, SIGNAL(triggered()), this, SLOT(showBookmarks())); //int curP = WIDGET->currentPage()-1; //currentPage reports pages starting at 1 //int lastP = numPages-1; @@ -150,11 +170,19 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->actionFind_Previous->setIcon(LXDG::findIcon("edit-find-prev","")); ui->actionProperties->setIcon(LXDG::findIcon("dialog-information","")); ui->actionSettings->setIcon(LXDG::findIcon("document-properties","")); + ui->findNextB->setIcon(LXDG::findIcon("go-down-search")); + ui->findPrevB->setIcon(LXDG::findIcon("go-up-search")); + ui->matchCase->setIcon(LXDG::findIcon("format-text-italic")); + ui->closeFind->setIcon(LXDG::findIcon("dialog-close")); //Now set the default state of the menu's and actions ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(false); ui->actionStart_Begin->setEnabled(false); + + qDebug() << "Disabling findGroup" << ui->findGroup; + ui->findGroup->setVisible(false); + ui->bookmarksFrame->setVisible(false); } MainUI::~MainUI(){ @@ -399,11 +427,22 @@ void MainUI::paintOnWidget(QPrinter *PRINTER){ QPainter painter(PRINTER); for(int i=0; inewPage(); } //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)); } + if(loadingHash.contains(i)){ + painter.drawImage(0,0, loadingHash[i].scaled(PRINTER->pageRect().size(), + Qt::KeepAspectRatio, Qt::SmoothTransformation)); + if(!clearHighlights and !results.empty()) { + for(int j = 0; j < results.size(); j++) { + Poppler::TextBox *currentText = results.keys()[j]; + if(results.value(currentText) == i) + painter.fillRect(currentText->boundingBox(), QColor(255, 255, 179, 128)); + } + } + } else{ painter.drawImage(0,0, QImage()); } } WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); loadingHash.clear(); + clearHighlights = false; } void MainUI::paintToPrinter(QPrinter *PRINTER){ @@ -564,3 +603,60 @@ void MainUI::showInformation() { PROPDIALOG = new PropDialog(DOC); PROPDIALOG->show(); } + +void MainUI::find(QString text, bool forward) { + qDebug() << "Finding Text"; + bool newText = results.empty(); + bool research = false; + if(!newText) + research = !results.keys()[0]->text().contains(text); + //Clear results if the user gives a new search string + if(research) + results.clear(); + + + if(research or newText) { + //combiner.setPen(Qt::NoPen); + for(int i = 0; i < numPages; i++) { + QList textList = DOC->page(i)->textList(); + for(int j = 0; j < textList.size(); j++) { + if(textList[j]->text().contains(text, (matchCase) ? Qt::CaseSensitive : Qt::CaseInsensitive)) { + results.insert(textList[j], i); + } + } + } + currentHighlight = (forward) ? -1 : results.size(); + } + + qDebug() << "Jumping to next result"; + if(!results.empty()) { + //Jump to the location of the next or previous textbox and highlight + if(forward) { + currentHighlight = (currentHighlight + 1) % results.size(); + }else{ + currentHighlight--; + //Ensure currentHighlight will be between 0 and results.size() - 1 + if(currentHighlight < 0) + currentHighlight = results.size() - 1; + } + + //Extra highlight the current text + Poppler::TextBox *currentText = results.keys()[currentHighlight]; + WIDGET->setCurrentPage(results.value(currentText)); + }else{ + //Print "No results found" + } +} + +void MainUI::enableFind() { + qDebug() << "Enabling"; + std::cout << ui->findGroup << '\n'; + WIDGET->setGeometry(QRect(WIDGET->pos(), QSize(WIDGET->width(), WIDGET->height()-ui->findGroup->height()))); + ui->findGroup->setVisible(true); + ui->findGroup->setFocus(); + ui->textEdit->setText(""); +} + +void MainUI::showBookmarks() { + ui->bookmarksFrame->setVisible(true); +} -- cgit From 9ab5b031d95750e0320743c5c941685701aafe63 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Tue, 26 Dec 2017 15:41:40 -0500 Subject: Made improvements to focus setting and the find widget in lumina-pdf --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 207 ++++++++++++++++++---------- 1 file changed, 135 insertions(+), 72 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 6045a1bc..c5de3015 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -27,6 +27,7 @@ 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 = 0; lastdir = QDir::homePath(); @@ -47,11 +48,13 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ //Now put the widgets into the UI ui->bookmarksFrame->setParent(WIDGET); ui->findGroup->setParent(WIDGET); + 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, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintOnWidget(QPrinter*)) ); + connect(WIDGET, &QPrintPreviewWidget::paintRequested, this, + [=](QPrinter *printer) { this->paintOnWidget(printer, this->highlight); }); DOC = 0; connect(this, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) ); @@ -82,6 +85,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ tmp->addAction(ui->actionAll_Pages); ui->actionSingle_Page->setChecked(true); + qDebug() << "Starting connections"; + //Connect up the buttons connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()) ); connect(ui->actionPrint, SIGNAL(triggered()), PrintDLG, SLOT(open()) ); @@ -106,22 +111,23 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(showInformation())); connect(ui->actionFind, SIGNAL(triggered()), this, SLOT(enableFind())); connect(ui->actionFind_Next, &QAction::triggered, this, - [&] { find(ui->textEdit->toPlainText(), true); }); + [&] { find(ui->textEdit->text(), true); }); connect(ui->actionFind_Previous, &QAction::triggered, this, - //[&] { find(ui->textEdit->toPlainText(), false); }); - [&] { find("Revision", false); }); + [&] { find(ui->textEdit->text(), false); }); connect(ui->findNextB, &QPushButton::clicked, this, - [&] { find(ui->textEdit->toPlainText(), true); }); + [&] { find(ui->textEdit->text(), true); }); connect(ui->findPrevB, &QPushButton::clicked, this, - [&] { find(ui->textEdit->toPlainText(), false); }); + [&] { find(ui->textEdit->text(), false); }); connect(ui->matchCase, &QPushButton::clicked, this, [&] (bool value) { this->matchCase = value; }); connect(ui->closeFind, &QPushButton::clicked, this, [&] { ui->findGroup->setVisible(false); this->setFocus(); }); connect(ui->actionClearHighlights, &QAction::triggered, WIDGET, - [&] { clearHighlights = true; WIDGET->update(); }); + [&] { WIDGET->updatePreview(); }); connect(ui->actionBookmarks, SIGNAL(triggered()), this, SLOT(showBookmarks())); + qDebug() << "Finished connctions"; + //int curP = WIDGET->currentPage()-1; //currentPage reports pages starting at 1 //int lastP = numPages-1; ui->actionFirst_Page->setText(tr("First Page")); @@ -175,12 +181,13 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->matchCase->setIcon(LXDG::findIcon("format-text-italic")); ui->closeFind->setIcon(LXDG::findIcon("dialog-close")); + qDebug() << "Finished setting icons"; + //Now set the default state of the menu's and actions ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(false); ui->actionStart_Begin->setEnabled(false); - qDebug() << "Disabling findGroup" << ui->findGroup; ui->findGroup->setVisible(false); ui->bookmarksFrame->setVisible(false); } @@ -212,7 +219,7 @@ void MainUI::loadFile(QString path){ delete DOC; DOC=0; } - loadingHash.clear(); //clear out this hash + //loadingHash.clear(); //clear out this hash numPages = -1; DOC = TDOC; //Save this for later qDebug() << "Opening File:" << path; @@ -377,7 +384,7 @@ void MainUI::endPresentation(){ void MainUI::startLoadingPages(QPrinter *printer){ if(numPages>0){ return; } //currently loaded[ing] - //qDebug() << " - Start Loading Pages"; + qDebug() << " - Start Loading Pages"; numPages = DOC->numPages(); //qDebug() << "numPages:" << numPages; progress->setRange(0,numPages); @@ -391,7 +398,7 @@ void MainUI::startLoadingPages(QPrinter *printer){ qDebug() << screens[i]->name() << screens[i]->logicalDotsPerInchX() << screens[i]->logicalDotsPerInchY(); }*/ for(int i=0; iccw = 0; QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize.size()); } @@ -417,32 +424,50 @@ void MainUI::slotPageLoaded(int page){ startPresentation(act == ui->actionAt_Beginning); }*/ -void MainUI::paintOnWidget(QPrinter *PRINTER){ +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 - PRINTER->setPageSize(QPageSize(PRINTER->pageRect().size()*2)); - qDebug() << PRINTER->pageRect().size() << loadingHash[0].size(); - + if(first) + PRINTER->setPageSize(QPageSize(PRINTER->pageRect().size()*2)); + qDebug() << PRINTER->pageRect().size() << loadingHash[0].size() << WIDGET->size(); QPainter painter(PRINTER); - for(int i=0; inewPage(); } //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)); - if(!clearHighlights and !results.empty()) { - for(int j = 0; j < results.size(); j++) { - Poppler::TextBox *currentText = results.keys()[j]; - if(results.value(currentText) == i) - painter.fillRect(currentText->boundingBox(), QColor(255, 255, 179, 128)); - } + 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; inewPage(); } //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()); } } - else{ painter.drawImage(0,0, QImage()); } + WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); + //loadingHash.clear(); + first = false; } - WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); - loadingHash.clear(); - clearHighlights = false; } void MainUI::paintToPrinter(QPrinter *PRINTER){ @@ -526,6 +551,7 @@ void MainUI::setScroll(bool tog) { 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); @@ -591,9 +617,8 @@ void MainUI::wheelEvent(QWheelEvent *event) { } void MainUI::newFocus(QWidget *oldW, QWidget *newW) { - Q_UNUSED(oldW); //qDebug() << "NEW: " << newW << "OLD: " << oldW; - if(newW and newW != this) { + if(!oldW && newW != this) { newW->setFocusPolicy(Qt::NoFocus); this->setFocus(); } @@ -605,58 +630,96 @@ void MainUI::showInformation() { } void MainUI::find(QString text, bool forward) { - qDebug() << "Finding Text"; - bool newText = results.empty(); - bool research = false; - if(!newText) - research = !results.keys()[0]->text().contains(text); - //Clear results if the user gives a new search string - if(research) - results.clear(); - - - if(research or newText) { - //combiner.setPen(Qt::NoPen); - for(int i = 0; i < numPages; i++) { - QList textList = DOC->page(i)->textList(); - for(int j = 0; j < textList.size(); j++) { - if(textList[j]->text().contains(text, (matchCase) ? Qt::CaseSensitive : Qt::CaseInsensitive)) { - results.insert(textList[j], i); + if(!text.isEmpty()) { + qDebug() << "Finding Text"; + bool newText = results.empty(); + bool research = false; + if(!newText) + research = !results.keys()[0]->text().contains(text); + //Clear results if the user gives a new search string + if(research) + results.clear(); + + if(research or newText) { + for(int i = 0; i < numPages; i++) { + QList textList = DOC->page(i)->textList(); + for(int j = 0; j < textList.size(); j++) { + if(textList[j]->text().contains(text, (matchCase) + ? Qt::CaseSensitive : Qt::CaseInsensitive)) { + results.insert(textList[j], i); + } } } + currentHighlight = (forward) ? -1 : results.size(); } - currentHighlight = (forward) ? -1 : results.size(); - } - qDebug() << "Jumping to next result"; - if(!results.empty()) { - //Jump to the location of the next or previous textbox and highlight - if(forward) { - currentHighlight = (currentHighlight + 1) % results.size(); + qDebug() << "Jumping to next result"; + if(!results.empty()) { + //Jump to the location of the next or previous textbox and highlight + if(forward) { + currentHighlight = (currentHighlight + 1) % results.size(); + }else{ + currentHighlight--; + //Ensure currentHighlight will be between 0 and results.size() - 1 + if(currentHighlight < 0) + currentHighlight = results.size() - 1; + } + + qDebug() << "Jump to location: " << currentHighlight; + + Poppler::TextBox *currentText = results.keys()[currentHighlight]; + WIDGET->setCurrentPage(results.value(currentText)); + + QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); + this->highlight = true; }else{ - currentHighlight--; - //Ensure currentHighlight will be between 0 and results.size() - 1 - if(currentHighlight < 0) - currentHighlight = results.size() - 1; + //Print "No results found" } - - //Extra highlight the current text - Poppler::TextBox *currentText = results.keys()[currentHighlight]; - WIDGET->setCurrentPage(results.value(currentText)); - }else{ - //Print "No results found" } } void MainUI::enableFind() { - qDebug() << "Enabling"; - std::cout << ui->findGroup << '\n'; - WIDGET->setGeometry(QRect(WIDGET->pos(), QSize(WIDGET->width(), WIDGET->height()-ui->findGroup->height()))); - ui->findGroup->setVisible(true); - ui->findGroup->setFocus(); - ui->textEdit->setText(""); + if(ui->findGroup->isVisible()) { + qDebug() << "Disabling Find"; + ui->findGroup->setVisible(false); + WIDGET->setGeometry(QRect(WIDGET->pos(), + QSize(WIDGET->width(), WIDGET->height()+ui->findGroup->height()))); + QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); + this->setFocus(); + }else{ + qDebug() << "Enabling Find"; + ui->findGroup->setGeometry(QRect(QPoint(0, WIDGET->height()-ui->findGroup->height()), + QSize(WIDGET->width()-12, ui->findGroup->height()))); + ui->findGroup->setVisible(true); + WIDGET->setGeometry(QRect(WIDGET->pos(), + QSize(WIDGET->width(), WIDGET->height()-ui->findGroup->height()))); + + QTimer::singleShot(0, WIDGET, SLOT(updatePreview())); + ui->findGroup->setFocus(); + } } void MainUI::showBookmarks() { ui->bookmarksFrame->setVisible(true); } + +void MainUI::resizeEvent(QResizeEvent *event) { + if(ui->findGroup->isVisible()) { + ui->findGroup->setGeometry(QRect(QPoint(0, WIDGET->height()-ui->findGroup->height()), + QSize(WIDGET->width()-10, ui->findGroup->height()))); + } + 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; +} -- cgit From a32c6a9fd54fd400db0b729e826bc9a06297a3d7 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Tue, 26 Dec 2017 18:20:40 -0500 Subject: Began creating custom QPrintPreviewWidget for lumina-pdf --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index c5de3015..6c5b762c 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -21,7 +21,7 @@ #include #include -#include "CM_PrintPreviewWidget.h" +#include "PrintWidget.h" MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->setupUi(this); @@ -33,7 +33,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ lastdir = QDir::homePath(); Printer = new QPrinter(); //Create the interface widgets - WIDGET = new CM_PrintPreviewWidget(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()) ); @@ -53,7 +53,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ 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, &QPrintPreviewWidget::paintRequested, this, + connect(WIDGET, &PrintWidget::paintRequested, this, [=](QPrinter *printer) { this->paintOnWidget(printer, this->highlight); }); DOC = 0; connect(this, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) ); -- cgit From 7e7f6f168a0528a19af6663e3c2b6fe985836a36 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Wed, 27 Dec 2017 15:59:26 -0500 Subject: Shifted from a custom QWidget to a subclass of QGraphicalView and connected it to the Main UI --- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 41 +++++++++++++---------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp') 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(); -- cgit