First handshake with pica
This commit is contained in:
parent
4da9a275a9
commit
f547170728
12 changed files with 391 additions and 82 deletions
|
@ -6,6 +6,8 @@ qt_add_qml_module(megpieQml
|
|||
NO_PLUGIN
|
||||
QML_FILES
|
||||
main.qml
|
||||
ServerPick.qml
|
||||
Welcome.qml
|
||||
)
|
||||
|
||||
target_link_libraries(megpie PRIVATE megpieQml)
|
||||
|
|
138
qml/ServerPick.qml
Normal file
138
qml/ServerPick.qml
Normal file
|
@ -0,0 +1,138 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Page {
|
||||
property string address
|
||||
property bool valid
|
||||
|
||||
signal back()
|
||||
signal success(address: string)
|
||||
|
||||
title: qsTr("Chosing a server")
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: 10
|
||||
|
||||
Label {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
id: label
|
||||
text: qsTr("Type server address in the field below")
|
||||
}
|
||||
TextField {
|
||||
width: parent.width
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
id: input
|
||||
placeholderText: "https://example.org"
|
||||
text: address
|
||||
onAccepted: modal.check()
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: /^(?:http|https)?:\/\/(?:\w*\.)*(?:\w)+(?:\:\d+)?(?:(?:\/\w+)\/?)*$/
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
spacing: 10
|
||||
|
||||
Button {
|
||||
text: qsTr("Cancel")
|
||||
onClicked: back()
|
||||
}
|
||||
Button {
|
||||
text: qsTr("Confirm")
|
||||
enabled: input.acceptableInput
|
||||
onClicked: modal.check()
|
||||
}
|
||||
}
|
||||
|
||||
Popup {
|
||||
property bool inProgress: false
|
||||
|
||||
id: modal
|
||||
anchors.centerIn: parent
|
||||
modal: true
|
||||
focus: true
|
||||
width: column.width + 60
|
||||
height: column.height + 60
|
||||
closePolicy: Popup.CloseOnEscape
|
||||
onClosed: function () {
|
||||
modal.inProgress = false;
|
||||
if (valid)
|
||||
success(address);
|
||||
}
|
||||
|
||||
Column {
|
||||
id: column
|
||||
anchors.centerIn: parent
|
||||
spacing: 10
|
||||
Label {
|
||||
id: status
|
||||
width: 300
|
||||
wrapMode: Label.WordWrap
|
||||
horizontalAlignment: Label.AlignHCenter
|
||||
}
|
||||
BusyIndicator {
|
||||
id: indicator
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: modal.inProgress
|
||||
running: modal.inProgress
|
||||
}
|
||||
Button {
|
||||
id: button
|
||||
text: qsTr("Close")
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: !modal.inProgress
|
||||
onClicked: modal.close()
|
||||
focus: true
|
||||
Keys.onReturnPressed: {
|
||||
if (!modal.inProgress)
|
||||
modal.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enter: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 0.0
|
||||
to: 1.0
|
||||
duration: 200
|
||||
}
|
||||
}
|
||||
exit: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 1.0
|
||||
to: 0.0
|
||||
duration: 200
|
||||
}
|
||||
}
|
||||
|
||||
function check () {
|
||||
valid = false;
|
||||
modal.inProgress = true;
|
||||
status.text = qsTr("Checking") + " " + address + "...";
|
||||
modal.open()
|
||||
|
||||
API.test(input.text, function (err, success) {
|
||||
if (!modal.inProgress)
|
||||
return;
|
||||
|
||||
modal.inProgress = false;
|
||||
if (err)
|
||||
status.text = err;
|
||||
else
|
||||
status.text = qsTr("Success");
|
||||
|
||||
valid = !!success;
|
||||
if (valid) {
|
||||
address = input.text;
|
||||
modal.close()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
qml/Welcome.qml
Normal file
48
qml/Welcome.qml
Normal file
|
@ -0,0 +1,48 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Page {
|
||||
property string serverAddress
|
||||
|
||||
signal pickServer(address: string)
|
||||
|
||||
title: qsTr("Welcome")
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: 10
|
||||
|
||||
Label {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Welcome to Megpie!")
|
||||
font {
|
||||
pixelSize: 22
|
||||
bold: true
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
spacing: 5
|
||||
|
||||
Label {
|
||||
horizontalAlignment: Label.AlignRight
|
||||
text: qsTr("Current server:")
|
||||
}
|
||||
Label {
|
||||
horizontalAlignment: Label.AlignLeft
|
||||
text: serverAddress || qsTr("choose")
|
||||
font {
|
||||
italic: true
|
||||
underline: true
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: pickServer(serverAddress)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
66
qml/main.qml
66
qml/main.qml
|
@ -3,57 +3,43 @@ import QtQuick.Window
|
|||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Window {
|
||||
|
||||
|
||||
ApplicationWindow {
|
||||
property int counter: 0
|
||||
|
||||
id: window
|
||||
width: 640
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("Hello World")
|
||||
title: "Megpie"
|
||||
|
||||
Rectangle {
|
||||
id: page
|
||||
header: Label {
|
||||
text: stack.currentItem.title
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
StackView {
|
||||
id: stack
|
||||
initialItem: welcome
|
||||
anchors.fill: parent
|
||||
anchors.centerIn: parent
|
||||
color: increment.down ? "blue" : decrement.down ? "red" : "lightgrey"
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: 100
|
||||
target: page
|
||||
easing.type: Easing.InOutQuad
|
||||
}
|
||||
Welcome {
|
||||
id: welcome
|
||||
onPickServer: function (address) {
|
||||
pick.address = address;
|
||||
stack.push(pick)
|
||||
}
|
||||
}
|
||||
|
||||
GridLayout {
|
||||
anchors.centerIn: parent
|
||||
columns: 2
|
||||
|
||||
Text {
|
||||
Layout.columnSpan: 2
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: qsTr("Hello World")
|
||||
font.pointSize: 24; font.bold: true
|
||||
}
|
||||
|
||||
Button {
|
||||
id: increment
|
||||
text: "Increment"
|
||||
onClicked: window.counter++
|
||||
}
|
||||
|
||||
Button {
|
||||
id: decrement
|
||||
text: "Decrement"
|
||||
onClicked: window.counter--
|
||||
}
|
||||
|
||||
Text {
|
||||
Layout.columnSpan: 2
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: "The value is " + window.counter
|
||||
}
|
||||
ServerPick {
|
||||
visible: false
|
||||
id: pick
|
||||
onBack: stack.pop()
|
||||
onSuccess: function (address) {
|
||||
welcome.serverAddress = address;
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue