1

QML: Add clipboard example

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-03-29 10:03:05 +02:00
parent 19c7e4ed1e
commit 6bab731c5f
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,20 @@
# Falkon QML Tutorial - 6. Using clipboard
Hello, in this chapter I will show you how to use Falkon clipboard. It
is only possible to copy data out of the extension into the clipboard.
## Use clipboard
```qml
Falkon.Clipboard.copy('Something from Falkon in the clipboard')
```
## Example
The example code will add a context menu which will add 2 entries. One
to copy something and other to copy image URL to the clipboard.
### Code
The code for this example can be found at
[extensions/qml_tutorial_6](../extensions/qml_tutorial_6)

View File

@ -0,0 +1,44 @@
import org.kde.falkon 1.0 as Falkon
import QtQuick 2.3
Falkon.PluginInterface {
init: function(state, settingsPath){
console.log(i18n('"Tutorial6" plugin loaded'))
tutorial3Object.clickCount = 0;
}
testPlugin: function() {
return true
}
unload: function() {
console.log(i18n('"Tutorial6" plugin unloaded'))
}
populateWebViewMenu: function(menu, webHitTestResult) {
/* Directly add actions to the menu */
var action_always = menu.addAction({
text: 'Copy something to the clipboard',
icon: 'falkon'
})
action_always.triggered.connect(function() {
Falkon.Clipboard.copy('Something from Falkon extension')
console.log(i18n('"Tutorial6" Something was copied to the clipboard'))
})
if (webHitTestResult.isImage()) {
var action_image = menu.addAction({
text: 'Image, copy URL',
icon: 'falkon'
})
action_image.triggered.connect(function() {
Falkon.Clipboard.copy(webHitTestResult.imageUrl)
console.log(i18n('"Tutorial6" Surprise, this is an image with url: ' + webHitTestResult.imageUrl))
})
}
}
}

View File

@ -0,0 +1,11 @@
[Desktop Entry]
Name=Tutorial6 QML
Comment=Example QML extension context menu and clipboard
Icon=
Type=Service
X-Falkon-Type=Extension/Qml
X-Falkon-Author=Juraj Oravec
X-Falkon-Email=jurajoravec@mailo.com
X-Falkon-Version=1.0.0
X-Falkon-Settings=false