From 6bab731c5f60b7383ddd1640611bf01016d66744 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Tue, 29 Mar 2022 10:03:05 +0200 Subject: [PATCH] QML: Add clipboard example Signed-off-by: Juraj Oravec --- qml/articles/6.Using_clipboard.md | 20 +++++++++ qml/extensions/qml_tutorial_6/main.qml | 44 +++++++++++++++++++ .../qml_tutorial_6/metadata.desktop | 11 +++++ 3 files changed, 75 insertions(+) create mode 100644 qml/articles/6.Using_clipboard.md create mode 100644 qml/extensions/qml_tutorial_6/main.qml create mode 100644 qml/extensions/qml_tutorial_6/metadata.desktop diff --git a/qml/articles/6.Using_clipboard.md b/qml/articles/6.Using_clipboard.md new file mode 100644 index 0000000..454c3dc --- /dev/null +++ b/qml/articles/6.Using_clipboard.md @@ -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) + diff --git a/qml/extensions/qml_tutorial_6/main.qml b/qml/extensions/qml_tutorial_6/main.qml new file mode 100644 index 0000000..b1d1941 --- /dev/null +++ b/qml/extensions/qml_tutorial_6/main.qml @@ -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)) + }) + } + } + +} diff --git a/qml/extensions/qml_tutorial_6/metadata.desktop b/qml/extensions/qml_tutorial_6/metadata.desktop new file mode 100644 index 0000000..be1ee14 --- /dev/null +++ b/qml/extensions/qml_tutorial_6/metadata.desktop @@ -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