Warning, /maui/fiery/src/views/browser/ActionsMenu.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.14
0002 import QtQml 2.12
0003 import QtQuick.Controls 2.13
0004 import QtQuick.Layouts 1.3
0005 
0006 import QtWebEngine 1.10
0007 import org.mauikit.controls 1.3 as Maui
0008 
0009 Maui.ContextualMenu
0010 {
0011     id: control
0012     property ContextMenuRequest request
0013     property WebEngineView webView
0014 
0015     property bool isValidUrl: request && request.linkUrl != "" // not strict equality
0016     property bool isAudio: request && request.mediaType === ContextMenuRequest.MediaTypeAudio
0017     property bool isImage: request && request.mediaType === ContextMenuRequest.MediaTypeImage
0018     property bool isVideo: request && request.mediaType === ContextMenuRequest.MediaTypeVideo
0019 
0020     Maui.MenuItemActionRow
0021     {
0022         Action
0023         {
0024             icon.name: "edit-undo"
0025             enabled:   request.editFlags & ContextMenuRequest.CanUndo
0026         }
0027 
0028         Action
0029         {
0030             icon.name: "edit-redo"
0031             enabled:   request.editFlags & ContextMenuRequest.CanRedo
0032         }
0033 
0034         Action
0035         {
0036             icon.name: "edit-cut"
0037             enabled:   request.editFlags & ContextMenuRequest.CanCut
0038         }
0039     }
0040 
0041     MenuItem
0042     {
0043         text: i18n("Paste")
0044         height: visible? implicitHeight : 00 - control.spacing
0045         visible:  request.editFlags & ContextMenuRequest.CanPaste
0046         onTriggered:
0047         {
0048             //            control.close()
0049             _webView.triggerWebAction(WebEngineView.Paste);
0050             //            pasteAction.trigger()
0051         }
0052     }
0053 
0054     MenuItem
0055     {
0056         text: i18n("Translate")
0057         height: visible? implicitHeight : 00 - control.spacing
0058         visible:  request.editFlags & ContextMenuRequest.CanTranslate
0059         onTriggered:
0060         {
0061             _webView.triggerWebAction(WebEngineView.Tran);
0062         }
0063     }
0064 
0065     MenuItem
0066     {
0067         text: i18n("Select All")
0068         height: visible? implicitHeight : 00 - control.spacing
0069         visible:  request.editFlags & ContextMenuRequest.CanSelectAll
0070         onTriggered:
0071         {
0072             webView.triggerWebAction(WebEngineView.SelectAll);
0073         }
0074     }
0075 
0076 
0077     MenuItem
0078     {
0079         text: i18n("Copy Text")
0080         height: visible? implicitHeight : 00 - control.spacing
0081         visible:  request.editFlags & ContextMenuRequest.CanCopy
0082         onTriggered:
0083         {
0084             Maui.Handy.copyTextToClipboard(control.request.selectedText)
0085         }
0086     }
0087 
0088     MenuItem
0089     {
0090         text: i18n("Copy Link")
0091         height: visible? implicitHeight : 00 - control.spacing
0092         visible: control.isValidUrl
0093         onTriggered:
0094         {
0095             Maui.Handy.copyTextToClipboard(control.request.linkUrl)
0096         }
0097     }
0098 
0099     MenuItem
0100     {
0101         text: i18n("Open Link")
0102         height: visible? implicitHeight : 00 - control.spacing
0103         visible: control.isValidUrl
0104         onTriggered:
0105         {
0106             openTab( control.request.linkUrl);
0107         }
0108     }
0109 
0110     MenuItem
0111     {
0112         text: i18n("Open Link in Split View")
0113         height: visible? implicitHeight : 00 - control.spacing
0114         visible: control.isValidUrl
0115         onTriggered:
0116         {
0117             openSplit( control.request.linkUrl);
0118         }
0119     }
0120 
0121     MenuItem
0122     {
0123         text: i18n("Open Link in New Window")
0124         height: visible? implicitHeight : 00 - control.spacing
0125         visible: control.isValidUrl
0126         onTriggered:
0127         {
0128             newWindow([control.request.linkUrl]);
0129         }
0130     }
0131 
0132 
0133     MenuItem
0134     {
0135         property string fullText: control.request ? control.request.selectedText || control.request.linkText : ""
0136         property string elidedText: fullText.length > 25 ? fullText.slice(0, 25) + "..." : fullText
0137         height: visible? implicitHeight : 00 - control.spacing
0138         visible: control.request && fullText
0139         text:  i18n('Search for "%1"', elidedText)
0140         onTriggered:
0141         {
0142 
0143             openTab(appSettings.searchEnginePage+ fullText);
0144 
0145         }
0146     }
0147 
0148     MenuItem
0149     {
0150         height: visible? implicitHeight : 0 - control.spacing
0151         visible: control.isVideo
0152         text: i18n("Save Video")
0153         onTriggered: webView.triggerWebAction(WebEngineView.DownloadMediaToDisk)
0154     }
0155 
0156     MenuItem
0157     {
0158         height: visible? implicitHeight : 00 - control.spacing
0159         visible: (control.isAudio || control.isVideo) && control.request.mediaUrl !== url
0160         text: control.isVideo ? i18n("Open Video") : i18n("Open Audio")
0161         onTriggered:
0162         {
0163             openTab(control.request.mediaUrl)
0164         }
0165     }
0166 
0167     MenuItem
0168     {
0169         height: visible? implicitHeight : 00 - control.spacing
0170         visible: control.isImage
0171         text: i18n("Save Image")
0172         onTriggered: webView.triggerWebAction(WebEngineView.DownloadImageToDisk)
0173     }
0174 
0175     MenuItem
0176     {
0177         height: visible? implicitHeight : 00 - control.spacing
0178         visible: control.isImage
0179         text: i18n("Copy Image")
0180         onTriggered: webView.triggerWebAction(WebEngineView.CopyImageToClipboard)
0181     }
0182 
0183     MenuItem
0184     {
0185         height: visible? implicitHeight : 00 - control.spacing
0186         visible: control.isImage && control.request.mediaUrl !== url
0187         text: i18n("Open Image")
0188         onTriggered:
0189         {
0190             openTab(control.request.mediaUrl)
0191         }
0192     }
0193 
0194     MenuItem
0195     {
0196         height: visible? implicitHeight : 00 - control.spacing
0197         visible: control.isAudio || control.isVideo
0198         text: control.request && control.request.mediaFlags & ContextMenuRequest.MediaPaused
0199               ? i18n("Play")
0200               : i18n("Pause")
0201         onTriggered: webView.triggerWebAction(WebEngineView.ToggleMediaPlayPause)
0202     }
0203 
0204     MenuItem
0205     {
0206         height: visible? implicitHeight : 00 - control.spacing
0207         visible: control.request && control.request.mediaFlags & ContextMenuRequest.MediaHasAudio
0208         text:  control.request && control.request.mediaFlags & ContextMenuRequest.MediaMuted
0209                ? i18n("Unmute")
0210                : i18n("Mute")
0211         onTriggered: webView.triggerWebAction(WebEngineView.ToggleMediaMute)
0212     }
0213 
0214     MenuItem
0215     {
0216         height: visible? implicitHeight : 00 - control.spacing
0217         visible: webView.settings.javascriptEnabled && (control.isAudio || control.isVideo)
0218         contentItem: RowLayout
0219         {
0220             Label
0221             {
0222                 Layout.fillWidth: true
0223                 text: i18n("Speed")
0224             }
0225 
0226             SpinBox
0227             {
0228                 value: control.playbackRate
0229                 from: 25
0230                 to: 1000
0231                 stepSize: 25
0232                 onValueModified: {
0233                     control.playbackRate = value
0234                     const point = control.request.x + ', ' + control.request.y
0235                     const js = 'document.elementFromPoint(' + point + ').playbackRate = ' + control.playbackRate / 100 + ';'
0236                     webView.runJavaScript(js)
0237                 }
0238                 textFromValue: function(value, locale) {
0239                     return Number(value / 100).toLocaleString(locale, 'f', 2)
0240                 }
0241             }
0242         }
0243     }
0244 
0245     MenuItem
0246     {
0247         height: visible? implicitHeight : 0 - control.spacing
0248         visible: control.isAudio || control.isVideo
0249         text: i18n("Loop")
0250         checked: control.request && control.request.mediaFlags & ContextMenuRequest.MediaLoop
0251         onTriggered: webView.triggerWebAction(WebEngineView.ToggleMediaLoop)
0252     }
0253 
0254     MenuItem
0255     {
0256         height: visible? implicitHeight : 0 - control.spacing
0257         visible: webView.settings.javascriptEnabled && control.isVideo
0258         text: webView.isFullScreen ? i18n("Exit fullscreen") : i18n("Fullscreen")
0259         onTriggered: {
0260             const point = control.request.x + ', ' + control.request.y
0261             const js = webView.isFullScreen
0262                      ? 'document.exitFullscreen()'
0263                      : 'document.elementFromPoint(' + point + ').requestFullscreen()'
0264             webView.runJavaScript(js)
0265         }
0266     }
0267 
0268     MenuItem
0269     {
0270         height: visible? implicitHeight : 0 - control.spacing
0271         visible: webView.settings.javascriptEnabled && (control.isAudio || control.isVideo)
0272         text: control.request && control.request.mediaFlags & ContextMenuRequest.MediaControls
0273               ? i18n("Hide controls")
0274               : i18n("Show controls")
0275         onTriggered: webView.triggerWebAction(WebEngineView.ToggleMediaControls)
0276     }
0277 
0278 }