Add simple demo GUI
This commit is contained in:
parent
e8d2b45d67
commit
81dd83226b
8 changed files with 226 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
|
|||
19
programs/light_client/CMakeLists.txt
Normal file
19
programs/light_client/CMakeLists.txt
Normal file
|
|
@ -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)
|
||||
23
programs/light_client/ClientDataModel.cpp
Normal file
23
programs/light_client/ClientDataModel.cpp
Normal file
|
|
@ -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<Balance> Account::balances()
|
||||
{
|
||||
return QQmlListProperty<Balance>(this, m_balances);
|
||||
}
|
||||
54
programs/light_client/ClientDataModel.hpp
Normal file
54
programs/light_client/ClientDataModel.hpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlListProperty>
|
||||
|
||||
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<Balance> balances READ balances)
|
||||
|
||||
QString name;
|
||||
quint64 id;
|
||||
QList<Balance*> m_balances;
|
||||
|
||||
public:
|
||||
Account(QObject* parent = nullptr)
|
||||
: QObject(parent){}
|
||||
|
||||
QQmlListProperty<Balance> balances();
|
||||
};
|
||||
|
||||
class ClientDataModel : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Q_INVOKABLE Account* getAccount(quint64 id)const;
|
||||
Q_INVOKABLE Account* getAccount(QString name)const;
|
||||
};
|
||||
21
programs/light_client/main.cpp
Normal file
21
programs/light_client/main.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include <QApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QtQml>
|
||||
|
||||
#include "ClientDataModel.hpp"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
qmlRegisterType<Asset>("Graphene.Client", 0, 1, "Asset");
|
||||
qmlRegisterType<Balance>("Graphene.Client", 0, 1, "Balance");
|
||||
qmlRegisterType<Account>("Graphene.Client", 0, 1, "Account");
|
||||
qmlRegisterType<ClientDataModel>("Graphene.Client", 0, 1, "DataModel");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
45
programs/light_client/qml/MainForm.qml
Normal file
45
programs/light_client/qml/MainForm.qml
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
51
programs/light_client/qml/main.qml
Normal file
51
programs/light_client/qml/main.qml
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
programs/light_client/qml/qml.qrc
Normal file
7
programs/light_client/qml/qml.qrc
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.qml</file>
|
||||
<file>MainForm.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Loading…
Reference in a new issue