From e41f68cc4576b8581466051319c94a1e840049c4 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Wed, 21 Mar 2018 15:20:09 -0400 Subject: Added a bookmarks menu, enabled on the MuPDF side. --- src-qt5/desktop-utils/lumina-pdf/Bookmark.h | 17 + src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.cpp | 53 +++ src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.h | 27 ++ src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.ui | 47 ++ src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp | 16 + src-qt5/desktop-utils/lumina-pdf/PrintWidget.h | 4 +- src-qt5/desktop-utils/lumina-pdf/PropDialog.cpp | 49 ++ src-qt5/desktop-utils/lumina-pdf/PropDialog.h | 29 ++ src-qt5/desktop-utils/lumina-pdf/PropDialog.ui | 515 +++++++++++++++++++++ .../desktop-utils/lumina-pdf/Renderer-mupdf.cpp | 76 ++- .../desktop-utils/lumina-pdf/Renderer-poppler.cpp | 4 + src-qt5/desktop-utils/lumina-pdf/Renderer.h | 8 +- src-qt5/desktop-utils/lumina-pdf/TextData.h | 35 ++ src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro | 12 +- src-qt5/desktop-utils/lumina-pdf/mainUI.cpp | 50 +- src-qt5/desktop-utils/lumina-pdf/mainUI.h | 9 +- src-qt5/desktop-utils/lumina-pdf/mainUI.ui | 59 +-- src-qt5/desktop-utils/lumina-pdf/propDialog.cpp | 50 -- src-qt5/desktop-utils/lumina-pdf/propDialog.h | 27 -- src-qt5/desktop-utils/lumina-pdf/propDialog.ui | 515 --------------------- src-qt5/desktop-utils/lumina-pdf/textData.h | 35 -- 21 files changed, 910 insertions(+), 727 deletions(-) create mode 100644 src-qt5/desktop-utils/lumina-pdf/Bookmark.h create mode 100644 src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.cpp create mode 100644 src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.h create mode 100644 src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.ui 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 create mode 100644 src-qt5/desktop-utils/lumina-pdf/TextData.h delete mode 100644 src-qt5/desktop-utils/lumina-pdf/propDialog.cpp delete mode 100644 src-qt5/desktop-utils/lumina-pdf/propDialog.h delete mode 100644 src-qt5/desktop-utils/lumina-pdf/propDialog.ui delete mode 100644 src-qt5/desktop-utils/lumina-pdf/textData.h (limited to 'src-qt5') diff --git a/src-qt5/desktop-utils/lumina-pdf/Bookmark.h b/src-qt5/desktop-utils/lumina-pdf/Bookmark.h new file mode 100644 index 00000000..9a78beb2 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/Bookmark.h @@ -0,0 +1,17 @@ +#pragma once + +class Bookmark { + public: + Bookmark(char *_title, char *_link, int _pagenum, int _level) : + pagenum(_pagenum), + level(_level) + { + title = QString::fromLocal8Bit(_title); + link = QString::fromLocal8Bit(_link); + } + + QString title; + QString link; + int pagenum; + int level; +}; diff --git a/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.cpp b/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.cpp new file mode 100644 index 00000000..0a8dd695 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.cpp @@ -0,0 +1,53 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== + +#include "BookmarkMenu.h" +#include "ui_BookmarkMenu.h" +#include + +BookmarkMenu::BookmarkMenu(Renderer *Backend, QWidget *parent) : QWidget(parent), ui(new Ui::BookmarkMenu()), BACKEND(Backend){ + ui->setupUi(this); + ui->closeButton->setIcon( LXDG::findIcon("dialog-close") ); + connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); + connect(ui->bookmarks, &QTreeWidget::itemClicked, this, [=](QTreeWidgetItem *item) { + Backend->handleLink(item->data(1, Qt::UserRole).toString()); }); + + ui->bookmarks->setHeaderLabel("Title"); +} + +void BookmarkMenu::loadBookmarks() { + QTreeWidgetItem *item=nullptr, *parent=nullptr; + QList bookmarks = BACKEND->getBookmarks(); + + if(ui->bookmarks->topLevelItemCount() != 0) { + ui->bookmarks->clear(); + } + + //Modfiy for more than 2 levels + if(bookmarks.empty()) { + item = new QTreeWidgetItem(ui->bookmarks); + item->setText(0, "No Bookmarks"); + item->setData(1, Qt::UserRole, ""); + item->setIcon(0, LXDG::findIcon("bookmark-remove")); + }else{ + foreach(Bookmark *bm, bookmarks) { + if(bm->level == 0) { + item = new QTreeWidgetItem(ui->bookmarks); + parent = item; + }else{ + item = new QTreeWidgetItem(parent); + } + + item->setText(0, bm->title); + item->setData(1, Qt::UserRole, bm->link); + if(!bm->link.isEmpty()) + item->setIcon(0, LXDG::findIcon("bookmark-new")); + else + item->setIcon(0, LXDG::findIcon("bookmark-remove")); + } + } +} diff --git a/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.h b/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.h new file mode 100644 index 00000000..46921f6f --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.h @@ -0,0 +1,27 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#pragma once + +#include +#include +#include "Renderer.h" + +namespace Ui{ + class BookmarkMenu; +}; + +class BookmarkMenu : public QWidget{ + Q_OBJECT + public: + BookmarkMenu(Renderer *Backend, QWidget *parent=NULL); + public slots: + void loadBookmarks(); + + private: + Ui::BookmarkMenu *ui; + Renderer *BACKEND; +}; diff --git a/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.ui b/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.ui new file mode 100644 index 00000000..de19be66 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/BookmarkMenu.ui @@ -0,0 +1,47 @@ + + + BookmarkMenu + + + + 0 + 0 + 109 + 507 + + + + Form + + + + + + + + + + + + + Bookmarks + + + Qt::AlignCenter + + + + + + + + 1 + + + + + + + + + diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp index 7c0fd323..63d25be4 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.cpp @@ -315,3 +315,19 @@ void PrintWidget::fit(bool doFitting) { //zoomFactor = this->transform().m11() * (float(printer->logicalDpiY()) / this->logicalDpiY()); } + +void PrintWidget::goToPosition(int pagenum, float x, float y) { + setCurrentPage(pagenum+1); + QPointF pt = this->transform().map(pages.at(pagenum)->pos()); + + if (zoomMode != FitInView) { + if(x != 0) { + QScrollBar *hsc = this->horizontalScrollBar(); + hsc->setValue(int(pt.x() + x) - 10); + } + if(y != 0) { + QScrollBar *vsc = this->verticalScrollBar(); + vsc->setValue(int(pt.y() + y) - 10); + } + } +} diff --git a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h index 98bcd259..92d82e11 100644 --- a/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h +++ b/src-qt5/desktop-utils/lumina-pdf/PrintWidget.h @@ -20,8 +20,7 @@ #include #include #include "Renderer.h" - -#include "textData.h" +#include "TextData.h" class PageItem : public QGraphicsItem { public: @@ -135,6 +134,7 @@ public slots: void setCurrentPage(int); void setVisible(bool) Q_DECL_OVERRIDE; void highlightText(TextData*); + void goToPosition(int, float, float); void updatePreview(); void fitView(); 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..a7a67f03 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/PropDialog.cpp @@ -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 +//=========================================== + +#include "PropDialog.h" +#include "ui_PropDialog.h" +#include + +PropDialog::PropDialog(Renderer *Backend) : QDialog(), ui(new Ui::PropDialog()), BACKEND(Backend){ + ui->setupUi(this); + this->setWindowTitle(tr("PDF Information")); + this->setWindowIcon( LXDG::findIcon("dialog-information","unknown")); + + connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); + + //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->saveButton->setText(tr("Save")); + ui->closeButton->setText(tr("Close")); +} + +//Load size from mainUI after pages have loaded +void PropDialog::setSize(QSizeF pageSize) { + ui->sizeL->setText(tr("Page Size: ") + QString::number(pageSize.width())+", "+QString::number(pageSize.height())); +} + +//Fill the text boxes with information from the document +void PropDialog::setInformation() { + QJsonObject info = BACKEND->properties(); + ui->titleE->setText( info.value("title").toString() ); + ui->subjectE->setText( info.value("subject").toString() ); + ui->authorE->setText( info.value("author").toString() ); + ui->creatorE->setText( info.value("creator").toString() ); + ui->producerE->setText( info.value("producer").toString() ); + ui->keywordE->setText( info.value("keywords").toString() ); + ui->createdEntry->setText( info.value("dt_created").toString() ); + ui->modifiedEntry->setText( info.value("dt_modified").toString() ); + ui->numberL->setText( tr("Number of Pages: ") + QString::number(BACKEND->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..aa8f4d92 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/PropDialog.h @@ -0,0 +1,29 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#pragma once + +#include +#include +#include "Renderer.h" + +namespace Ui{ + class PropDialog; +}; + +class PropDialog : public QDialog { + Q_OBJECT + public: + PropDialog(Renderer *Backend); + + public slots: + void setSize(QSizeF); + void setInformation(); + + private: + Ui::PropDialog *ui; + Renderer *BACKEND; +}; 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..d79d2087 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/PropDialog.ui @@ -0,0 +1,515 @@ + + + PropDialog + + + + 0 + 0 + 627 + 655 + + + + PDF Information + + + + + + Title: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + Qt::TextSelectableByKeyboard + + + + + + + Subject: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + Qt::TextSelectableByKeyboard + + + + + + + Author: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + Qt::TextSelectableByMouse + + + + + + + Creator: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + QTextEdit::WidgetWidth + + + true + + + false + + + Qt::TextSelectableByMouse + + + + + + + Producer: + + + + + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + + + Keywords: + + + + + + + true + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + + + Created: + + + + + + + true + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + + + Modified: + + + + + + + true + + + + 0 + 0 + + + + + 256 + 16 + + + + + 512 + 128 + + + + false + + + false + + + QFrame::StyledPanel + + + QFrame::Sunken + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + true + + + false + + + + + + + Page Size: + + + + + + + Number of Pages: + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Save + + + + + + + Close + + + true + + + true + + + false + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp index 23d9b3d1..7846e9c1 100644 --- a/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-mupdf.cpp @@ -1,14 +1,14 @@ #include "Renderer.h" #include #include +#include #include #include #include class Data { public: - Data(int _pagenum, fz_context *_ctx, fz_display_list *_list, fz_rect _bbox, fz_pixmap *_pix, fz_matrix _ctm, double _sf) : - pagenumber(_pagenum), + Data(int _pagenum, fz_context *_ctx, fz_display_list *_list, fz_rect _bbox, fz_pixmap *_pix, fz_matrix _ctm, double _sf) : pagenumber(_pagenum), ctx(_ctx), list(_list), bbox(_bbox), @@ -66,9 +66,8 @@ Renderer::Renderer(){ } Renderer::~Renderer(){ - qDebug() << "Calling destructor"; - qDeleteAll(dataHash); - dataHash.clear(); + qDebug() << "Dropping Context"; + clearHash(); fz_drop_document(CTX, DOC); DOC = NULL; fz_drop_context(CTX); @@ -77,6 +76,33 @@ Renderer::~Renderer(){ bool Renderer::loadMultiThread(){ return false; } +void Renderer::handleLink(QString link) { + float xp = 0.0, yp = 0.0; + int pagenum = 0; + + QByteArray linkData = link.toLocal8Bit(); + char *uri = linkData.data(); + + if(!link.isEmpty()) { + pagenum = fz_resolve_link(CTX, DOC, uri, &xp, &yp); + emit goToPosition(pagenum, xp, yp); + } +} + +//Traverse the outline tree through Preorder traversal +void Renderer::traverseOutline(void *link, int level) { + fz_outline *olink = (fz_outline*)link; + + Bookmark *bm = new Bookmark(olink->title, olink->uri, olink->page, level); + bookmarks.push_back(bm); + + if(olink->down) + traverseOutline(olink->down, level+1); + + if(olink->next) + traverseOutline(olink->next, level); +} + bool Renderer::loadDocument(QString path, QString password){ //first time through if(path != docpath) { @@ -86,13 +112,17 @@ bool Renderer::loadDocument(QString path, QString password){ DOC = NULL; needpass = false; docpath = path; + if(bookmarks.size() > 0) { + qDeleteAll(bookmarks); + bookmarks.clear(); + } }else if(DOC==0){ fz_register_document_handlers(CTX); qDebug() << "Document handlers registered"; } - DOC = fz_open_document(CTX, path.toLocal8Bit().data()); docpath = path; + DOC = fz_open_document(CTX, path.toLocal8Bit().data()); qDebug() << "File opened" << DOC; if(DOC==0){ qDebug() << "Could not open file:" << path; @@ -107,13 +137,13 @@ bool Renderer::loadDocument(QString path, QString password){ if(needpass){ return false; } //incorrect password } - //qDebug() << "Password Check cleared"; + qDebug() << "Password Check cleared"; pnum = fz_count_pages(CTX, DOC); qDebug() << "Page count: " << pnum; doctitle.clear(); - //qDebug() << "Opening File:" << path; - jobj.insert("title", getTextInfo("Title") ); + + qDebug() << "Opening File:" << path; jobj.insert("subject", getTextInfo("Subject") ); jobj.insert("author", getTextInfo("Author") ); jobj.insert("creator", getTextInfo("Creator") ); @@ -122,13 +152,21 @@ bool Renderer::loadDocument(QString path, QString password){ jobj.insert("dt_created", QDateTime::fromString( getTextInfo("CreationDate").left(16), "'D:'yyyyMMddHHmmss").toString() ); jobj.insert("dt_modified", QDateTime::fromString( getTextInfo("ModDate").left(16), "'D:'yyyyMMddHHmmss").toString() ); - if(!jobj["title"].isNull()) + if(!jobj["title"].toString().isEmpty()) doctitle = jobj["title"].toString(); else doctitle = path.section("/",-1); - qDebug() << "Page Loaded"; //Possibly check Page orientation + + fz_outline *outline = fz_load_outline(CTX, DOC); + if(outline) + traverseOutline(outline, 0); + else + qDebug() << "No Bookmarks"; + + fz_drop_outline(CTX, outline); + return true; } return false; @@ -162,7 +200,6 @@ void renderer(Data *data, Renderer *obj) emit obj->PageLoaded(pagenum); } -//Consider rendering through a display list void Renderer::renderPage(int pagenum, QSize DPI, int degrees){ //qDebug() << "- Rendering Page:" << pagenum << degrees; Data *data; @@ -172,7 +209,7 @@ void Renderer::renderPage(int pagenum, QSize DPI, int degrees){ fz_pixmap *pixmap; fz_display_list *list; - double pageDPI = 96.0; + double pageDPI = 150.0; double sf = DPI.width() / pageDPI; fz_scale(&matrix, sf, sf); fz_pre_rotate(&matrix, degrees); @@ -185,6 +222,17 @@ void Renderer::renderPage(int pagenum, QSize DPI, int degrees){ list = fz_new_display_list(CTX, &bbox); fz_device *dev = fz_new_list_device(CTX, list); fz_run_page(CTX, PAGE, dev, &fz_identity, NULL); + /*fz_annot *annot = fz_first_annot(CTX, PAGE); + + while(annot) { + fz_run_annot(CTX, annot, dev, &fz_identity, NULL); + fz_rect bbox; + fz_bound_annot(CTX, annot, &bbox); + + QRectF rect(bbox.x0, bbox.y0, (bbox.x1-bbox.x0), (bbox.y1 - bbox.y0)); + qDebug() << "Annotation:" << rect << "at" << pagenum; + annot = fz_next_annot(CTX, annot); + }*/ fz_close_device(CTX, dev); fz_drop_device(CTX, dev); @@ -201,7 +249,7 @@ QList Renderer::searchDocument(QString text, bool matchCase){ fz_rect rectBuffer[1000]; QList results; for(int i = 0; i < pnum; i++) { - int count = fz_search_display_list(CTX, dataHash[i]->list, text.toLatin1().data(), rectBuffer, 1000); + int count = fz_search_display_list(CTX, dataHash[i]->list, text.toLocal8Bit().data(), rectBuffer, 1000); //qDebug() << "Page " << i+1 << ": Count, " << count; for(int j = 0; j < count; j++) { double sf = dataHash[i]->sf; diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp index 439fd804..28045539 100644 --- a/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/Renderer-poppler.cpp @@ -128,3 +128,7 @@ void Renderer::clearHash() { } bool Renderer::supportsExtraFeatures() { return false; } + +void Renderer::traverseOutline(void *, int) { } + +void Renderer::handleLink(QString link) { } diff --git a/src-qt5/desktop-utils/lumina-pdf/Renderer.h b/src-qt5/desktop-utils/lumina-pdf/Renderer.h index ab86724d..22548278 100644 --- a/src-qt5/desktop-utils/lumina-pdf/Renderer.h +++ b/src-qt5/desktop-utils/lumina-pdf/Renderer.h @@ -10,7 +10,8 @@ #include #include #include -#include "textData.h" +#include "TextData.h" +#include "Bookmark.h" class Renderer : public QObject { Q_OBJECT @@ -22,6 +23,7 @@ private: QString doctitle; QJsonObject jobj; int degrees; + QList bookmarks; public: Renderer(); @@ -36,11 +38,14 @@ public: int hashSize(); QImage imageHash(int pagenum); int rotatedDegrees() { return degrees; } + QList getBookmarks() { return bookmarks; } //Main access functions bool loadDocument(QString path, QString password); void renderPage(int pagenum, QSize DPI, int degrees=0); QList searchDocument(QString text, bool matchCase); + void traverseOutline(void *, int); + void handleLink(QString); void clearHash(); //Makes sure degrees is between 0 and 360 then rotates the matrix and @@ -56,6 +61,7 @@ signals: void PageLoaded(int); void OrigSize(QSizeF); void reloadPages(int); + void goToPosition(int, float, float); }; #endif diff --git a/src-qt5/desktop-utils/lumina-pdf/TextData.h b/src-qt5/desktop-utils/lumina-pdf/TextData.h new file mode 100644 index 00000000..9bf7e5bb --- /dev/null +++ b/src-qt5/desktop-utils/lumina-pdf/TextData.h @@ -0,0 +1,35 @@ +#ifndef textData_H +#define textData_H + +#include + +class TextData { + private: + QRectF p_loc; + bool p_highlighted=false; + int p_page=0; + QString p_text=""; + //int p_degrees=0; + + public: + TextData(QRectF _loc, int _page, QString _text) : + p_loc(_loc), + p_page(_page), + p_text(_text) + //p_degrees(_degrees) + { } + + QRectF loc() { return p_loc; } + bool highlighted() { return p_highlighted; } + int page() { return p_page; } + QString text() { return p_text; } + //int degrees() { return p_degrees; } + + void loc(QRect loc) { p_loc = loc; } + void highlighted(bool highlighted) { p_highlighted = highlighted; } + void page(int page) { p_page = page; } + void text(QString text) { p_text = text; } + //void degrees(int degrees) { p_degrees = degrees; } +}; + +#endif diff --git a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro index 8ed0e9f3..17a76c3a 100644 --- a/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro +++ b/src-qt5/desktop-utils/lumina-pdf/lumina-pdf.pro @@ -19,18 +19,22 @@ message("Qt Modules Needed: $${QT}") SOURCES += main.cpp \ mainUI.cpp \ - propDialog.cpp \ - PrintWidget.cpp + PropDialog.cpp \ + PrintWidget.cpp \ + BookmarkMenu.cpp HEADERS += mainUI.h \ PrintWidget.h \ PresentationLabel.h \ PropDialog.h \ Renderer.h \ - textData.h + TextData.h \ + Bookmark.h \ + BookmarkMenu.h FORMS += mainUI.ui \ - propDialog.ui + PropDialog.ui \ + BookmarkMenu.ui isEmpty(USE_MUPDF){ message("Using Poppler-Qt5 Backend") diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp index 3c2d1541..011f8660 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.cpp @@ -29,7 +29,10 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ CurrentPage = 1; lastdir = QDir::homePath(); BACKEND = new Renderer(); - PROPDIALOG=nullptr; + PROPDIALOG = new PropDialog(BACKEND); + BOOKMARKS = new BookmarkMenu(BACKEND, this->centralWidget()); + BOOKMARKS->setContextMenuPolicy(Qt::CustomContextMenu); + BOOKMARKS->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //Create the interface widgets WIDGET = new PrintWidget(BACKEND, this->centralWidget()); WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); @@ -52,11 +55,13 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ connect(contextMenu, SIGNAL(aboutToShow()), this, SLOT(updateContextMenu())); this->centralWidget()->layout()->replaceWidget(ui->label_replaceme, WIDGET); ui->label_replaceme->setVisible(false); - WIDGET->setContextMenuPolicy(Qt::CustomContextMenu); + this->centralWidget()->layout()->replaceWidget(ui->label_replaceme2, BOOKMARKS); + ui->label_replaceme2->setVisible(false); connect(WIDGET, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(showContextMenu(const QPoint&)) ); connect(WIDGET, SIGNAL(currentPageChanged()), this, SLOT(updatePageNumber()) ); connect(BACKEND, SIGNAL(PageLoaded(int)), this, SLOT(slotPageLoaded(int)) ); connect(BACKEND, SIGNAL(reloadPages(int)), this, SLOT(startLoadingPages(int))); + connect(BACKEND, SIGNAL(goToPosition(int, float, float)), WIDGET, SLOT(goToPosition(int, float, float))); PrintDLG = new QPrintDialog(this); connect(PrintDLG, SIGNAL(accepted(QPrinter*)), this, SLOT(paintToPrinter(QPrinter*)) ); @@ -133,11 +138,9 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ [&] (bool value) { this->matchCase = value; }); connect(ui->closeFind, &QPushButton::clicked, this, [&] { ui->findGroup->setVisible(false); this->setFocus(); }); - connect(ui->closeBookmarks, &QPushButton::clicked, this, - [&] { ui->bookmarksFrame->setVisible(false); this->setFocus(); }); connect(ui->actionClearHighlights, &QAction::triggered, WIDGET, [&] { WIDGET->updatePreview(); }); - connect(ui->actionBookmarks, SIGNAL(triggered()), this, SLOT(showBookmarks())); + connect(ui->actionBookmarks, &QAction::triggered, this, [=] () { BOOKMARKS->setVisible(true); }); //qDebug() << "Finished connctions"; @@ -195,9 +198,6 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->findNextB->setIcon(LXDG::findIcon("go-down-search")); ui->matchCase->setIcon(LXDG::findIcon("format-text-italic")); ui->closeFind->setIcon(LXDG::findIcon("dialog-close")); - ui->closeBookmarks->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); @@ -205,7 +205,6 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ ui->actionStart_Begin->setEnabled(false); ui->findGroup->setVisible(false); - ui->bookmarksFrame->setVisible(false); //TESTING features/functionality bool TESTING = BACKEND->supportsExtraFeatures(); @@ -234,6 +233,8 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){ } MainUI::~MainUI(){ + if(BOOKMARKS!=0){ BOOKMARKS->deleteLater(); } + if(PROPDIALOG!=0) { PROPDIALOG->deleteLater(); } delete BACKEND; } @@ -247,19 +248,18 @@ void MainUI::loadFile(QString path){ if(!ok){ break; } //cancelled } //Clear the current display + WIDGET->setVisible(false); - QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); + BOOKMARKS->setVisible(false); //Load the new document info this->setWindowTitle( BACKEND->title()); if(BACKEND->needPassword()){ return; } //cancelled; qDebug() << " - Document Setup : start loading pages now"; - QTimer::singleShot(50, [&]() { startLoadingPages(0); } ); -} -void MainUI::loadPage(int num, MainUI *obj, QSize dpi, int degrees){ - //qDebug() << " - Render Page:" << num; - BACKEND->renderPage(num, dpi, degrees); - //qDebug() << "Image at" << num << "accessed outside:" << BACKEND->imageHash(num).isNull(); + //Populate or repopulate the Bookmarks menu and Properties Dialog + QTimer::singleShot(10, BOOKMARKS, SLOT(loadBookmarks()) ); + QTimer::singleShot(10, PROPDIALOG, SLOT(setInformation()) ); + QTimer::singleShot(50, [&]() { startLoadingPages(0); } ); } QScreen* MainUI::getScreen(bool current, bool &cancelled){ @@ -373,8 +373,6 @@ void MainUI::startLoadingPages(int degrees){ qDebug() <<"Start Loading Pages"; //if(BACKEND->hashSize() != 0) { return; } //currently loaded[ing] loadingQueue.clear(); - if(PROPDIALOG) - delete PROPDIALOG; BACKEND->clearHash(); WIDGET->setVisible(false); //qDebug() << "Update Progress Bar"; @@ -389,15 +387,15 @@ void MainUI::startLoadingPages(int degrees){ QSize DPI(300,300); //print-quality (some printers even go to 600 DPI nowdays) - qDebug() << "Screen Resolutions:"; + /*qDebug() << "Screen Resolutions:"; QList screens = QApplication::screens(); for(int i=0; iname() << screens[i]->logicalDotsPerInchX() << screens[i]->logicalDotsPerInchY(); - } + }*/ for(int i=0; inumPages(); i++){ //qDebug() << " - Kickoff page load:" << i; if(BACKEND->loadMultiThread()) { - QtConcurrent::run(this, &MainUI::loadPage, i, this, DPI, degrees); + QtConcurrent::run(BACKEND, &Renderer::renderPage, i, DPI, degrees); }else{ BACKEND->renderPage(i, DPI, degrees); } @@ -406,20 +404,18 @@ void MainUI::startLoadingPages(int degrees){ } void MainUI::slotPageLoaded(int page){ - loadingQueue.push_back(page); + loadingQueue.push_back(page); int finished = loadingQueue.size(); //qDebug() << "Page Loaded:" << page << finished; if(finished == BACKEND->numPages()){ - //qDebug() << " - finished:" << finished; progAct->setVisible(false); WIDGET->setVisible(true); WIDGET->setCurrentPage(1); - PROPDIALOG = new PropDialog(BACKEND); - PROPDIALOG->setSize(pageSize); ui->actionStop_Presentation->setEnabled(false); ui->actionStart_Here->setEnabled(true); ui->actionStart_Begin->setEnabled(true); pageAct->setVisible(true); + PROPDIALOG->setSize(pageSize); qDebug() << " - Document Setup: All pages loaded"; QTimer::singleShot(10, WIDGET, SLOT(updatePreview())); //start loading the file preview }else{ @@ -644,7 +640,3 @@ void MainUI::find(QString text, bool forward) { } } } - -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 311bb46d..10f2d2e4 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.h +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.h @@ -21,10 +21,11 @@ #include #include "Renderer.h" +#include "BookmarkMenu.h" #include "PresentationLabel.h" -#include "propDialog.h" +#include "PropDialog.h" #include "PrintWidget.h" -#include "textData.h" +#include "TextData.h" namespace Ui{ class MainUI; @@ -43,6 +44,7 @@ private: PrintWidget *WIDGET; Ui::MainUI *ui; PropDialog *PROPDIALOG; + BookmarkMenu *BOOKMARKS; QPrintDialog *PrintDLG; QString lastdir; bool matchCase; @@ -62,8 +64,6 @@ private: //PDF Page Loading cache variables Renderer *BACKEND; - void loadPage(int num, MainUI *obj, QSize dpi, int degrees); - //Functions/variables for the presentation mode PresentationLabel *presentationLabel; QScreen *getScreen(bool current, bool &cancelled); @@ -86,7 +86,6 @@ private slots: void closePresentation(){ endPresentation(); } void find(QString text, bool forward); - void showBookmarks(); void paintToPrinter(QPrinter *PRINTER); diff --git a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui index e8b07c26..92921057 100644 --- a/src-qt5/desktop-utils/lumina-pdf/mainUI.ui +++ b/src-qt5/desktop-utils/lumina-pdf/mainUI.ui @@ -46,50 +46,6 @@ - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 6 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - - - - - - - Bookmarks - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - @@ -170,6 +126,19 @@ + + + + + 0 + 0 + + + + Bookmarks Area + + + @@ -178,7 +147,7 @@ 0 0 697 - 38 + 23 diff --git a/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp b/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp deleted file mode 100644 index c721f65f..00000000 --- a/src-qt5/desktop-utils/lumina-pdf/propDialog.cpp +++ /dev/null @@ -1,50 +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 -//=========================================== - -#include "propDialog.h" -#include "ui_propDialog.h" - -#include - -PropDialog::PropDialog(Renderer *Backend) : QDialog(), ui(new Ui::PropDialog()){ - ui->setupUi(this); - this->setWindowTitle(tr("PDF Information")); - this->setWindowIcon( LXDG::findIcon("dialog-information","unknown")); - - connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); - - //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->sizeL->setText(tr("Page Size: ")); - ui->numberL->setText(tr("Number of Pages: ")); - ui->saveButton->setText(tr("Save")); - ui->closeButton->setText(tr("Close")); - - QJsonObject info = Backend->properties(); - //Fill the text boxes with information from the document - ui->titleE->setText( info.value("title").toString() ); - ui->subjectE->setText( info.value("subject").toString() ); - ui->authorE->setText( info.value("author").toString() ); - ui->creatorE->setText( info.value("creator").toString() ); - ui->producerE->setText( info.value("producer").toString() ); - ui->keywordE->setText( info.value("keywords").toString() ); - ui->createdEntry->setText( info.value("dt_created").toString() ); - ui->modifiedEntry->setText( info.value("dt_modified").toString() ); - ui->numberL->setText( ui->numberL->text() + QString::number(Backend->numPages()) ); -} - -//Load size from mainUI after pages have loaded -void PropDialog::setSize(QSizeF pageSize) { - ui->sizeL->setText(ui->sizeL->text()+QString::number(pageSize.width())+", "+QString::number(pageSize.height())); -} diff --git a/src-qt5/desktop-utils/lumina-pdf/propDialog.h b/src-qt5/desktop-utils/lumina-pdf/propDialog.h deleted file mode 100644 index 23b8c877..00000000 --- a/src-qt5/desktop-utils/lumina-pdf/propDialog.h +++ /dev/null @@ -1,27 +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 -//=========================================== -#ifndef _LUMINA_PDF_VIEWER_PROP_DIALOG_H -#define _LUMINA_PDF_VIEWER_PROP_DIALOG_H - -#include -#include -#include "Renderer.h" - -namespace Ui{ - class PropDialog; -}; - -class PropDialog : public QDialog { - Q_OBJECT - public: - PropDialog(Renderer *Backend); - void setSize(QSizeF); - - 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 deleted file mode 100644 index d79d2087..00000000 --- a/src-qt5/desktop-utils/lumina-pdf/propDialog.ui +++ /dev/null @@ -1,515 +0,0 @@ - - - PropDialog - - - - 0 - 0 - 627 - 655 - - - - PDF Information - - - - - - Title: - - - - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - Qt::TextSelectableByKeyboard - - - - - - - Subject: - - - - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - Qt::TextSelectableByKeyboard - - - - - - - Author: - - - - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - Qt::TextSelectableByMouse - - - - - - - Creator: - - - - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - QTextEdit::WidgetWidth - - - true - - - false - - - Qt::TextSelectableByMouse - - - - - - - Producer: - - - - - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - - - - - Keywords: - - - - - - - true - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - false - - - QFrame::StyledPanel - - - QFrame::Sunken - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - - - - - Created: - - - - - - - true - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - false - - - QFrame::StyledPanel - - - QFrame::Sunken - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - - - - - Modified: - - - - - - - true - - - - 0 - 0 - - - - - 256 - 16 - - - - - 512 - 128 - - - - false - - - false - - - QFrame::StyledPanel - - - QFrame::Sunken - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - true - - - false - - - - - - - Page Size: - - - - - - - Number of Pages: - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Save - - - - - - - Close - - - true - - - true - - - false - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - diff --git a/src-qt5/desktop-utils/lumina-pdf/textData.h b/src-qt5/desktop-utils/lumina-pdf/textData.h deleted file mode 100644 index 9bf7e5bb..00000000 --- a/src-qt5/desktop-utils/lumina-pdf/textData.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef textData_H -#define textData_H - -#include - -class TextData { - private: - QRectF p_loc; - bool p_highlighted=false; - int p_page=0; - QString p_text=""; - //int p_degrees=0; - - public: - TextData(QRectF _loc, int _page, QString _text) : - p_loc(_loc), - p_page(_page), - p_text(_text) - //p_degrees(_degrees) - { } - - QRectF loc() { return p_loc; } - bool highlighted() { return p_highlighted; } - int page() { return p_page; } - QString text() { return p_text; } - //int degrees() { return p_degrees; } - - void loc(QRect loc) { p_loc = loc; } - void highlighted(bool highlighted) { p_highlighted = highlighted; } - void page(int page) { p_page = page; } - void text(QString text) { p_text = text; } - //void degrees(int degrees) { p_degrees = degrees; } -}; - -#endif -- cgit