1
FalkonTutorials/qml/extensions/qml_tutorial_4/main.qml
Juraj Oravec 7ee07ad363
Style and naming correction
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2022-03-29 22:41:19 +02:00

104 lines
3.1 KiB
QML

import org.kde.falkon 1.0 as Falkon
import QtQuick 2.3
Falkon.PluginInterface {
QtObject {
id: tutorial4Object
property int clickCount
}
init: function(state, settingsPath) {
console.log(i18n('"Tutorial4" plugin loaded'))
tutorial4Object.clickCount = 0;
}
testPlugin: function() {
return true
}
unload: function() {
console.log(i18n('"Tutorial4" plugin unloaded'))
}
function buttonClicked() {
tutorial4Object.clickCount++;
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial4Object.clickCount))
}
Falkon.BrowserAction {
name: 'QML Tutorial 4'
identity: 'qml-tutorial-4-id'
title: i18n('Qml Tutorial 4')
toolTip: i18n('My little button')
icon: 'falkon'
badgeText: tutorial4Object.clickCount
location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
popup: Rectangle {
width: 100;
height: 100;
}
}
populateWebViewMenu: function(menu, webHitTestResult) {
/* Directly add actions to the menu */
var action_always = menu.addAction({
text: 'Increment counter by one',
icon: 'falkon'
})
action_always.triggered.connect(function() {
tutorial4Object.clickCount++;
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial4Object.clickCount))
})
if (webHitTestResult.isImage()) {
var action_image = menu.addAction({
text: 'Image, increment by two',
icon: 'falkon'
})
action_image.triggered.connect(function() {
tutorial4Object.clickCount += 2;
console.log(i18n('"Tutorial4" Surprise, this is an image with url: ' + webHitTestResult.imageUrl))
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial4Object.clickCount))
})
}
/* Add a separator between these 2 examples */
menu.addSeparator()
/* Create a submenu */
var subMenu = menu.addMenu({
title: 'Example submenu',
icon: 'falkon'
})
/* Copy the actions from before */
var sm_action_always = subMenu.addAction({
text: 'Increment counter by one',
icon: 'falkon'
})
sm_action_always.triggered.connect(function() {
tutorial4Object.clickCount++;
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial4Object.clickCount))
})
if (webHitTestResult.isImage()) {
var sm_action_image = subMenu.addAction({
text: 'Image, increment by two',
icon: 'falkon'
})
sm_action_image.triggered.connect(function() {
tutorial4Object.clickCount += 2;
console.log(i18n('"Tutorial4" Surprise, this is an image with url: ' + webHitTestResult.imageUrl))
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial4Object.clickCount))
})
}
}
}