diff --git a/src/lib/plugins/qml/api/menus/qmlmenu.cpp b/src/lib/plugins/qml/api/menus/qmlmenu.cpp index e5d3c030a..b1d1bef2c 100644 --- a/src/lib/plugins/qml/api/menus/qmlmenu.cpp +++ b/src/lib/plugins/qml/api/menus/qmlmenu.cpp @@ -17,11 +17,14 @@ * ============================================================ */ #include "qmlmenu.h" #include "qztools.h" +#include QmlMenu::QmlMenu(QMenu *menu, QObject *parent) : QObject(parent) , m_menu(menu) { + QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); + connect(m_menu, &QMenu::triggered, this, &QmlMenu::triggered); } diff --git a/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp b/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp index 8f319b330..54a01cccd 100644 --- a/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp +++ b/src/lib/plugins/qml/api/menus/qmlwebhittestresult.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . * ============================================================ */ #include "qmlwebhittestresult.h" +#include #define NOT ! @@ -23,6 +24,7 @@ QmlWebHitTestResult::QmlWebHitTestResult(const WebHitTestResult &webHitTestResul : QObject(parent) , m_webHitTestResult(webHitTestResult) { + QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } /** diff --git a/src/lib/plugins/qml/qmlplugininterface.cpp b/src/lib/plugins/qml/qmlplugininterface.cpp index fd2b1d44a..7bd6715ce 100644 --- a/src/lib/plugins/qml/qmlplugininterface.cpp +++ b/src/lib/plugins/qml/qmlplugininterface.cpp @@ -117,9 +117,6 @@ void QmlPluginInterface::populateWebViewMenu(QMenu *menu, WebView *webview, cons args.append(m_engine->newQObject(qmlWebHitTestResult)); m_populateWebViewMenu.call(args); menu->addSeparator(); - - qmlMenu->deleteLater(); - qmlWebHitTestResult->deleteLater(); } void QmlPluginInterface::showSettings(QWidget *parent) @@ -139,6 +136,7 @@ void QmlPluginInterface::showSettings(QWidget *parent) QDialog *dialog = new QDialog(parent); QVBoxLayout *boxLayout = new QVBoxLayout; boxLayout->addWidget(widget); + boxLayout->setContentsMargins(0 ,0 ,0 ,0); dialog->setLayout(boxLayout); dialog->setFixedSize(window->size()); dialog->exec(); diff --git a/src/scripts/helloqml/helloqml.qml b/src/scripts/helloqml/helloqml.qml index 5689a1df1..89981b7c2 100644 --- a/src/scripts/helloqml/helloqml.qml +++ b/src/scripts/helloqml/helloqml.qml @@ -79,4 +79,81 @@ Falkon.PluginInterface { } } } + + populateWebViewMenu: function(menu, webHitTestResult) { + var text = 'My first qml plugin action' + var action = menu.addAction({ + text: text, + icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg') + }) + + if (webHitTestResult.isImage()) { + action.update({ + text: text + " on image" + }) + } else if (webHitTestResult.isLink()) { + action.update({ + text: text + " on link" + }) + } else if (webHitTestResult.isContentEditable()) { + action.update({ + text: text + " on input" + }) + } + + action.triggered.connect(function() { + Falkon.Notifications.create({ + heading: 'Hello QML', + message: 'First qml plugin action works :-)', + icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg') + }) + }) + } + + Falkon.Settings { + id: settings + name: 'HelloQML' + } + + settingsWindow: Window { + id: window + width: 256 + height: 200 + Image { + id: image + source: Qt.resolvedUrl('qrc:/icons/other/about.svg') + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + } + TextField { + id: textField + text: settings.value({key: 'text'}) + placeholderText: 'Enter text to save' + width: 256 + height: 50 + anchors.top: image.bottom + onTextChanged: function() { + button.text = 'Save' + } + } + Button { + id: button + text: 'Save' + width: 256 + height: 50 + anchors.top: textField.bottom + onClicked: function() { + var res = settings.setValue({ + key: 'text', + value: textField.text + }) + if (res) { + button.text = 'Saved!' + } else { + button.text = 'Error occurred, try again!' + } + } + } + } } \ No newline at end of file diff --git a/src/scripts/helloqml/metadata.desktop b/src/scripts/helloqml/metadata.desktop index b4db887b0..19d00045e 100644 --- a/src/scripts/helloqml/metadata.desktop +++ b/src/scripts/helloqml/metadata.desktop @@ -6,5 +6,5 @@ Type=Service X-Falkon-Author=Anmol Gautam X-Falkon-Email=tarptaeya@gmail.com X-Falkon-Version=0.1.0 -X-Falkon-Settings=false +X-Falkon-Settings=true X-Falkon-EntryPoint=helloqml.qml