1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Added more gui to HelloQml plugin & fix qmlmenu and webhittest deletion

This commit is contained in:
Anmol Gautam 2018-06-24 01:32:59 +05:30
parent 2e1e0c77ee
commit 37820520df
5 changed files with 84 additions and 4 deletions

View File

@ -17,11 +17,14 @@
* ============================================================ */
#include "qmlmenu.h"
#include "qztools.h"
#include <QQmlEngine>
QmlMenu::QmlMenu(QMenu *menu, QObject *parent)
: QObject(parent)
, m_menu(menu)
{
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
connect(m_menu, &QMenu::triggered, this, &QmlMenu::triggered);
}

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "qmlwebhittestresult.h"
#include <QQmlEngine>
#define NOT !
@ -23,6 +24,7 @@ QmlWebHitTestResult::QmlWebHitTestResult(const WebHitTestResult &webHitTestResul
: QObject(parent)
, m_webHitTestResult(webHitTestResult)
{
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
}
/**

View File

@ -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();

View File

@ -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!'
}
}
}
}
}

View File

@ -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