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 ++++++++++++++++++++++------ src-qt5/desktop-utils/lumina-pdf/mainUI.h | 47 +--------- src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 24 ++--- 3 files changed, 123 insertions(+), 84 deletions(-) (limited to 'src-qt5') 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); + } +} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 527bcb2a..078caaca 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -41,9 +41,6 @@ private: Ui::MainUI *ui; QPrinter* Printer; QPrintDialog *PrintDLG; - - int ccw; - QString lastdir; //Other Interface elements @@ -96,51 +93,13 @@ private slots: void updateContextMenu(); void setScroll(bool); - void rotate(QPrinter*, bool); + void rotate(bool); + //void rotate(QPrinter*, bool); signals: void PageLoaded(int); protected: - void keyPressEvent(QKeyEvent *event){ - //See if this is one of the special hotkeys and act appropriately - //qDebug() << "Got Key Press:"; - bool inPresentation = (presentationLabel!=0); - if(!inPresentation){ - //Alternate functionality when **not** in presentation mode - /*if(event->key()==Qt::Key_Down){ - qDebug() << "Send Wheel Event"; - QWheelEvent event( WIDGET->mapFromGlobal(QCursor::pos()), QCursor::pos(),QPoint(0,0), QPoint(0,30), 0, Qt::Vertical, Qt::LeftButton, Qt::NoModifier); - QApplication::sendEvent(WIDGET, &event); - //WIDGET->scrollDown(); - return; - }else if(event->key()==Qt::Key_Up){ - return; - }*/ - } - - 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_Down || 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_Up || 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{ - QMainWindow::keyPressEvent(event); - } - } + void keyPressEvent(QKeyEvent*); }; #endif diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui index 20a79cf2..8ce8c989 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui @@ -105,6 +105,9 @@ + + + @@ -250,17 +253,6 @@ Rotate Clockwise - - - true - - - true - - - Select Mode - - true @@ -275,6 +267,16 @@ Scroll Mode + + + + + + + + + + -- 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 ++++++++++++++++++++++------- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 2 +- src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 35 +++++++++----- 3 files changed, 80 insertions(+), 32 deletions(-) (limited to 'src-qt5') 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); } } diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 078caaca..9ed50ba0 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -69,7 +69,7 @@ private: private slots: void startLoadingPages(QPrinter *printer); void slotPageLoaded(int); - void slotStartPresentation(QAction *act); + //void slotStartPresentation(QAction *act); //Simplification routines void nextPage(){ ShowPage( WIDGET->currentPage() ); } //currentPage() starts at 1 rather than 0 diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui index 8ce8c989..70d3167a 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui @@ -33,19 +33,14 @@ - + &Presentation - - - Start Presentation - - - - + + @@ -59,6 +54,7 @@ + @@ -173,9 +169,9 @@ All Pages - + - At Beginning + Start Presentation (at beginning) @@ -233,9 +229,9 @@ Last Page - + - PDF Info + Properties @@ -255,7 +251,7 @@ - true + false false @@ -277,6 +273,19 @@ + + + Start Presentation (current slide) + + + + + false + + + Select Mode + + -- cgit From d503b6a89ebbc399cb56e5fac687c35e72996536 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Mon, 18 Dec 2017 19:09:55 -0500 Subject: Added missing JSON file for Grav screensaver --- .../extrafiles/screensavers/Grav.json | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Grav.json (limited to 'src-qt5') diff --git a/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Grav.json b/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Grav.json new file mode 100644 index 00000000..8d75d399 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Grav.json @@ -0,0 +1,25 @@ +{ + "name" : { + "default" : "Grav" + }, + "description" : { + "default" : "Simulates a solar system, with a single star and planets erratically orbiting that star" + }, + "author" : { + "name" : "Zackary Welch", + "email" : "zwelch@ixsystems.com", + "website" : "https://github.com/ZackaryWelch", + "company" : "iXsystems", + "company_website" : "http://ixsystems.com" + }, + "meta" : { + "license" : "3-clause BSD", + "license_url" : "https://github.com/trueos/lumina/blob/master/LICENSE", + "copyright" : "Copyright (c) 2017, Ken Moore (ken@ixsystems.com)", + "date_created" : "20171101", + "version" : "1.0" + }, + "qml" : { + "exec" : "qml_scripts/Grav.qml" + } +} -- cgit From 753a80a842bca997f53b5becf299c2d381c55c24 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Mon, 18 Dec 2017 19:10:54 -0500 Subject: Added test QML files --- src-qt5/src-qml/test/Grav.qml | 164 ++++++++++++++++++++++++++++++++++++++++++ src-qt5/src-qml/test/Test.qml | 7 ++ 2 files changed, 171 insertions(+) create mode 100644 src-qt5/src-qml/test/Grav.qml create mode 100644 src-qt5/src-qml/test/Test.qml (limited to 'src-qt5') diff --git a/src-qt5/src-qml/test/Grav.qml b/src-qt5/src-qml/test/Grav.qml new file mode 100644 index 00000000..d7404a56 --- /dev/null +++ b/src-qt5/src-qml/test/Grav.qml @@ -0,0 +1,164 @@ +import QtQuick 2.7 +import QtQuick.Window 2.2 +import QtGraphicalEffects 1.0 + +Rectangle { + id : canvas + anchors.fill: parent + width: Screen.width + height: Screen.height + color: "black" + + //TODO Add orbital trails option + //TODO Fix jitteryness and start position + //TODO Make orbits more extreme + + //Between 5 and 15 planets, read from settings + property int planets: Math.round(( Math.random() * 10 ) + 5 ) + property int cx: Math.round(width/2) + property int cy: Math.round(height/2) + + //Create planets + Repeater { + id: planetRepeater + model: planets + + Rectangle { + id : index + parent: canvas + + //Creates random distance for elipse + property double c: Math.random() * 250 + property double b: Math.random() * 150 + c + property double a: Math.sqrt(b*b+c*c) + //Random angle of rotation + property double th: Math.random() * Math.PI + property var pathX: createPathX() + property var pathY: createPathY() + property var testArray: createTest() + + //Calculates starting position + x: Math.round(cx + a * Math.cos(th)) + y: Math.round(cy + b * Math.sin(th)) + + //Planet size between 14 and 32 pixels + width: Math.round(1.75 * (((Math.random() * 10) + 8 ))) + height: width + + //Make each rectangle look circular + radius: width / 2 + + //Give each planet a random color, semi-transparent + color: Qt.rgba(Math.random(), Math.random(), Math.random(), 0.5) + + PathAnimation on x{ + loops: Animation.Infinite + duration: 200 + path: Path { + startX: x + startY: y + PathCurve { x: pathX; y: pathY } + } + } + + NumberAnimation { + + } + + function createTest() { + var test = [] + for(var i = 1; i <= 200; i++) { + test.push(PathCurve { x: pathX[i]; y: pathY[i] }) + } + return test + } + + function createPathX() { + var pathX = [] + for(var i = 1; i <= 200; i++) { + pathX.push(cx+a*Math.cos(2*Math.PI*(i/200.0))*Math.cos(th) - b*Math.sin(2*Math.PI*(i/200.0))*Math.sin(th)) + } + return pathX + } + + function createPathY() { + var pathY = [] + for(var i = 1; i <= 200; i++) { + pathY.push(cy+a*Math.cos(2*Math.PI*(i/200.0))*Math.sin(th) + b*Math.sin(2*Math.PI*(i/200.0))*Math.cos(th)) + } + return pathY + } + + /*Timer { + //Each planet updates between 1ms and 51ms (smaller times=faster) + interval: Math.round(Math.random() * 50 ) + 1 + repeat: true + running: true + property int time: 0 + + onTriggered: { + //Parametric equation that calculates the position of the general ellipse. Completes a loop ever 314 cycles. Credit to + x = cx+a*Math.cos(2*Math.PI*(time/314.0))*Math.cos(th) - b*Math.sin(2*Math.PI*(time/314.0))*Math.sin(th) + y = cy+a*Math.cos(2*Math.PI*(time/314.0))*Math.sin(th) + b*Math.sin(2*Math.PI*(time/314.0))*Math.cos(th) + time++; + + //Move a planet 80 pixels away from the sun if the planet is too close + if(x > cx && Math.abs(cx-x) < 80) { + x+=80 + }else if(x < cx && Math.abs(cx-x) < 80) { + x-=80 + } + + if(y > cy && Math.abs(cy-y) < 80) { + y+=80 + }else if(y < cy && Math.abs(cy-y) < 80) { + y-=80 + } + } + }*/ + } + } + + //Create the star + Rectangle{ + id: star + parent: canvas + + //Centers in star in the center of the canvas, with an offset to center the animation + x: cx - 30 + y: cy - 30 + + width: 60 + height: width + + //Create the wobble animation + SequentialAnimation on height { + loops: Animation.Infinite + PropertyAnimation { duration: 2000; to: 90 } + PropertyAnimation { duration: 2000; to: 60 } + } + + SequentialAnimation on width { + loops: Animation.Infinite + PropertyAnimation { duration: 2000; to: 90 } + PropertyAnimation { duration: 2000; to: 60 } + } + + color: "black" + radius: width / 2 + + //Creates a radial gradient to make the star look cool + RadialGradient { + anchors.fill: parent + gradient: Gradient { + GradientStop { position:0 ;color: Qt.rgba(0,0,0,0)} + GradientStop { position:0.18 ;color: Qt.rgba(0,0,0,0)} + GradientStop { position:0.2 ;color: Qt.rgba(0.32,0.47,0.30,0.13)} + GradientStop { position:0.3 ;color: Qt.rgba(0.62,0.92,0.58,0.25)} + GradientStop { position:0.4 ;color: Qt.rgba(1.00,0.93,0.59,0.51)} + GradientStop { position:0.5 ;color: Qt.rgba(0,0,0,0)} + } + } + + } +} diff --git a/src-qt5/src-qml/test/Test.qml b/src-qt5/src-qml/test/Test.qml new file mode 100644 index 00000000..a2407b6c --- /dev/null +++ b/src-qt5/src-qml/test/Test.qml @@ -0,0 +1,7 @@ +import QtQuick 2.7 + +Rectangle { + id : canvas + anchors.fill: parent + color: "black" +} -- cgit From 7b03f5af04943e2de6f3041e67be23280219a238 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 19 Dec 2017 23:54:07 -0500 Subject: Add a new C++ object: PanelObject This is tied into the RootDesktopObject as well as the ScreenObject, resulting in global-session panels as well as per-screen panels. --- .../src-desktop/src-cpp/PanelObject.cpp | 44 +++++++++++++++++++ .../src-desktop/src-cpp/PanelObject.h | 49 ++++++++++++++++++++++ .../src-desktop/src-cpp/RootDesktopObject.cpp | 24 +++++++++++ .../src-desktop/src-cpp/RootDesktopObject.h | 8 ++++ .../src-desktop/src-cpp/ScreenObject.cpp | 26 ++++++++++++ .../src-desktop/src-cpp/ScreenObject.h | 9 ++++ .../src-desktop/src-cpp/src-cpp.pri | 7 ++-- 7 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp create mode 100644 src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h (limited to 'src-qt5') diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp new file mode 100644 index 00000000..471da58f --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp @@ -0,0 +1,44 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "PanelObject.h" +#include +#include + +PanelObject::PanelObject(QString id, QObject *parent) : QObject(parent){ + panel_id = id; +} + +void PanelObject::RegisterType(){ + static bool done = false; + if(done){ return; } + done=true; + qmlRegisterType("Lumina.Backend.PanelObject",2,0, "PanelObject"); +} + +QString PanelObject::name(){ return panel_id; } +QString PanelObject::background(){ + if(bg.isEmpty()){ return "transparent"; } + return bg; +} +int PanelObject::x(){ return geom.x(); } +int PanelObject::y(){ return geom.y(); } +int PanelObject::width(){ return geom.width(); } +int PanelObject::height(){ return geom.height(); } + +void PanelObject::setBackground(QString fileOrColor){ + if(bg!=fileOrColor){ + bg = fileOrColor; + emit backgroundChanged(); + } +} + +void PanelObject::setGeometry( QRect newgeom ){ + if(geom!=newgeom){ + geom = newgeom; + emit geomChanged(); + } +} diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h new file mode 100644 index 00000000..a788fa07 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h @@ -0,0 +1,49 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is the base C++ object that is used to pass Panel info to the QML classes +//=========================================== +#ifndef _LUMINA_DESKTOP_PANEL_OBJECT_H +#define _LUMINA_DESKTOP_PANEL_OBJECT_H +#include +#include +#include + +class PanelObject : public QObject { + Q_OBJECT + Q_PROPERTY( QString name READ name ) + Q_PROPERTY( QString background READ background NOTIFY backgroundChanged) + Q_PROPERTY( int x READ x NOTIFY geomChanged) + Q_PROPERTY( int y READ y NOTIFY geomChanged) + Q_PROPERTY( int width READ width NOTIFY geomChanged) + Q_PROPERTY( int height READ height NOTIFY geomChanged) + +private: + QString panel_id, bg; + QRect geom; + +public: + PanelObject(QString id = "", QObject *parent = 0); + + static void RegisterType(); + + Q_INVOKABLE QString name(); + Q_INVOKABLE QString background(); + Q_INVOKABLE int x(); + Q_INVOKABLE int y(); + Q_INVOKABLE int width(); + Q_INVOKABLE int height(); + +public slots: + void setBackground(QString fileOrColor); + void setGeometry(QRect newgeom); + +signals: + void backgroundChanged(); + void geomChanged(); +}; + +#endif diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp index 60cf56c3..c1652ba6 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp @@ -21,6 +21,9 @@ RootDesktopObject::~RootDesktopObject(){ } void RootDesktopObject::RegisterType(){ + static bool done = false; + if(done){ return; } + done=true; qmlRegisterType("Lumina.Backend.RootDesktopObject", 2, 0, "RootDesktopObject"); //Also register any types that are needed by this class ScreenObject::RegisterType(); @@ -47,6 +50,26 @@ ScreenObject* RootDesktopObject::screen(QString id){ return 0; } +QStringList RootDesktopObject::panels(){ + //qDebug() << "Request Panels:" << panel_objects.length(); + QStringList names; + for(int i=0; iname(); } + return names; +} + +PanelObject* RootDesktopObject::panel(QString id){ + //qDebug() << "Got Panel Request:" << id; + for(int i=0; iname()==id){ return panel_objects[i]; } + } + return 0; +} + +void RootDesktopObject::setPanels(QList list){ + panel_objects = list; + emit panelsChanged(); +} + void RootDesktopObject::logout(){ emit startLogout(); } @@ -85,4 +108,5 @@ void RootDesktopObject::ChangeWallpaper(QString screen, QString value){ } } + // === PRIVATE === diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h index ba586701..93beb6e4 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h @@ -17,6 +17,7 @@ class RootDesktopObject : public QObject{ Q_OBJECT //Define all the QML Properties here (interface between QML and the C++ methods below) Q_PROPERTY( QStringList screens READ screens NOTIFY screensChanged) + Q_PROPERTY( QStringList panels READ panels NOTIFY panelsChanged) public: //main contructor/destructor @@ -31,13 +32,19 @@ public: //QML Read Functions QStringList screens(); Q_INVOKABLE ScreenObject* screen(QString id); + Q_INVOKABLE QStringList panels(); + Q_INVOKABLE PanelObject* panel(QString id); + + void setPanels(QList list); //QML Access Functions Q_INVOKABLE void logout(); Q_INVOKABLE void lockscreen(); Q_INVOKABLE void mousePositionChanged(); + private: QList s_objects; + QList panel_objects; public slots: void updateScreens(); //rescan/update screen objects @@ -47,6 +54,7 @@ private slots: signals: void screensChanged(); + void panelsChanged(); void startLogout(); void mouseMoved(); void lockScreen(); diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp index 4c1d6189..82622403 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp @@ -13,7 +13,12 @@ ScreenObject::ScreenObject(QScreen *scrn, QObject *parent) : QObject(parent){ } void ScreenObject::RegisterType(){ + static bool done = false; + if(done){ return; } + done=true; qmlRegisterType("Lumina.Backend.ScreenObject",2,0, "ScreenObject"); + //Also register any types that are needed by this class + PanelObject::RegisterType(); } QString ScreenObject::name(){ return bg_screen->name(); } @@ -29,3 +34,24 @@ void ScreenObject::setBackground(QString fileOrColor){ emit backgroundChanged(); } } + +void ScreenObject::setPanels(QList list){ + panel_objects = list; + emit panelsChanged(); +} + +//QML Read Functions +QStringList ScreenObject::panels(){ + //qDebug() << "Request Panels:" << panel_objects.length(); + QStringList names; + for(int i=0; iname(); } + return names; +} + +PanelObject* ScreenObject::panel(QString id){ + //qDebug() << "Got Panel Request:" << id; + for(int i=0; iname()==id){ return panel_objects[i]; } + } + return 0; +} diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h index 8076f1ae..1afff6d2 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h @@ -12,6 +12,8 @@ #include #include +#include "PanelObject.h" + class ScreenObject : public QObject { Q_OBJECT Q_PROPERTY( QString name READ name ) @@ -20,10 +22,12 @@ class ScreenObject : public QObject { Q_PROPERTY( int y READ y NOTIFY geomChanged) Q_PROPERTY( int width READ width NOTIFY geomChanged) Q_PROPERTY( int height READ height NOTIFY geomChanged) + Q_PROPERTY( QStringList panels READ panels NOTIFY panelsChanged) private: QScreen *bg_screen; QString bg; + QList panel_objects; public: ScreenObject(QScreen *scrn = 0, QObject *parent = 0); @@ -36,6 +40,10 @@ public: Q_INVOKABLE int y(); Q_INVOKABLE int width(); Q_INVOKABLE int height(); + Q_INVOKABLE QStringList panels(); + Q_INVOKABLE PanelObject* panel(QString id); + + void setPanels(QList list); public slots: void setBackground(QString fileOrColor); @@ -43,6 +51,7 @@ public slots: signals: void backgroundChanged(); void geomChanged(); + void panelsChanged(); }; #endif diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/src-cpp.pri b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/src-cpp.pri index 33b699da..899f4968 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/src-cpp.pri +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/src-cpp.pri @@ -1,8 +1,9 @@ SOURCES *= $${PWD}/RootDesktopObject.cpp \ - $${PWD}/ScreenObject.cpp + $${PWD}/ScreenObject.cpp \ + $${PWD}/PanelObject.cpp HEADERS *= $${PWD}/RootDesktopObject.h \ - $${PWD}/ScreenObject.h + $${PWD}/ScreenObject.h \ + $${PWD}/PanelObject.h INCLUDEPATH *= $${PWD} - -- cgit From 7207ddde754868ef5071e3d5ebb91a0b9bfbc5ca Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 20 Dec 2017 00:06:17 -0500 Subject: Make sure the QML filenames correspond to the C++ objects (PanelObject.h -> Panel.qml) Add a new "Panel.qml" widget for reserved screen areas. --- .../src-desktop/src-qml/Panel.qml | 26 ++++++++++++++++++++++ .../src-desktop/src-qml/RootDesktop.qml | 3 ++- .../src-desktop/src-qml/Screen.qml | 26 ++++++++++++++++++++++ .../src-desktop/src-qml/WallpaperImage.qml | 26 ---------------------- .../src-desktop/src-qml/src-qml.pri | 3 ++- .../src-desktop/src-qml/src-qml.qrc | 3 ++- 6 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Panel.qml create mode 100644 src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Screen.qml delete mode 100644 src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/WallpaperImage.qml (limited to 'src-qt5') diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Panel.qml b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Panel.qml new file mode 100644 index 00000000..846b5b55 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Panel.qml @@ -0,0 +1,26 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +import QtQuick 2.2 +import QtQuick.Window 2.2 +import QtQuick.Controls 1 + +import Lumina.Backend.PanelObject 2.0 + +AnimatedImage { + //C++ backend object + property string screen_id + property PanelObject object + + //Normal geometries/placements + asynchronous: true + clip: true + source: object.background + x: object.x + y: object.y + width: object.width + height: object.height + } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml index e0381e23..beecb848 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml @@ -49,8 +49,9 @@ Rectangle { //Setup the wallpapers Repeater{ model: RootObject.screens - QML.WallpaperImage{ + QML.Screen{ screen_id: modelData + object: RootObject.screen(modelData) z: 0+index } } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Screen.qml b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Screen.qml new file mode 100644 index 00000000..3b83653a --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/Screen.qml @@ -0,0 +1,26 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +import QtQuick 2.2 +import QtQuick.Window 2.2 +import QtQuick.Controls 1 + +import Lumina.Backend.ScreenObject 2.0 + +AnimatedImage { + //C++ backend object + property string screen_id + property ScreenObject object + + //Normal geometries/placements + asynchronous: true + clip: true + source: object.background + x: object.x + y: object.y + width: object.width + height: object.height + } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/WallpaperImage.qml b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/WallpaperImage.qml deleted file mode 100644 index 1b44963f..00000000 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/WallpaperImage.qml +++ /dev/null @@ -1,26 +0,0 @@ -//=========================================== -// Lumina-desktop source code -// Copyright (c) 2017, Ken Moore -// Available under the 3-clause BSD license -// See the LICENSE file for full details -//=========================================== -import QtQuick 2.2 -import QtQuick.Window 2.2 -import QtQuick.Controls 1 - -import Lumina.Backend.ScreenObject 2.0 - -AnimatedImage { - //C++ backend object - property string screen_id - property ScreenObject object: RootObject.screen(screen_id) - - //Normal geometries/placements - asynchronous: true - clip: true - source: object.background - x: object.x - y: object.y - width: object.width - height: object.height - } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.pri b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.pri index fed18e02..ad07902a 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.pri +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.pri @@ -2,7 +2,8 @@ lupdate_only{ SOURCES *= $${PWD}/RootDesktop.qml \ $${PWD}/ContextMenu.qml \ - $${PWD}/WallpaperImage.qml + $${PWD}/Screen.qml \ + $${PWD}/Panel.qml } RESOURCES *= $${PWD}/src-qml.qrc diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.qrc b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.qrc index ebdcc606..b0c66e20 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.qrc +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/src-qml.qrc @@ -2,6 +2,7 @@ RootDesktop.qml ContextMenu.qml - WallpaperImage.qml + Screen.qml + Panel.qml -- cgit From 70a95acc3d3cae25fd99a027d932960cce819299 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 20 Dec 2017 00:28:17 -0500 Subject: Setup the RootDesktopObject to start providing NativeWindow objects to the QML interface. --- .../core/lumina-desktop-unified/global-includes.h | 7 +++---- .../src-desktop/src-cpp/RootDesktopObject.cpp | 21 +++++++++++++++++++++ .../src-desktop/src-cpp/RootDesktopObject.h | 10 +++++++++- .../src-desktop/src-qml/RootDesktop.qml | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/core/lumina-desktop-unified/global-includes.h b/src-qt5/core/lumina-desktop-unified/global-includes.h index 40987ad4..fbc3c4f7 100644 --- a/src-qt5/core/lumina-desktop-unified/global-includes.h +++ b/src-qt5/core/lumina-desktop-unified/global-includes.h @@ -59,10 +59,6 @@ #include #include -// C++ Backend classes for QML interface -#include -#include - // libLumina includes #include #include @@ -80,6 +76,9 @@ #include #include +// C++ Backend classes for QML interface +#include +#include //Setup any global defines (no classes or global objects: use "global-objects.h" for that) diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp index c1652ba6..5750ac2d 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp @@ -65,11 +65,32 @@ PanelObject* RootDesktopObject::panel(QString id){ return 0; } +QStringList RootDesktopObject::windows(){ + //qDebug() << "Request Panels:" << panel_objects.length(); + QStringList names; + for(int i=0; iid()); } + return names; +} + +NativeWindow* RootDesktopObject::window(QString id){ + //qDebug() << "Got Panel Request:" << id; + WId chk = id.toInt(); //numerical ID's in this case + for(int i=0; iid()==chk){ return window_objects[i]; } + } + return 0; +} + void RootDesktopObject::setPanels(QList list){ panel_objects = list; emit panelsChanged(); } +void RootDesktopObject::setWindows(QList list){ + window_objects = list; + emit windowsChanged(); +} + void RootDesktopObject::logout(){ emit startLogout(); } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h index 93beb6e4..838b5f7d 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h @@ -10,6 +10,7 @@ #define _LUMINA_DESKTOP_QML_BACKEND_ROOT_DESKTOP_OBJECT_H #include #include +#include #include "ScreenObject.h" @@ -18,6 +19,7 @@ class RootDesktopObject : public QObject{ //Define all the QML Properties here (interface between QML and the C++ methods below) Q_PROPERTY( QStringList screens READ screens NOTIFY screensChanged) Q_PROPERTY( QStringList panels READ panels NOTIFY panelsChanged) + Q_PROPERTY( QStringList windows READ windows NOTIFY windowsChanged); public: //main contructor/destructor @@ -30,12 +32,15 @@ public: static RootDesktopObject* instance(); //QML Read Functions - QStringList screens(); + Q_INVOKABLE QStringList screens(); Q_INVOKABLE ScreenObject* screen(QString id); Q_INVOKABLE QStringList panels(); Q_INVOKABLE PanelObject* panel(QString id); + Q_INVOKABLE QStringList windows(); + Q_INVOKABLE NativeWindow* window(QString id); void setPanels(QList list); + void setWindows(QList list); //QML Access Functions Q_INVOKABLE void logout(); @@ -45,6 +50,7 @@ public: private: QList s_objects; QList panel_objects; + QList window_objects; public slots: void updateScreens(); //rescan/update screen objects @@ -55,6 +61,8 @@ private slots: signals: void screensChanged(); void panelsChanged(); + void windowsChanged(); + void startLogout(); void mouseMoved(); void lockScreen(); diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml index beecb848..c564ee42 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/RootDesktop.qml @@ -46,7 +46,7 @@ Rectangle { //Create the context menu itself QML.ContextMenu { id: contextMenu } - //Setup the wallpapers + //Setup the screens/wallpapers Repeater{ model: RootObject.screens QML.Screen{ -- 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/lumina-pdf.pro | 9 +- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 85 ++-- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 8 +- src-qt5/desktop-utils/lumina-pdf/propDialog.cpp | 54 +++ src-qt5/desktop-utils/lumina-pdf/propDialog.h | 25 + src-qt5/desktop-utils/lumina-pdf/propDialog.ui | 601 ++++++++++++++++++++++++ 6 files changed, 721 insertions(+), 61 deletions(-) create mode 100644 src-qt5/desktop-utils/lumina-pdf/propDialog.cpp create mode 100644 src-qt5/desktop-utils/lumina-pdf/propDialog.h create mode 100644 src-qt5/desktop-utils/lumina-pdf/propDialog.ui (limited to 'src-qt5') diff --git a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro index 894d21f2..3a031067 100644 --- a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro +++ b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro @@ -18,13 +18,16 @@ include(../../core/libLumina/LuminaXDG.pri) message("Qt Modules Needed: $${QT}") SOURCES += main.cpp \ - mainUI.cpp + mainUI.cpp \ + propDialog.cpp HEADERS += mainUI.h \ CM_PrintPreviewWidget.h \ - PresentationLabel.h + PresentationLabel.h \ + PropDialog.h -FORMS += mainUI.ui +FORMS += mainUI.ui \ + propDialog.ui LIBS += -lpoppler-qt5 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(); +} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 9ed50ba0..18b3d231 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -21,6 +21,7 @@ #include #include "PresentationLabel.h" +#include "propDialog.h" namespace Ui{ class MainUI; @@ -34,11 +35,11 @@ public: void loadFile(QString path); - private: Poppler::Document *DOC; QPrintPreviewWidget *WIDGET; Ui::MainUI *ui; + PropDialog *PROPDIALOG; QPrinter* Printer; QPrintDialog *PrintDLG; QString lastdir; @@ -79,8 +80,9 @@ private slots: void startPresentationHere(){ startPresentation(false); } void startPresentationBeginning(){ startPresentation(true); } void closePresentation(){ endPresentation(); } + void showInformation(); - + void newFocus(QWidget*, QWidget*); void paintOnWidget(QPrinter *PRINTER); void paintToPrinter(QPrinter *PRINTER); @@ -94,12 +96,12 @@ private slots: void setScroll(bool); void rotate(bool); - //void rotate(QPrinter*, bool); signals: void PageLoaded(int); protected: void keyPressEvent(QKeyEvent*); + void wheelEvent(QWheelEvent*); }; #endif diff --git a/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp b/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp new file mode 100644 index 00000000..6dbdee69 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp @@ -0,0 +1,54 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== + +#include "propDialog.h" +#include "ui_propDialog.h" + +#include + +PropDialog::PropDialog(Poppler::Document *DOC) : QDialog(), ui(new Ui::PropDialog()){ + this->setWindowTitle(tr("PDF Information")); + this->setWindowIcon( LXDG::findIcon("dialog-information","unknown")); + int verMa, verMi; + QString version; + QSize size = DOC->page(0)->pageSize(); + + //Grab the version + DOC->getPdfVersion(&verMa, &verMi); + version = QString::number(verMa)+"."+QString::number(verMi); + + ui->setupUi(this); + + //Setup translations + ui->titleL->setText(tr("Title:")); + ui->subjectL->setText(tr("Subject:")); + ui->authorL->setText(tr("Author:")); + ui->creatorL->setText(tr("Creator:")); + ui->producerL->setText(tr("Producer:")); + ui->keywordsL->setText(tr("Keywords:")); + ui->createdL->setText(tr("Created:")); + ui->modifiedL->setText(tr("Modified:")); + ui->versionL->setText(tr("PDF Version:")); + ui->sizeL->setText(tr("Page Size:")); + ui->numberL->setText(tr("Number of Pages:")); + ui->saveButton->setText(tr("Save")); + ui->closeButton->setText(tr("Close")); + + //Fill the text boxes with information from the document + ui->titleE->setText(DOC->title()); + ui->subjectE->setText(DOC->subject()); + ui->authorE->setText(DOC->author()); + ui->creatorE->setText(DOC->creator()); + ui->producerE->setText(DOC->producer()); + ui->keywordE->setText(DOC->keywords()); + ui->createdEntry->setText(DOC->creationDate().toString(Qt::TextDate)); + ui->modifiedEntry->setText(DOC->modificationDate().toString(Qt::TextDate)); + ui->versionL->setText(ui->versionL->text()+version); + ui->sizeL->setText(ui->sizeL->text()+QString::number(size.height())+ + ", "+QString::number(size.width())); + ui->numberL->setText(ui->numberL->text()+QString::number(DOC->numPages())); +} diff --git a/src-qt5/desktop-utils/lumina-pdf/propDialog.h b/src-qt5/desktop-utils/lumina-pdf/propDialog.h new file mode 100644 index 00000000..be67ebd3 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/propDialog.h @@ -0,0 +1,25 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_PDF_VIEWER_PROP_DIALOG_H +#define _LUMINA_PDF_VIEWER_PROP_DIALOG_H + +#include +#include + +namespace Ui{ + class PropDialog; +}; + +class PropDialog : public QDialog { + Q_OBJECT + public: + PropDialog(Poppler::Document*); + + private: + Ui::PropDialog *ui; +}; +#endif diff --git a/src-qt5/desktop-utils/lumina-pdf/propDialog.ui b/src-qt5/desktop-utils/lumina-pdf/propDialog.ui new file mode 100644 index 00000000..ad995473 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/propDialog.ui @@ -0,0 +1,601 @@ + + + PropDialog + + + + 0 + 0 + 400 + 300 + + + + PDF Information + + + + + 100 + 30 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + 20 + 30 + 71 + 16 + + + + Title: + + + + + + 20 + 50 + 71 + 16 + + + + Subject: + + + + + + 20 + 70 + 71 + 16 + + + + Author: + + + + + + 20 + 90 + 71 + 16 + + + + Creator: + + + + + + 20 + 150 + 81 + 16 + + + + Created: + + + + + + 20 + 110 + 71 + 16 + + + + Producer: + + + + + + 20 + 130 + 71 + 16 + + + + Keywords: + + + + + + 100 + 50 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + 100 + 90 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + 100 + 70 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + true + + + + 100 + 130 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + 100 + 110 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + 20 + 200 + 311 + 16 + + + + PDF Version: + + + + + + 20 + 220 + 301 + 16 + + + + Page Size: + + + + + + 20 + 240 + 321 + 16 + + + + Number of Pages: + + + + + + 20 + 170 + 81 + 16 + + + + Modified: + + + + + true + + + + 100 + 150 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + true + + + + 100 + 170 + 291 + 16 + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + + 230 + 270 + 80 + 23 + + + + Save + + + + + + 310 + 270 + 80 + 23 + + + + Close + + + true + + + true + + + false + + + + + + -- cgit From 04107ece21a7a5a067c50abef25bdc8da8d244b9 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 21 Dec 2017 09:47:01 -0500 Subject: Turn of some stdout messages within the Qt theme plugin. --- .../src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp b/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp index 670e1c9c..e581b016 100644 --- a/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp +++ b/src-qt5/core/lumina-theme-engine/src/lthemeengine-qtplugin/lthemeengineplatformtheme.cpp @@ -43,7 +43,7 @@ lthemeenginePlatformTheme::lthemeenginePlatformTheme(){ #endif QGuiApplication::setFont(m_generalFont); } - qCDebug(llthemeengine) << "using lthemeengine plugin"; + //qCDebug(llthemeengine) << "using lthemeengine plugin"; #ifdef QT_WIDGETS_LIB if(!QStyleFactory::keys().contains("lthemeengine-style")) qCCritical(llthemeengine) << "unable to find lthemeengine proxy style"; @@ -60,7 +60,7 @@ QPlatformMenuBar *lthemeenginePlatformTheme::createPlatformMenuBar() const{ if(m_checkDBusGlobalMenu){ QDBusConnection conn = QDBusConnection::sessionBus(); m_dbusGlobalMenuAvailable = conn.interface()->isServiceRegistered("com.canonical.AppMenu.Registrar"); - qCDebug(llthemeengine) << "D-Bus global menu:" << (m_dbusGlobalMenuAvailable ? "yes" : "no"); + //qCDebug(llthemeengine) << "D-Bus global menu:" << (m_dbusGlobalMenuAvailable ? "yes" : "no"); } return (m_dbusGlobalMenuAvailable ? new QDBusMenuBar() : nullptr); } -- 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 ++- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 6 + src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 118 ++- src-qt5/desktop-utils/lumina-pdf/propDialog.cpp | 2 + src-qt5/desktop-utils/lumina-pdf/propDialog.ui | 1040 ++++++++++------------- 5 files changed, 677 insertions(+), 587 deletions(-) (limited to 'src-qt5') 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); +} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 18b3d231..8337ed9c 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -43,6 +43,9 @@ private: QPrinter* Printer; QPrintDialog *PrintDLG; QString lastdir; + bool matchCase, clearHighlights; + QMap results; + int currentHighlight; //Other Interface elements QProgressBar *progress; @@ -81,6 +84,9 @@ private slots: void startPresentationBeginning(){ startPresentation(true); } void closePresentation(){ endPresentation(); } void showInformation(); + void find(QString text, bool forward); + void enableFind(); + void showBookmarks(); void newFocus(QWidget*, QWidget*); void paintOnWidget(QPrinter *PRINTER); diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui index 70d3167a..c8cd8271 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui @@ -6,20 +6,123 @@ 0 0 - 660 - 588 + 695 + 694 MainWindow - + + + + + 0 + 560 + 691 + 61 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + + + + + + + 16777215 + 24 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Find... + + + + + + + + + 0 + 9 + 81 + 601 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 10 + 0 + 71 + 16 + + + + Bookmarks + + + + 0 0 - 660 + 695 21 @@ -50,11 +153,13 @@ + + @@ -286,6 +391,11 @@ Select Mode + + + Clear Highlights + + diff --git a/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp b/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp index 6dbdee69..0c26af74 100644 --- a/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp @@ -23,6 +23,8 @@ PropDialog::PropDialog(Poppler::Document *DOC) : QDialog(), ui(new Ui::PropDialo ui->setupUi(this); + connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); + //Setup translations ui->titleL->setText(tr("Title:")); ui->subjectL->setText(tr("Subject:")); diff --git a/src-qt5/desktop-utils/lumina-pdf/propDialog.ui b/src-qt5/desktop-utils/lumina-pdf/propDialog.ui index ad995473..6806f81a 100644 --- a/src-qt5/desktop-utils/lumina-pdf/propDialog.ui +++ b/src-qt5/desktop-utils/lumina-pdf/propDialog.ui @@ -13,588 +13,464 @@ PDF Information - - - - 100 - 30 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - false - - - - - - 20 - 30 - 71 - 16 - - - - Title: - - - - - - 20 - 50 - 71 - 16 - - - - Subject: - - - - - - 20 - 70 - 71 - 16 - - - - Author: - - - - - - 20 - 90 - 71 - 16 - - - - Creator: - - - - - - 20 - 150 - 81 - 16 - - - - Created: - - - - - - 20 - 110 - 71 - 16 - - - - Producer: - - - - - - 20 - 130 - 71 - 16 - - - - Keywords: - - - - - - 100 - 50 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - false - - - - - - 100 - 90 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - false - - - - - - 100 - 70 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - false - - - - - true - - - - 100 - 130 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - false - - - QFrame::StyledPanel - - - QFrame::Sunken - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - false - - - - - - 100 - 110 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - false - - - - - - 20 - 200 - 311 - 16 - - - - PDF Version: - - - - - - 20 - 220 - 301 - 16 - - - - Page Size: - - - - - - 20 - 240 - 321 - 16 - - - - Number of Pages: - - - - - - 20 - 170 - 81 - 16 - - - - Modified: - - - - - true - - - - 100 - 150 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - false - - - QFrame::StyledPanel - - - QFrame::Sunken - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - - - true - - - - 100 - 170 - 291 - 16 - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 16 - - - - false - - - false - - - QFrame::StyledPanel - - - QFrame::Sunken - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - - - - 230 - 270 - 80 - 23 - - - - Save - - - - - - 310 - 270 - 80 - 23 - - - - Close - - - true - - - true - - - false - - + + + + + Title: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + + Subject: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + + Author: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + + Creator: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + + Producer: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + + Keywords: + + + + + + + true + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + false + + + false + + + + + + + Created: + + + + + + + true + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + + + Modified: + + + + + + + true + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 16 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + + + PDF Version: + + + + + + + Page Size: + + + + + + + Number of Pages: + + + + + + + Save + + + + + + + Close + + + true + + + true + + + false + + + + -- 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 ++++++++++++++++++---------- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 6 +- src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 28 ++-- 3 files changed, 151 insertions(+), 90 deletions(-) (limited to 'src-qt5') 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; +} diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 8337ed9c..60a1beb9 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -43,7 +43,7 @@ private: QPrinter* Printer; QPrintDialog *PrintDLG; QString lastdir; - bool matchCase, clearHighlights; + bool matchCase, highlight; QMap results; int currentHighlight; @@ -61,6 +61,7 @@ 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; @@ -89,7 +90,7 @@ private slots: void showBookmarks(); void newFocus(QWidget*, QWidget*); - void paintOnWidget(QPrinter *PRINTER); + void paintOnWidget(QPrinter*, bool); void paintToPrinter(QPrinter *PRINTER); //Button Slots @@ -109,5 +110,6 @@ signals: protected: void keyPressEvent(QKeyEvent*); void wheelEvent(QWheelEvent*); + void resizeEvent(QResizeEvent*); }; #endif diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui index c8cd8271..8f6fff27 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui @@ -6,7 +6,7 @@ 0 0 - 695 + 697 694 @@ -23,6 +23,12 @@ 61 + + + 0 + 0 + + QFrame::StyledPanel @@ -40,20 +46,7 @@ - - - - 16777215 - 24 - - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - + @@ -74,6 +67,9 @@ + + true + @@ -122,7 +118,7 @@ 0 0 - 695 + 697 21 -- 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 --- .../lumina-pdf/CM_PrintPreviewWidget.h | 34 -- src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp | 352 +++++++++++++++++++++ src-qt5/desktop-utils/lumina-pdf/PrintWidget.h | 114 +++++++ src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro | 5 +- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 6 +- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 3 +- 6 files changed, 474 insertions(+), 40 deletions(-) delete mode 100644 src-qt5/desktop-utils/lumina-pdf/CM_PrintPreviewWidget.h create mode 100644 src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp create mode 100644 src-qt5/desktop-utils/lumina-pdf/PrintWidget.h (limited to 'src-qt5') diff --git a/src-qt5/desktop-utils/lumina-pdf/CM_PrintPreviewWidget.h b/src-qt5/desktop-utils/lumina-pdf/CM_PrintPreviewWidget.h deleted file mode 100644 index ac457a10..00000000 --- a/src-qt5/desktop-utils/lumina-pdf/CM_PrintPreviewWidget.h +++ /dev/null @@ -1,34 +0,0 @@ -//=========================================== -// Lumina Desktop source code -// Copyright (c) 2017, Ken Moore -// Available under the 3-clause BSD license -// See the LICENSE file for full details -//=========================================== -// Simple subclass of QPrintPreviewWidget to provide -// notification when a context menu is requested -//=========================================== -#ifndef _CONTEXT_MENU_PRINT_PREVIEW_WIDGET_H -#define _CONTEXT_MENU_PRINT_PREVIEW_WIDGET_H - -#include -#include -#include - -class CM_PrintPreviewWidget : public QPrintPreviewWidget{ - Q_OBJECT -signals: - void customContextMenuRequested(const QPoint&); - -public: - CM_PrintPreviewWidget(QPrinter * printer = 0, QWidget *parent = 0) : QPrintPreviewWidget(printer, parent){ - this->setMouseTracking(true); - QList children = this->findChildren("",Qt::FindChildrenRecursively); - for(int i=0; isetContextMenuPolicy(Qt::CustomContextMenu); - connect(children[i], SIGNAL(customContextMenuRequested(const QPoint&)), this, SIGNAL(customContextMenuRequested(const QPoint&)) ); - } - } - -}; - -#endif diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp new file mode 100644 index 00000000..3fa87367 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -0,0 +1,352 @@ +#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; + this->setMouseTracking(true); + QList children = this->findChildren("",Qt::FindChildrenRecursively); + for(int i=0; isetContextMenuPolicy(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, SLOT(updateCurrentPage())); + QObject::connect(graphicsView, SIGNAL(resized()), this, SLOT(fit())); + + scene = new QGraphicsScene(graphicsView); + scene->setBackgroundBrush(Qt::gray); + graphicsView->setScene(scene); + + QVBoxLayout *layout = new QVBoxLayout; + setLayout(layout); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(graphicsView); +} + +PrintWidget::~PrintWidget() { + //Nothing here for now +} + +//Public Slots + +void PrintWidget::fitInView() { + setZoomMode(FitToWidth); +} + +void PrintWidget::fitToWidget() { + setZoomMode(FitInView); +} + +void PrintWidget::setZoomMode(ZoomMode mode) { + zoomMode = mode; + fitting = true; + fit(true); +} + +void PrintWidget::setAllPagesViewMode() { + setViewMode(AllPagesView); +} + +void PrintWidget::setSinglePageViewMode() { + setViewMode(SinglePageView); +} + +void PrintWidget::setFacingPagesViewMode() { + setViewMode(FacingPagesView); +} + +void PrintWidget::setViewMode(ViewMode mode) { + viewMode = mode; + layoutPages(); + if (viewMode == AllPagesView) { + graphicsView->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio); + fitting = false; + zoomMode = CustomZoom; + zoomFactor = graphicsView->transform().m11() * (double(printer->logicalDpiY()) / logicalDpiY()); + emit previewChanged(); + } else { + fitting = true; + fit(); + } +} + +void PrintWidget::zoomIn(double factor) { + fitting = false; + zoomMode = CustomZoom; + zoomFactor *= factor; + graphicsView->scale(factor, factor); +} + +void PrintWidget::zoomOut(double factor) { + fitting = false; + zoomMode = CustomZoom; + zoomFactor *= factor; + graphicsView->scale(1/factor, 1/factor); +} + +void PrintWidget::updatePreview() { + initialized = true; + generatePreview(); + graphicsView->updateGeometry(); +} + +void PrintWidget::setOrientation(QPrinter::Orientation orientation) { + printer->setOrientation(orientation); + generatePreview(); +} + +void PrintWidget::setVisible(bool visible) { + if(visible and !initialized) + updatePreview(); + QWidget::setVisible(visible); +} + +void PrintWidget::setCurrentPage(int pageNumber) { + 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 = graphicsView->horizontalScrollBar(); + QScrollBar *vsc = graphicsView->verticalScrollBar(); + QPointF pt = graphicsView->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)); + } + } +} + +//Private functions + +void PrintWidget::generatePreview() { + //printer->d_func()->setPreviewMode(true); + emit paintRequested(printer); + //printer->d_func()->setPreviewMode(false); + //pictures = printer->previewPages(); + populateScene(); // i.e. setPreviewPrintedPictures() e.l. + layoutPages(); + curPage = qBound(1, curPage, pages.count()); + if (fitting) + fit(); + emit previewChanged(); +} + +void PrintWidget::layoutPages() { + int numPages = pages.count(); + if (numPages < 1) + return; + + 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 += 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()); +} + +void PrintWidget::populateScene() +{ + for (int i = 0; i < pages.size(); i++) + scene->removeItem(pages.at(i)); + qDeleteAll(pages); + pages.clear(); + + int numPages = pictures.count(); + QSize paperSize = printer->pageLayout().fullRectPixels(printer->resolution()).size(); + QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); + + for (int i = 0; i < numPages; i++) { + PageItem* item = new PageItem(i+1, pictures.at(i), paperSize, pageRect); + scene->addItem(item); + pages.append(item); + } +} + + +//Private Slots +void PrintWidget::updateCurrentPage() { + if (viewMode == AllPagesView) + return; + + 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 items = graphicsView->items(viewRect); + for (int i=0; i(items.at(i)); + QRect overlap = graphicsView->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 = graphicsView->viewport()->rect(); + if (zoomMode == FitInView) { + QList containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect); + foreach(QGraphicsItem* item, containedItems) { + PageItem* pg = static_cast(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 = graphicsView->viewport()->width() / target.width(); + t.scale(scale, scale); + graphicsView->setTransform(t); + if (doFitting && fitting) { + QRectF viewSceneRect = graphicsView->viewportTransform().mapRect(graphicsView->viewport()->rect()); + viewSceneRect.moveTop(target.top()); + graphicsView->ensureVisible(viewSceneRect); // Nah... + } + } else { + graphicsView->fitInView(target, Qt::KeepAspectRatio); + if (zoomMode == FitInView) { + int step = qRound(graphicsView->matrix().mapRect(target).height()); + graphicsView->verticalScrollBar()->setSingleStep(step); + graphicsView->verticalScrollBar()->setPageStep(step); + } + } + + zoomFactor = graphicsView->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY()); + emit previewChanged(); +} diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h new file mode 100644 index 00000000..061aef49 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h @@ -0,0 +1,114 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// Simple subclass of QPrintPreviewWidget to provide +// notification when a context menu is requested +//=========================================== +#ifndef _PRINT_PREVIEW_WIDGET_H +#define _PRINT_PREVIEW_WIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class GraphicsView : public QGraphicsView +{ + 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(); + } + + void showEvent(QShowEvent* e) Q_DECL_OVERRIDE { + QGraphicsView::showEvent(e); + emit resized(); + } +}; + +class PrintWidget: public QWidget{ + Q_OBJECT +public: + enum ViewMode { + SinglePageView, + FacingPagesView, + AllPagesView + }; + + enum ZoomMode { + CustomZoom, + FitToWidth, + 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); + +public slots: + void zoomIn(double factor=1.2); + void zoomOut(double factor=1.2); + void setOrientation(QPrinter::Orientation); + void setCurrentPage(int); + + void fitInView(); + void fitToWidget(); + void setAllPagesViewMode(); + void setSinglePageViewMode(); + void setFacingPagesViewMode(); + + void updatePreview(); + +private slots: + void updateCurrentPage(); + int calcCurrentPage(); + void fit(bool doFitting=false); + +signals: + void customContextMenuRequested(const QPoint&); + void paintRequested(QPrinter*); + void previewChanged(); + +private: + void generatePreview(); + void layoutPages(); + void populateScene(); + void setViewMode(ViewMode viewMode); + void setZoomMode(ZoomMode viewMode); + + QPrinter *printer; + GraphicsView *graphicsView; + QGraphicsScene *scene; + int curPage; + QList pictures; + QList pages; + + ViewMode viewMode; + ZoomMode zoomMode; + double zoomFactor; + bool initialized, fitting; +}; + +#endif diff --git a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro index 3a031067..8ee67d06 100644 --- a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro +++ b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro @@ -19,10 +19,11 @@ message("Qt Modules Needed: $${QT}") SOURCES += main.cpp \ mainUI.cpp \ - propDialog.cpp + propDialog.cpp \ + PrintWidget.cpp HEADERS += mainUI.h \ - CM_PrintPreviewWidget.h \ + PrintWidget.h \ PresentationLabel.h \ PropDialog.h 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)) ); diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.h b/src-qt5/desktop-utils/lumina-pdf/mainUI.h index 60a1beb9..cce04cd4 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -22,6 +22,7 @@ #include #include "PresentationLabel.h" #include "propDialog.h" +#include "PrintWidget.h" namespace Ui{ class MainUI; @@ -37,7 +38,7 @@ public: private: Poppler::Document *DOC; - QPrintPreviewWidget *WIDGET; + PrintWidget *WIDGET; Ui::MainUI *ui; PropDialog *PROPDIALOG; QPrinter* Printer; -- 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/PrintWidget.cpp | 232 +++++++++-------------- src-qt5/desktop-utils/lumina-pdf/PrintWidget.h | 157 ++++++++++----- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 41 ++-- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 1 - 4 files changed, 210 insertions(+), 221 deletions(-) (limited to 'src-qt5') 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 children = this->findChildren("",Qt::FindChildrenRecursively); for(int i=0; isetContextMenuPolicy(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 items = graphicsView->items(viewRect); + QRect viewRect = this->viewport()->rect(); + QList items = this->items(viewRect); for (int i=0; i(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 containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect); + QList containedItems = this->items(viewRect, Qt::ContainsItemBoundingRect); foreach(QGraphicsItem* item, containedItems) { PageItem* pg = static_cast(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 *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 #include @@ -19,33 +19,85 @@ #include #include #include - -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*); +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 pictures; - QList pages; + QPrinter *printer; + QPreviewPaintEngine *previewEngine; + QPdfPrintEngine *pdfEngine; + int curPage; ViewMode viewMode; ZoomMode zoomMode; double zoomFactor; bool initialized, fitting; + QList pages; + QHash *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); -- cgit