From 3dce09328e5656516c2ac90ec3c7a1398a220a84 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Thu, 1 Apr 2021 19:54:53 +0200 Subject: [PATCH] qml: Initial QML to test QObject property binding, ListModels, Camera --- electrum/gui/qml/components/EButton.qml | 41 +++++++++++++++++ electrum/gui/qml/components/landing.qml | 60 +++++++++++++++++++++++++ electrum/gui/qml/components/main.qml | 35 +++++++++++++++ electrum/gui/qml/components/scan.qml | 58 ++++++++++++++++++++++++ electrum/gui/qml/components/splash.qml | 14 ++++++ electrum/gui/qml/components/tx.qml | 39 ++++++++++++++++ 6 files changed, 247 insertions(+) create mode 100644 electrum/gui/qml/components/EButton.qml create mode 100644 electrum/gui/qml/components/landing.qml create mode 100644 electrum/gui/qml/components/main.qml create mode 100644 electrum/gui/qml/components/scan.qml create mode 100644 electrum/gui/qml/components/splash.qml create mode 100644 electrum/gui/qml/components/tx.qml diff --git a/electrum/gui/qml/components/EButton.qml b/electrum/gui/qml/components/EButton.qml new file mode 100644 index 000000000..87f7d459c --- /dev/null +++ b/electrum/gui/qml/components/EButton.qml @@ -0,0 +1,41 @@ +import QtQuick 2.6 + +Item { + id: rootItem + width: visbut.width + 10 + height: visbut.height + 10 + + signal clicked + property string text + + Rectangle { + id: visbut + border { + color: '#444444' + width: 2 + } + color: '#dddddd' + radius: 4 + + anchors.centerIn: parent + width: buttonText.width + height: buttonText.height + + MouseArea { + anchors.fill: parent + onClicked: rootItem.clicked() + } + } + + Text { + id: buttonText + leftPadding: 30 + rightPadding: 30 + topPadding: 20 + bottomPadding: 20 + verticalAlignment: Text.AlignVCenter + text: rootItem.text + color: 'red' + } + +} diff --git a/electrum/gui/qml/components/landing.qml b/electrum/gui/qml/components/landing.qml new file mode 100644 index 000000000..469799937 --- /dev/null +++ b/electrum/gui/qml/components/landing.qml @@ -0,0 +1,60 @@ +import QtQuick 2.6 +import QtQuick.Controls 1.4 +import QtQml 2.6 + +Item { + Column { + width: parent.width + + Row { + Text { text: "Server: " } + Text { text: Network.server } + } + Row { + Text { text: "Local Height: " } + Text { text: Network.height } + } + Row { + Text { text: "Status: " } + Text { text: Network.status } + } + Row { + Text { text: "Wallet: " } + Text { text: Daemon.walletName } + } + + EButton { + text: 'Scan QR Code' + onClicked: app.stack.push(Qt.resolvedUrl('scan.qml')) + } + + EButton { + text: 'Show TXen' + onClicked: app.stack.push(Qt.resolvedUrl('tx.qml')) + } + + ListView { + width: parent.width + height: 200 + model: Daemon.activeWallets + delegate: Item { + width: parent.width + + Row { + Rectangle { + width: 10 + height: parent.height + color: 'red' + } + Text { + leftPadding: 20 + text: model.display + } + } + } + } + + } + +} + diff --git a/electrum/gui/qml/components/main.qml b/electrum/gui/qml/components/main.qml new file mode 100644 index 000000000..233c671f3 --- /dev/null +++ b/electrum/gui/qml/components/main.qml @@ -0,0 +1,35 @@ +import QtQuick 2.6 +import QtQuick.Controls 1.4 +import QtQml 2.6 +import QtMultimedia 5.6 + +ApplicationWindow +{ + id: app + visible: true + width: 480 + height: 800 + color: '#dddddd' + + property alias stack: mainStackView + + StackView { + id: mainStackView + anchors.fill: parent + + initialItem: Qt.resolvedUrl('splash.qml') + } + + Timer { + id: splashTimer + interval: 400 + onTriggered: { + mainStackView.push(Qt.resolvedUrl('landing.qml')) + } + } + + Component.onCompleted: { + Daemon.load_wallet() + splashTimer.start() + } +} diff --git a/electrum/gui/qml/components/scan.qml b/electrum/gui/qml/components/scan.qml new file mode 100644 index 000000000..a13b04615 --- /dev/null +++ b/electrum/gui/qml/components/scan.qml @@ -0,0 +1,58 @@ +import QtQuick 2.6 +import QtMultimedia 5.6 + + +Item { + Column { + width: parent.width + + Item { + id: voc + width: parent.width + height: parent.width + + VideoOutput { + id: vo + anchors.fill: parent + source: camera + //fillMode: VideoOutput.PreserveAspectCrop + } + + MouseArea { + anchors.fill: parent + onClicked: { + vo.grabToImage(function(result) { + console.log("grab: image=" + (result.image !== undefined) + " url=" + result.url) + if (result.image !== undefined) { + console.log('scanning image for QR') + QR.scanImage(result.image) + } + }) + } + } + } + + EButton { + text: 'Exit' + onClicked: app.stack.pop() + } + } + + Camera { + id: camera + deviceId: QtMultimedia.defaultCamera.deviceId + viewfinder.resolution: "640x480" + + function dumpstats() { + console.log(camera.viewfinder.resolution) + console.log(camera.viewfinder.minimumFrameRate) + console.log(camera.viewfinder.maximumFrameRate) + var resolutions = camera.supportedViewfinderResolutions() + resolutions.forEach(function(item, i) { + console.log('' + item.width + 'x' + item.height) + }) + } + } + + +} diff --git a/electrum/gui/qml/components/splash.qml b/electrum/gui/qml/components/splash.qml new file mode 100644 index 000000000..cd882d712 --- /dev/null +++ b/electrum/gui/qml/components/splash.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Item { + Rectangle { + anchors.fill: parent + color: '#111111' + } + + Image { + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + source: "../../icons/electrum.png" + } +} diff --git a/electrum/gui/qml/components/tx.qml b/electrum/gui/qml/components/tx.qml new file mode 100644 index 000000000..116b18d25 --- /dev/null +++ b/electrum/gui/qml/components/tx.qml @@ -0,0 +1,39 @@ +import QtQuick 2.6 + +Item { + id: rootItem +// height: 800 + Column { + width: parent.width +// height: parent.height + + Text { + text: "Transactions" + } + + ListView { + width: parent.width + height: 200 +// anchors.bottom: rootItem.bottom + + model: Daemon.currentWallet.historyModel + delegate: Item { + width: parent.width + height: line.height + Row { + id: line + Rectangle { + width: 10 + height: parent.height + color: 'blue' + } + Text { + leftPadding: 20 + text: model.display + } + } + } + } + + } +}