diff --git a/ui/pageview.cpp b/ui/pageview.cpp --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -56,6 +57,8 @@ #include #include #include +#include +#include // system includes #include @@ -243,12 +246,15 @@ // Keep track of mouse over link object const Okular::ObjectRect * mouseOverLinkObject; + + Purpose::Menu * m_shareMenu; }; PageViewPrivate::PageViewPrivate( PageView *qq ) : q( qq ) #ifdef HAVE_SPEECH , m_tts( nullptr ) + , m_shareMenu(new Purpose::Menu) #endif { } @@ -2829,6 +2835,30 @@ menu.addAction( new OKMenuTitle( &menu, i18n( "Image (%1 by %2 pixels)", selectionRect.width(), selectionRect.height() ) ) ); imageToClipboard = menu.addAction( QIcon::fromTheme(QStringLiteral("image-x-generic")), i18n( "Copy to Clipboard" ) ); imageToFile = menu.addAction( QIcon::fromTheme(QStringLiteral("document-save")), i18n( "Save to File..." ) ); + d->m_shareMenu->setTitle(i18n("Share")); + d->m_shareMenu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); + d->m_shareMenu->model()->setPluginType(QStringLiteral("Export")); + + QString sharedFileName = QStringLiteral("/tmp/okularsave.png"); + + d->m_shareMenu->model()->setInputData(QJsonObject{ + { QStringLiteral("mimeType"), QJsonValue{QStringLiteral("image/png")} }, + { QStringLiteral("urls"), QJsonArray{QUrl::fromLocalFile(sharedFileName).toString()} } + }); + d->m_shareMenu->reload(); + + connect(d->m_shareMenu, &QMenu::triggered, this, [this, selectionRect, sharedFileName] { + // renders page into a pixmap and saves it + QPixmap copyPix( selectionRect.width(), selectionRect.height() ); + QPainter copyPainter( ©Pix ); + copyPainter.translate( -selectionRect.left(), -selectionRect.top() ); + drawDocumentOnPainter( selectionRect, ©Painter ); + copyPainter.end(); + copyPix.save( sharedFileName, qPrintable( "PNG" ) ); + }); + + menu.addAction(d->m_shareMenu->menuAction()); + QAction *choice = menu.exec( e->globalPos() ); // check if the user really selected an action if ( choice )