opt: open image in external tool (#1308)

* opt: open image in external tool

* [autofix.ci] apply automated fixes

---------

Co-authored-by: YiFang Xiao <yifang.xiao@noreply.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2023-12-05 14:59:45 +08:00 committed by GitHub
parent b6420c87f7
commit 64f69d2235
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,7 @@
#include <QWebEngineSettings> #include <QWebEngineSettings>
#include <map> #include <map>
#include <QApplication> #include <QApplication>
#include <QRandomGenerator>
#if ( QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) ) #if ( QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
#include <QWebEngineContextMenuData> #include <QWebEngineContextMenuData>
@ -1493,6 +1494,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
QAction * addHeaderToHistoryAction = nullptr; QAction * addHeaderToHistoryAction = nullptr;
QAction * sendWordToInputLineAction = nullptr; QAction * sendWordToInputLineAction = nullptr;
QAction * saveImageAction = nullptr; QAction * saveImageAction = nullptr;
QAction * openImageAction = nullptr;
QAction * saveSoundAction = nullptr; QAction * saveSoundAction = nullptr;
QAction * saveBookmark = nullptr; QAction * saveBookmark = nullptr;
@ -1536,6 +1538,9 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
menu.addAction( webview->pageAction( QWebEnginePage::CopyImageToClipboard ) ); menu.addAction( webview->pageAction( QWebEnginePage::CopyImageToClipboard ) );
saveImageAction = new QAction( tr( "Save &image..." ), &menu ); saveImageAction = new QAction( tr( "Save &image..." ), &menu );
menu.addAction( saveImageAction ); menu.addAction( saveImageAction );
openImageAction = new QAction( tr( "Open image in system viewer..." ), &menu );
menu.addAction( openImageAction );
} }
} }
@ -1748,6 +1753,29 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
saveResource( url, webview->url(), fileName ); saveResource( url, webview->url(), fileName );
} }
} }
else if ( result == openImageAction ) {
QUrl url = imageUrl;
QString fileName;
QString name = Utils::Url::path( url ).section( '/', -1 );
// Image data
// Check for babylon image name
if ( name[ 0 ] == '\x1E' )
name.remove( 0, 1 );
if ( name.length() && name[ name.length() - 1 ] == '\x1F' )
name.chop( 1 );
fileName = QString::number( QRandomGenerator::global()->generate() ) + name;
if ( !fileName.isEmpty() ) {
QFileInfo fileInfo( fileName );
saveResource( url, webview->url(), fileName );
QDesktopServices::openUrl( fileName );
}
}
else { else {
if ( !popupView && result == maxDictionaryRefsAction ) if ( !popupView && result == maxDictionaryRefsAction )
emit showDictsPane(); emit showDictsPane();