Falkon Develop
Cross-platform Qt-based web browser
main.qml
Go to the documentation of this file.
1import org.kde.falkon 1.0 as Falkon
2import QtQuick.Controls 2.3
3import QtQuick 2.3
5Falkon.PluginInterface {
6
7 QtObject {
8 id: helloQmlObject
9 property int clickCount: 0
10 signal clicked(int count)
11 }
12
13 Falkon.UserScript {
14 id: testingHelloQmlUserScript
15 name: 'testing-hello-qml'
16 runsOnSubFrames: false
17 sourceCode: Falkon.FileUtils.readAllFileContents('script.js')
18 injectionPoint: Falkon.UserScript.DocumentReady
19 worldId: Falkon.UserScript.ApplicationWorld
20 }
21
22 init: function(state, settingsPath){
23 console.log(i18n('"Hello QML" plugin loaded'))
24 Falkon.ExternalJsObject.registerExtraObject({
25 id: 'helloQmlObject',
26 object: helloQmlObject
27 })
28 }
29
30 testPlugin: function() {
31 return true
32 }
33
34 unload: function() {
35 console.log(i18n('Bye!'))
36 }
37
38 // Point falkon to extension://helloqml to see Hello World
39 Falkon.ExtensionScheme {
40 name: 'helloqml'
41 onRequestStarted: {
42 request.reply({
43 contentType: 'text/html',
44 content: '<h1>Hello World</h1>'
45 })
46 }
47 }
48
49 Falkon.BrowserAction {
50 name: 'helloqml-button'
51 identity: 'helloqml-id'
52 title: i18n('Testing QML Title')
53 toolTip: i18n('Testing QML Tooltip')
54 icon: 'extensions.svg'
55 location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
56 popup: Rectangle {
57 property var borderMargin: 1
58 property var imageWidth: 256
59 property var imageHeight: 200
60 property var buttonHeight: 40
61
62 width: imageWidth + 2 * borderMargin
63 height: imageHeight + buttonHeight + 2 * borderMargin
64 color: 'black'
65 Rectangle {
66 anchors.fill: parent
67 anchors.leftMargin: borderMargin
68 anchors.rightMargin: borderMargin
69 anchors.topMargin: borderMargin
70 anchors.bottomMargin: borderMargin
71 color: 'white'
72 Image {
73 id: image
74 source: 'qrc:/icons/other/startpage.svg'
75 anchors.left: parent.left
76 anchors.right: parent.right
77 anchors.top: parent.top
78 }
79
80 Button {
81 text: i18n('Click Me!')
82 height: buttonHeight
83 anchors.top: image.bottom
84 anchors.left: parent.left
85 anchors.right: parent.right
86 onClicked: {
87 helloQmlObject.clickCount += 1
88 helloQmlObject.clicked(helloQmlObject.clickCount)
89 }
90 }
91 }
92 }
93 }
94
95 Falkon.SideBar {
96 name: 'helloqml-sidebar'
97 title: i18n('Testing QML SideBar')
98 icon: 'extensions.svg'
99 checkable: true
100 Rectangle {
101 Image {
102 source: 'qrc:/icons/other/startpage.svg'
103 anchors.verticalCenter: parent.verticalCenter
104 anchors.left: parent.left
105 anchors.right: parent.right
106 }
107
108 Button {
109 text: i18n('Hello Qml Plugin')
110 anchors.left: parent.left
111 anchors.right: parent.right
112 anchors.bottom: parent.bottom
113 }
114 }
115 }
116
117 populateWebViewMenu: function(menu, webHitTestResult) {
118 var text = 'My first qml plugin action'
119 var action = menu.addAction({
120 text: text,
121 icon: 'extensions.svg'
122 })
123
124 action.triggered.connect(function() {
125 Falkon.Notifications.create({
126 heading: i18n('Hello QML'),
127 message: i18n('First qml plugin action works :-)'),
128 icon: 'extensions.svg'
129 })
130 })
131 }
132
133 Falkon.Settings {
134 id: settings
135 name: 'HelloQML'
136 }
137
138 settingsWindow: Rectangle {
139 id: window
140 width: 256
141 height: 200
142 Image {
143 id: image
144 source: 'qrc:/icons/other/about.svg'
145 anchors.top: parent.top
146 anchors.left: parent.left
147 anchors.right: parent.right
148 }
149 TextField {
150 id: textField
151 text: settings.value({key: 'text'})
152 placeholderText: i18n('Enter text to save')
153 width: 256
154 height: 50
155 anchors.top: image.bottom
156 onTextChanged: function() {
157 button.text = i18n('Save')
158 }
159 }
160 Button {
161 id: button
162 text: i18n('Save')
163 width: 256
164 height: 50
165 anchors.top: textField.bottom
166 onClicked: function() {
167 var res = settings.setValue({
168 key: 'text',
169 value: textField.text
170 })
171 if (res) {
172 button.text = i18n('Saved!')
173 } else {
174 button.text = i18n('Error occurred, try again!')
175 }
176 }
177 }
178 }
179}
int value(const QColor &c)
Definition: colors.cpp:238
i18n
Definition: i18n.py:28
State state