QML: Add clipboard example
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
19c7e4ed1e
commit
6bab731c5f
20
qml/articles/6.Using_clipboard.md
Normal file
20
qml/articles/6.Using_clipboard.md
Normal 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)
|
||||
|
44
qml/extensions/qml_tutorial_6/main.qml
Normal file
44
qml/extensions/qml_tutorial_6/main.qml
Normal 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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
qml/extensions/qml_tutorial_6/metadata.desktop
Normal file
11
qml/extensions/qml_tutorial_6/metadata.desktop
Normal 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
|
Loading…
Reference in New Issue
Block a user