mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
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:
parent
b6420c87f7
commit
64f69d2235
|
@ -30,6 +30,7 @@
|
|||
#include <QWebEngineSettings>
|
||||
#include <map>
|
||||
#include <QApplication>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) && QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
#include <QWebEngineContextMenuData>
|
||||
|
@ -1493,6 +1494,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
|
|||
QAction * addHeaderToHistoryAction = nullptr;
|
||||
QAction * sendWordToInputLineAction = nullptr;
|
||||
QAction * saveImageAction = nullptr;
|
||||
QAction * openImageAction = nullptr;
|
||||
QAction * saveSoundAction = nullptr;
|
||||
QAction * saveBookmark = nullptr;
|
||||
|
||||
|
@ -1536,6 +1538,9 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
|
|||
menu.addAction( webview->pageAction( QWebEnginePage::CopyImageToClipboard ) );
|
||||
saveImageAction = new QAction( tr( "Save &image..." ), &menu );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
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 {
|
||||
if ( !popupView && result == maxDictionaryRefsAction )
|
||||
emit showDictsPane();
|
||||
|
|
Loading…
Reference in a new issue