aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-pdf/mainUI.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-pdf/mainUI.cpp186
1 files changed, 139 insertions, 47 deletions
diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp
index ce2707c9..f0429b9d 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
@@ -47,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;
@@ -54,7 +54,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);
@@ -88,11 +88,37 @@ 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(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); });
+ 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()) );
+ connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(showInformation()));
+
+ //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(curP<lastP);
+ ui->actionLast_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",""));
@@ -104,14 +130,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(){
@@ -256,7 +299,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();
@@ -296,7 +340,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();
@@ -311,8 +356,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<QScreen*> screens = QApplication::screens();
@@ -321,49 +364,46 @@ void MainUI::startLoadingPages(QPrinter *printer){
}*/
for(int i=0; i<numPages; i++){
//qDebug() << " - Kickoff page load:" << i;
- this->ccw = 0;
+ //this->ccw = 0;
QtConcurrent::run(this, &MainUI::loadPage, i, DOC, this, DPI, pageSize.size());
}
}
void MainUI::slotPageLoaded(int page){
+ Q_UNUSED(page);
//qDebug() << "Page Loaded:" << page;
int finished = loadingHash.keys().length();
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);
+ 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; }
- //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; i<numPages; i++){
- if(i != 0){ PRINTER->newPage(); } //this is the start of the next page (not needed for first)
- if(loadingHash.contains(i)){ painter.drawImage(0,0, loadingHash[i].scaled(PRINTER->pageRect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); 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; i<numPages; i++){
+ if(i != 0){ PRINTER->newPage(); } //this is the start of the next page (not needed for first)
+ if(loadingHash.contains(i)){ painter.drawImage(0,0, loadingHash[i].scaled(PRINTER->pageRect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); }
+ else{ painter.drawImage(0,0, QImage()); }
+ }
WIDGET->setContextMenuPolicy(Qt::CustomContextMenu);
+ loadingHash.clear();
}
void MainUI::paintToPrinter(QPrinter *PRINTER){
@@ -403,7 +443,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,32 +482,85 @@ 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(){
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(curP<lastP);
- contextMenu->addAction(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(ui->actionStop_Presentation);
+ }
+}
+
+void MainUI::keyPressEvent(QKeyEvent *event){
+ //See if this is one of the special hotkeys and act appropriately
+ bool inPresentation = (presentationLabel!=0);
+ if( event->key()==Qt::Key_Escape || event->key()==Qt::Key_Backspace){
+ if(inPresentation){ endPresentation(); }
+ }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){
+ prevPage();
+ }else if(event->key()==Qt::Key_Home){
+ firstPage();
+ }else if(event->key()==Qt::Key_End){
+ lastPage();
+ }else if(event->key()==Qt::Key_F11){
+ if(inPresentation){ endPresentation(); }
+ else{ startPresentationHere(); }
+ }else if(event->key() == Qt::Key_Up) {
+ //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);*/
}else{
- contextMenu->addAction(tr("Stop Presentation"), this, SLOT(closePresentation()) );
+ 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();
+}
bgstack15