2023-08-16 09:57:32 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
|
2023-10-03 18:40:20 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2024-07-30 15:33:30 +00:00
|
|
|
import StatusQ.Components 0.1
|
2023-08-16 09:57:32 +00:00
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
|
|
|
|
import shared.controls 1.0
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property string firstTabName: qsTr("Scan QR code")
|
|
|
|
property string secondTabName: qsTr("Enter sync code")
|
2023-08-21 10:58:21 +00:00
|
|
|
property string firstInstructionButtonName: qsTr("How to get a sync code")
|
|
|
|
property string secondInstructionButtonName: qsTr("How to get a sync code")
|
2023-08-16 09:57:32 +00:00
|
|
|
property string syncQrErrorMessage: qsTr("This does not look like a sync QR code")
|
|
|
|
property string syncCodeErrorMessage: qsTr("This does not look like a sync code")
|
2023-08-21 10:58:21 +00:00
|
|
|
property string syncCodeLabel: qsTr("Paste sync code")
|
2023-08-16 09:57:32 +00:00
|
|
|
|
2023-10-03 18:40:20 +00:00
|
|
|
property var validateConnectionString: function(stringValue) { return true }
|
2023-08-16 09:57:32 +00:00
|
|
|
|
2023-08-21 10:58:21 +00:00
|
|
|
readonly property bool syncViaQr: !switchTabBar.currentIndex
|
|
|
|
|
2023-08-16 09:57:32 +00:00
|
|
|
signal displayInstructions()
|
|
|
|
signal proceed(string connectionString)
|
|
|
|
|
2023-10-03 18:40:20 +00:00
|
|
|
spacing: 8
|
2023-08-16 09:57:32 +00:00
|
|
|
|
|
|
|
StatusSwitchTabBar {
|
|
|
|
id: switchTabBar
|
2023-08-21 10:58:21 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.rightMargin: 16
|
2023-08-16 09:57:32 +00:00
|
|
|
currentIndex: 0
|
|
|
|
|
|
|
|
StatusSwitchTabButton {
|
|
|
|
text: root.firstTabName
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusSwitchTabButton {
|
|
|
|
text: root.secondTabName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-30 15:33:30 +00:00
|
|
|
StatusBetaTag {
|
|
|
|
anchors.left: switchTabBar.right
|
|
|
|
anchors.leftMargin: 8
|
|
|
|
anchors.verticalCenter: switchTabBar.verticalCenter
|
|
|
|
}
|
|
|
|
|
2023-08-16 09:57:32 +00:00
|
|
|
StackLayout {
|
|
|
|
Layout.fillWidth: true
|
2023-08-21 10:58:21 +00:00
|
|
|
Layout.preferredHeight: Math.max(syncQr.implicitHeight, syncCode.implicitHeight)
|
2023-10-03 18:40:20 +00:00
|
|
|
Layout.topMargin: 24
|
2023-08-16 09:57:32 +00:00
|
|
|
currentIndex: switchTabBar.currentIndex
|
|
|
|
|
|
|
|
// StackLayout doesn't support alignment, so we create an `Item` wrappers
|
|
|
|
|
|
|
|
Item {
|
|
|
|
StatusSyncCodeScan {
|
2023-08-21 10:58:21 +00:00
|
|
|
id: syncQr
|
2023-08-16 09:57:32 +00:00
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
}
|
|
|
|
validators: [
|
|
|
|
StatusValidator {
|
|
|
|
name: "isSyncQrCode"
|
|
|
|
errorMessage: root.syncQrErrorMessage
|
|
|
|
validate: root.validateConnectionString
|
|
|
|
}
|
|
|
|
]
|
|
|
|
onConnectionStringFound: {
|
|
|
|
root.proceed(connectionString)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-03 18:40:20 +00:00
|
|
|
ColumnLayout {
|
|
|
|
spacing: 20
|
2023-08-16 09:57:32 +00:00
|
|
|
StatusSyncCodeInput {
|
2023-08-21 10:58:21 +00:00
|
|
|
id: syncCode
|
2023-10-03 18:40:20 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.preferredWidth: 424
|
2023-08-21 10:58:21 +00:00
|
|
|
|
|
|
|
mode: StatusSyncCodeInput.Mode.WriteMode
|
2023-10-03 18:40:20 +00:00
|
|
|
label: root.syncCodeLabel
|
2023-08-21 10:58:21 +00:00
|
|
|
input.placeholderText: qsTr("eg. %1").arg("0x2Ef19")
|
|
|
|
|
2023-08-16 09:57:32 +00:00
|
|
|
validators: [
|
|
|
|
StatusValidator {
|
|
|
|
name: "isSyncCode"
|
|
|
|
errorMessage: root.syncCodeErrorMessage
|
|
|
|
validate: root.validateConnectionString
|
|
|
|
}
|
|
|
|
]
|
|
|
|
input.onValidChanged: {
|
|
|
|
if (!input.valid)
|
|
|
|
return
|
2023-08-21 10:58:21 +00:00
|
|
|
root.proceed(syncCode.text)
|
2023-08-16 09:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-03 18:40:20 +00:00
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
|
|
|
text: qsTr("Ensure both devices are on the same network")
|
|
|
|
}
|
2023-08-16 09:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusFlatButton {
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2023-08-21 10:58:21 +00:00
|
|
|
visible: switchTabBar.currentIndex == 0 && !!root.firstInstructionButtonName ||
|
|
|
|
switchTabBar.currentIndex == 1 && !!root.secondInstructionButtonName
|
|
|
|
text: switchTabBar.currentIndex == 0?
|
|
|
|
root.firstInstructionButtonName :
|
|
|
|
root.secondInstructionButtonName
|
2023-08-16 09:57:32 +00:00
|
|
|
onClicked: {
|
|
|
|
root.displayInstructions()
|
|
|
|
}
|
|
|
|
}
|
2023-08-21 10:58:21 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
2023-08-16 09:57:32 +00:00
|
|
|
}
|