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:
parent
2e1e0c77ee
commit
37820520df
@ -17,11 +17,14 @@
|
|||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlmenu.h"
|
#include "qmlmenu.h"
|
||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
QmlMenu::QmlMenu(QMenu *menu, QObject *parent)
|
QmlMenu::QmlMenu(QMenu *menu, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_menu(menu)
|
, m_menu(menu)
|
||||||
{
|
{
|
||||||
|
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
|
||||||
|
|
||||||
connect(m_menu, &QMenu::triggered, this, &QmlMenu::triggered);
|
connect(m_menu, &QMenu::triggered, this, &QmlMenu::triggered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlwebhittestresult.h"
|
#include "qmlwebhittestresult.h"
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
#define NOT !
|
#define NOT !
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ QmlWebHitTestResult::QmlWebHitTestResult(const WebHitTestResult &webHitTestResul
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_webHitTestResult(webHitTestResult)
|
, m_webHitTestResult(webHitTestResult)
|
||||||
{
|
{
|
||||||
|
QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,9 +117,6 @@ void QmlPluginInterface::populateWebViewMenu(QMenu *menu, WebView *webview, cons
|
|||||||
args.append(m_engine->newQObject(qmlWebHitTestResult));
|
args.append(m_engine->newQObject(qmlWebHitTestResult));
|
||||||
m_populateWebViewMenu.call(args);
|
m_populateWebViewMenu.call(args);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
qmlMenu->deleteLater();
|
|
||||||
qmlWebHitTestResult->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlPluginInterface::showSettings(QWidget *parent)
|
void QmlPluginInterface::showSettings(QWidget *parent)
|
||||||
@ -139,6 +136,7 @@ void QmlPluginInterface::showSettings(QWidget *parent)
|
|||||||
QDialog *dialog = new QDialog(parent);
|
QDialog *dialog = new QDialog(parent);
|
||||||
QVBoxLayout *boxLayout = new QVBoxLayout;
|
QVBoxLayout *boxLayout = new QVBoxLayout;
|
||||||
boxLayout->addWidget(widget);
|
boxLayout->addWidget(widget);
|
||||||
|
boxLayout->setContentsMargins(0 ,0 ,0 ,0);
|
||||||
dialog->setLayout(boxLayout);
|
dialog->setLayout(boxLayout);
|
||||||
dialog->setFixedSize(window->size());
|
dialog->setFixedSize(window->size());
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
@ -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!'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,5 +6,5 @@ Type=Service
|
|||||||
X-Falkon-Author=Anmol Gautam
|
X-Falkon-Author=Anmol Gautam
|
||||||
X-Falkon-Email=tarptaeya@gmail.com
|
X-Falkon-Email=tarptaeya@gmail.com
|
||||||
X-Falkon-Version=0.1.0
|
X-Falkon-Version=0.1.0
|
||||||
X-Falkon-Settings=false
|
X-Falkon-Settings=true
|
||||||
X-Falkon-EntryPoint=helloqml.qml
|
X-Falkon-EntryPoint=helloqml.qml
|
||||||
|
Loading…
Reference in New Issue
Block a user