Changeset View
Changeset View
Standalone View
Standalone View
ui/pageview.cpp
Show All 35 Lines | |||||
36 | #include <qclipboard.h> | 36 | #include <qclipboard.h> | ||
37 | #include <qmenu.h> | 37 | #include <qmenu.h> | ||
38 | #include <QInputDialog> | 38 | #include <QInputDialog> | ||
39 | #include <qdesktopwidget.h> | 39 | #include <qdesktopwidget.h> | ||
40 | #include <QDesktopServices> | 40 | #include <QDesktopServices> | ||
41 | #include <QMimeDatabase> | 41 | #include <QMimeDatabase> | ||
42 | #include <QMimeData> | 42 | #include <QMimeData> | ||
43 | #include <QGestureEvent> | 43 | #include <QGestureEvent> | ||
44 | #include <QJsonArray> | ||||
44 | 45 | | |||
45 | #include <qaction.h> | 46 | #include <qaction.h> | ||
46 | #include <kactionmenu.h> | 47 | #include <kactionmenu.h> | ||
47 | #include <kstandardaction.h> | 48 | #include <kstandardaction.h> | ||
48 | #include <kactioncollection.h> | 49 | #include <kactioncollection.h> | ||
49 | #include <KLocalizedString> | 50 | #include <KLocalizedString> | ||
50 | #include <kselectaction.h> | 51 | #include <kselectaction.h> | ||
51 | #include <ktoggleaction.h> | 52 | #include <ktoggleaction.h> | ||
52 | #include <QtCore/QDebug> | 53 | #include <QtCore/QDebug> | ||
53 | #include <kmessagebox.h> | 54 | #include <kmessagebox.h> | ||
54 | #include <QIcon> | 55 | #include <QIcon> | ||
55 | #include <kurifilter.h> | 56 | #include <kurifilter.h> | ||
56 | #include <kstringhandler.h> | 57 | #include <kstringhandler.h> | ||
57 | #include <ktoolinvocation.h> | 58 | #include <ktoolinvocation.h> | ||
58 | #include <krun.h> | 59 | #include <krun.h> | ||
60 | #include <PurposeWidgets/Menu> | ||||
apol: Purpose is already used in other parts of Okular and it's ifdef'd there. | |||||
61 | #include <Purpose/AlternativesModel> | ||||
59 | 62 | | |||
60 | // system includes | 63 | // system includes | ||
61 | #include <math.h> | 64 | #include <math.h> | ||
62 | #include <stdlib.h> | 65 | #include <stdlib.h> | ||
63 | 66 | | |||
64 | // local includes | 67 | // local includes | ||
65 | #include "debug_ui.h" | 68 | #include "debug_ui.h" | ||
66 | #include "formwidgets.h" | 69 | #include "formwidgets.h" | ||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Line(s) | 193 | #endif | |||
238 | 241 | | |||
239 | int setting_viewCols; | 242 | int setting_viewCols; | ||
240 | bool rtl_Mode; | 243 | bool rtl_Mode; | ||
241 | // Keep track of whether tablet pen is currently pressed down | 244 | // Keep track of whether tablet pen is currently pressed down | ||
242 | bool penDown; | 245 | bool penDown; | ||
243 | 246 | | |||
244 | // Keep track of mouse over link object | 247 | // Keep track of mouse over link object | ||
245 | const Okular::ObjectRect * mouseOverLinkObject; | 248 | const Okular::ObjectRect * mouseOverLinkObject; | ||
249 | | ||||
250 | Purpose::Menu * m_shareMenu; | ||||
246 | }; | 251 | }; | ||
247 | 252 | | |||
248 | PageViewPrivate::PageViewPrivate( PageView *qq ) | 253 | PageViewPrivate::PageViewPrivate( PageView *qq ) | ||
249 | : q( qq ) | 254 | : q( qq ) | ||
250 | #ifdef HAVE_SPEECH | 255 | #ifdef HAVE_SPEECH | ||
251 | , m_tts( nullptr ) | 256 | , m_tts( nullptr ) | ||
257 | , m_shareMenu(new Purpose::Menu) | ||||
252 | #endif | 258 | #endif | ||
253 | { | 259 | { | ||
254 | } | 260 | } | ||
255 | 261 | | |||
256 | FormWidgetsController* PageViewPrivate::formWidgetsController() | 262 | FormWidgetsController* PageViewPrivate::formWidgetsController() | ||
257 | { | 263 | { | ||
258 | if ( !formsWidgetController ) | 264 | if ( !formsWidgetController ) | ||
259 | { | 265 | { | ||
▲ Show 20 Lines • Show All 2564 Lines • ▼ Show 20 Line(s) | 2829 | #endif | |||
2824 | if ( copyAllowed ) | 2830 | if ( copyAllowed ) | ||
2825 | { | 2831 | { | ||
2826 | addWebShortcutsMenu( &menu, selectedText ); | 2832 | addWebShortcutsMenu( &menu, selectedText ); | ||
2827 | } | 2833 | } | ||
2828 | } | 2834 | } | ||
2829 | menu.addAction( new OKMenuTitle( &menu, i18n( "Image (%1 by %2 pixels)", selectionRect.width(), selectionRect.height() ) ) ); | 2835 | menu.addAction( new OKMenuTitle( &menu, i18n( "Image (%1 by %2 pixels)", selectionRect.width(), selectionRect.height() ) ) ); | ||
2830 | imageToClipboard = menu.addAction( QIcon::fromTheme(QStringLiteral("image-x-generic")), i18n( "Copy to Clipboard" ) ); | 2836 | imageToClipboard = menu.addAction( QIcon::fromTheme(QStringLiteral("image-x-generic")), i18n( "Copy to Clipboard" ) ); | ||
2831 | imageToFile = menu.addAction( QIcon::fromTheme(QStringLiteral("document-save")), i18n( "Save to File..." ) ); | 2837 | imageToFile = menu.addAction( QIcon::fromTheme(QStringLiteral("document-save")), i18n( "Save to File..." ) ); | ||
2838 | d->m_shareMenu->setTitle(i18n("Share")); | ||||
2839 | d->m_shareMenu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); | ||||
2840 | d->m_shareMenu->model()->setPluginType(QStringLiteral("Export")); | ||||
2841 | | ||||
2842 | QString sharedFileName = QStringLiteral("/tmp/okularsave.png"); | ||||
2843 | | ||||
2844 | d->m_shareMenu->model()->setInputData(QJsonObject{ | ||||
2845 | { QStringLiteral("mimeType"), QJsonValue{QStringLiteral("image/png")} }, | ||||
2846 | { QStringLiteral("urls"), QJsonArray{QUrl::fromLocalFile(sharedFileName).toString()} } | ||||
2847 | }); | ||||
2848 | d->m_shareMenu->reload(); | ||||
2849 | | ||||
2850 | connect(d->m_shareMenu, &QMenu::triggered, this, [this, selectionRect, sharedFileName] { | ||||
2851 | // renders page into a pixmap and saves it | ||||
aacid: Don't duplicate code that is just 3 lines below, reuse! | |||||
2852 | QPixmap copyPix( selectionRect.width(), selectionRect.height() ); | ||||
2853 | QPainter copyPainter( ©Pix ); | ||||
2854 | copyPainter.translate( -selectionRect.left(), -selectionRect.top() ); | ||||
2855 | drawDocumentOnPainter( selectionRect, ©Painter ); | ||||
2856 | copyPainter.end(); | ||||
2857 | copyPix.save( sharedFileName, qPrintable( "PNG" ) ); | ||||
2858 | }); | ||||
2859 | | ||||
2860 | menu.addAction(d->m_shareMenu->menuAction()); | ||||
2861 | | ||||
2832 | QAction *choice = menu.exec( e->globalPos() ); | 2862 | QAction *choice = menu.exec( e->globalPos() ); | ||
2833 | // check if the user really selected an action | 2863 | // check if the user really selected an action | ||
2834 | if ( choice ) | 2864 | if ( choice ) | ||
2835 | { | 2865 | { | ||
2836 | // IMAGE operation chosen | 2866 | // IMAGE operation chosen | ||
2837 | if ( choice == imageToClipboard || choice == imageToFile ) | 2867 | if ( choice == imageToClipboard || choice == imageToFile ) | ||
2838 | { | 2868 | { | ||
2839 | // renders page into a pixmap | 2869 | // renders page into a pixmap | ||
▲ Show 20 Lines • Show All 2698 Lines • Show Last 20 Lines |
Purpose is already used in other parts of Okular and it's ifdef'd there.