diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index 90a6f7b0..b9655661 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -2,3 +2,9 @@ add_subdirectory( cli_wallet ) add_subdirectory( witness_node ) add_subdirectory( js_operation_serializer ) add_subdirectory( size_checker ) + + +set(BUILD_QT_GUI FALSE CACHE BOOL "Build the Qt-based light client GUI") +if(BUILD_QT_GUI) + add_subdirectory(light_client) +endif() diff --git a/programs/light_client/CMakeLists.txt b/programs/light_client/CMakeLists.txt new file mode 100644 index 00000000..66236369 --- /dev/null +++ b/programs/light_client/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.11) + +project(light_client) + +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) +# Instruct CMake to run rcc automatically when needed. +set(CMAKE_AUTORCC ON) + +find_package(Qt5Core) +find_package(Qt5Widgets) +find_package(Qt5Quick) + +file(GLOB QML qml/*) +add_executable(light_client ClientDataModel.cpp ClientDataModel.hpp main.cpp ${QML}) + +target_link_libraries(light_client PRIVATE Qt5::Core Qt5::Widgets Qt5::Quick graphene_chain graphene_utilities fc) diff --git a/programs/light_client/ClientDataModel.cpp b/programs/light_client/ClientDataModel.cpp new file mode 100644 index 00000000..4338cebf --- /dev/null +++ b/programs/light_client/ClientDataModel.cpp @@ -0,0 +1,23 @@ +#include "ClientDataModel.hpp" + + +Account* ClientDataModel::getAccount(quint64 id) const +{ + auto acct = new Account; + acct->setProperty("id", id); + acct->setProperty("name", "joe"); + return acct; +} + +Account*ClientDataModel::getAccount(QString name) const +{ + auto acct = new Account; + acct->setProperty("id", 800); + acct->setProperty("name", name); + return acct; +} + +QQmlListProperty Account::balances() +{ + return QQmlListProperty(this, m_balances); +} diff --git a/programs/light_client/ClientDataModel.hpp b/programs/light_client/ClientDataModel.hpp new file mode 100644 index 00000000..1986293f --- /dev/null +++ b/programs/light_client/ClientDataModel.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include +#include + +class Asset : public QObject { + Q_OBJECT + + Q_PROPERTY(QString symbol MEMBER symbol) + Q_PROPERTY(quint64 id MEMBER id) + Q_PROPERTY(quint8 precision MEMBER precision) + + QString symbol; + quint64 id; + quint8 precision; +}; + +class Balance : public QObject { + Q_OBJECT + + Q_PROPERTY(Asset* type MEMBER type) + Q_PROPERTY(qint64 amount MEMBER amount) + Q_PROPERTY(quint64 id MEMBER id) + + Asset* type; + qint64 amount; + quint64 id; +}; + +class Account : public QObject { + Q_OBJECT + + Q_PROPERTY(QString name MEMBER name) + Q_PROPERTY(quint64 id MEMBER id) + Q_PROPERTY(QQmlListProperty balances READ balances) + + QString name; + quint64 id; + QList m_balances; + +public: + Account(QObject* parent = nullptr) + : QObject(parent){} + + QQmlListProperty balances(); +}; + +class ClientDataModel : public QObject { + Q_OBJECT + +public: + Q_INVOKABLE Account* getAccount(quint64 id)const; + Q_INVOKABLE Account* getAccount(QString name)const; +}; diff --git a/programs/light_client/main.cpp b/programs/light_client/main.cpp new file mode 100644 index 00000000..57ee4b1f --- /dev/null +++ b/programs/light_client/main.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +#include "ClientDataModel.hpp" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + qmlRegisterType("Graphene.Client", 0, 1, "Asset"); + qmlRegisterType("Graphene.Client", 0, 1, "Balance"); + qmlRegisterType("Graphene.Client", 0, 1, "Account"); + qmlRegisterType("Graphene.Client", 0, 1, "DataModel"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} + diff --git a/programs/light_client/qml/MainForm.qml b/programs/light_client/qml/MainForm.qml new file mode 100644 index 00000000..04c2d926 --- /dev/null +++ b/programs/light_client/qml/MainForm.qml @@ -0,0 +1,45 @@ +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.2 + +Item { + id: item1 + width: 640 + height: 480 + + property alias button1: button1 + property alias button2: button2 + + ColumnLayout { + id: columnLayout1 + width: parent.width / 2 + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + + RowLayout { + id: buttonRow + Layout.fillWidth: true + + Button { + id: button1 + text: qsTr("Press Me 1") + } + Item { Layout.fillWidth: true } + Button { + id: button2 + text: qsTr("Press Me 2") + } + } + + Slider { + id: slider + Layout.fillWidth: true + } + ProgressBar { + id: progressBar1 + value: Math.sin(Math.PI * slider.value) + Layout.fillWidth: true + } + } +} + diff --git a/programs/light_client/qml/main.qml b/programs/light_client/qml/main.qml new file mode 100644 index 00000000..49202020 --- /dev/null +++ b/programs/light_client/qml/main.qml @@ -0,0 +1,51 @@ +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import QtQuick.Dialogs 1.2 + +import Graphene.Client 0.1 + +ApplicationWindow { + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") + + menuBar: MenuBar { + Menu { + title: qsTr("File") + MenuItem { + text: qsTr("&Open") + onTriggered: console.log("Open action triggered"); + } + MenuItem { + text: qsTr("Exit") + onTriggered: Qt.quit(); + } + } + } + + DataModel { + id: model + objectName: "model" + } + + MainForm { + id: form + anchors.fill: parent + button1.onClicked: { + console.log(JSON.stringify(model.getAccount(3))) + messageDialog.show(qsTr("Account name is %1").arg(model.getAccount(3).name)) + } + button2.onClicked: messageDialog.show(qsTr("Account name is %1").arg(model.getAccount("steve").name)) + } + + MessageDialog { + id: messageDialog + title: qsTr("May I have your attention, please?") + + function show(caption) { + messageDialog.text = caption; + messageDialog.open(); + } + } +} diff --git a/programs/light_client/qml/qml.qrc b/programs/light_client/qml/qml.qrc new file mode 100644 index 00000000..a9442bbc --- /dev/null +++ b/programs/light_client/qml/qml.qrc @@ -0,0 +1,7 @@ + + + main.qml + MainForm.qml + + +