diff --git a/core/action.h b/core/action.h index f16b2ca35..c17c306b5 100644 --- a/core/action.h +++ b/core/action.h @@ -279,8 +279,6 @@ class OKULARCORE_EXPORT DocumentAction : public Action public: /** * Describes the possible action types. - * - * WARNING KEEP IN SYNC WITH POPPLER! */ enum DocumentActionType { PageFirst = 1, ///< Jump to first page @@ -294,7 +292,8 @@ public: EndPresentation = 9, ///< End presentation Find = 10, ///< Open find dialog GoToPage = 11, ///< Goto page - Close = 12 ///< Close document + Close = 12, ///< Close document + Print = 13 ///< Print the document @since 22.04 }; /** diff --git a/core/document.cpp b/core/document.cpp index bb26c5266..ea125537e 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -4004,6 +4004,9 @@ void Document::processAction(const Action *action) case DocumentAction::Close: emit close(); break; + case DocumentAction::Print: + emit requestPrint(); + break; } } break; diff --git a/core/document.h b/core/document.h index 0ce1db2ce..ab0608916 100644 --- a/core/document.h +++ b/core/document.h @@ -1111,6 +1111,13 @@ Q_SIGNALS: */ void close(); + /** + * This signal is emitted whenever an action requests a + * document print operation. + * @since 22.04 + */ + void requestPrint(); + /** * This signal is emitted whenever an action requests an * application quit operation. diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index f7fc8c73c..eac223045 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -338,6 +338,44 @@ QPair createMovieFromPopplerRichMedia(c return qMakePair(movie, pdfEmbeddedFile); } +static Okular::DocumentAction::DocumentActionType popplerToOkular(Poppler::LinkAction::ActionType pat) +{ + switch (pat) { + case Poppler::LinkAction::PageFirst: + return Okular::DocumentAction::PageFirst; + case Poppler::LinkAction::PagePrev: + return Okular::DocumentAction::PagePrev; + case Poppler::LinkAction::PageNext: + return Okular::DocumentAction::PageNext; + case Poppler::LinkAction::PageLast: + return Okular::DocumentAction::PageLast; + case Poppler::LinkAction::HistoryBack: + return Okular::DocumentAction::HistoryBack; + case Poppler::LinkAction::HistoryForward: + return Okular::DocumentAction::HistoryForward; + case Poppler::LinkAction::Quit: + return Okular::DocumentAction::Quit; + case Poppler::LinkAction::Presentation: + return Okular::DocumentAction::Presentation; + case Poppler::LinkAction::EndPresentation: + return Okular::DocumentAction::EndPresentation; + case Poppler::LinkAction::Find: + return Okular::DocumentAction::Find; + case Poppler::LinkAction::GoToPage: + return Okular::DocumentAction::GoToPage; + case Poppler::LinkAction::Close: + return Okular::DocumentAction::Close; + case Poppler::LinkAction::Print: + return Okular::DocumentAction::Print; + } + + qWarning() << "Unsupported Poppler::LinkAction::ActionType" << pat; + // TODO When we can use C++17 make this function return an optional + // for now it's not super important since at the time of writing + // okular DocumentAction supports all that poppler ActionType supports + return Okular::DocumentAction::PageFirst; +} + /** * Note: the function will take ownership of the popplerLink object. */ @@ -385,7 +423,7 @@ Okular::Action *createLinkFromPopplerLink(const Poppler::Link *popplerLink, bool case Poppler::Link::Action: popplerLinkAction = static_cast(popplerLink); - link = new Okular::DocumentAction((Okular::DocumentAction::DocumentActionType)popplerLinkAction->actionType()); + link = new Okular::DocumentAction(popplerToOkular(popplerLinkAction->actionType())); break; case Poppler::Link::Sound: { diff --git a/part/part.cpp b/part/part.cpp index eb3b3978d..b555dd1b0 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -359,6 +359,7 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &args) connect(m_document, &Document::openUrl, this, &Part::openUrlFromDocument); connect(m_document->bookmarkManager(), &BookmarkManager::openUrl, this, &Part::openUrlFromBookmarks); connect(m_document, &Document::close, this, &Part::close); + connect(m_document, &Document::requestPrint, this, &Part::slotPrint); connect(m_document, &Document::undoHistoryCleanChanged, this, [this](bool clean) { setModified(!clean); setWindowTitleFromDocument();