Support the PDF Print named action

Also stop casting directly from a poppler enum to an okular enum, it's
not cool

BUGS: 448791
This commit is contained in:
Albert Astals Cid 2022-01-19 22:44:23 +01:00
parent c9e09be0a9
commit fa6743aa04
5 changed files with 52 additions and 4 deletions

View file

@ -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
};
/**

View file

@ -4004,6 +4004,9 @@ void Document::processAction(const Action *action)
case DocumentAction::Close:
emit close();
break;
case DocumentAction::Print:
emit requestPrint();
break;
}
} break;

View file

@ -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.

View file

@ -338,6 +338,44 @@ QPair<Okular::Movie *, Okular::EmbeddedFile *> 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<const Poppler::LinkAction *>(popplerLink);
link = new Okular::DocumentAction((Okular::DocumentAction::DocumentActionType)popplerLinkAction->actionType());
link = new Okular::DocumentAction(popplerToOkular(popplerLinkAction->actionType()));
break;
case Poppler::Link::Sound: {

View file

@ -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();