aboutsummaryrefslogtreecommitdiff
path: root/wizard/SeedListItem.qml
blob: 4905211a2b90e3fbb5b825ddd2096b309a665dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import "../components" as MonzeroComponents;
import QtQuick 2.9
import QtQuick.Layouts 1.2
import FontAwesome 1.0

ColumnLayout {
    id: seedListItem
    property var wordNumber;
    property var word;
    property var wordSpelled: (word.split("")).join(". ")
    property var acessibleText: (wordNumber + 1) + word
    property alias wordText: wordText
    property alias lineEdit: lineEdit
    property alias icon: icon
    spacing: 0

    Layout.preferredWidth: 136
    Layout.maximumWidth: 136
    Layout.minimumWidth: 136

    Accessible.role: Accessible.StaticText
    Accessible.name: lineEdit.inputHasFocus && !lineEdit.readOnly ? qsTr("Please enter the word number") + " " + (wordNumber + 1) + "." +
                                                                    (icon.visible ? (icon.wordsMatch ? qsTr("Green check mark") + "."
                                                                                                     : qsTr("Red exclamation mark") + ".")
                                                                                  : "")
                                                                  : (wordNumber + 1) + word + ". " +
                                                                    (lineEdit.inputHasFocus && lineEdit.readOnly ? qsTr("Green check mark")
                                                                                                                 : qsTr("This word is spelled ") + " " + wordSpelled + ".") +
                                                                    translationManager.emptyString
    KeyNavigation.up: wordNumber == 0 ? (recoveryPhraseLabel.visible ? recoveryPhraseLabel : header) : parent.children[wordNumber - 1]
    KeyNavigation.backtab: wordNumber == 0 ? (recoveryPhraseLabel.visible ? recoveryPhraseLabel : header) : parent.children[wordNumber - 1]
    Keys.onUpPressed: focusOnPreviousField()
    Keys.onBacktabPressed: focusOnPreviousField()
    Keys.onDownPressed: focusOnNextField()
    Keys.onTabPressed: focusOnNextField()

    function focusOnPreviousField() {
        if (wizardCreateWallet2.state == "verify") {
            if (wordNumber < 5) {
                if (recoveryPhraseLabel.visible) {
                    return recoveryPhraseLabel.forceActiveFocus();
                } else {
                    return header.forceActiveFocus();
                }
            } else if (wordNumber >= 5 && wordNumber < 25) {
                return parent.children[wizardCreateWallet2.hiddenWords[parseInt(wordNumber / 5) - 1]].lineEdit.forceActiveFocus()
            }
        } else {
            if (wordNumber == 0) {
                if (recoveryPhraseLabel.visible) {
                    return recoveryPhraseLabel.forceActiveFocus();
                } else {
                    return header.forceActiveFocus();
                }
            } else {
                return parent.children[wordNumber - 1].forceActiveFocus()
            }
        }
    }

    function focusOnNextField() {
        if (wizardCreateWallet2.state == "verify") {
            if (wordNumber < 20) {
                return parent.children[wizardCreateWallet2.hiddenWords[parseInt(wordNumber / 5) + 1]].lineEdit.forceActiveFocus()
            } else {
                return navigation.btnPrev.forceActiveFocus()
            }
        } else {
            if (wordNumber == 24) {
                if (createNewSeedButton.visible) {
                    return createNewSeedButton.forceActiveFocus()
                } else {
                    return printPDFTemplate.forceActiveFocus()
                }
            } else {
                return parent.children[wordNumber + 1].forceActiveFocus()
            }
        }
    }

    RowLayout {
        id: wordRow
        spacing: 0

        MonzeroComponents.Label {
            color: lineEdit.inputHasFocus ? MonzeroComponents.Style.defaultFontColor : MonzeroComponents.Style.dimmedFontColor
            fontSize: 13
            text: (wordNumber + 1)
            themeTransition: false
        }

        MonzeroComponents.LineEdit {
            id: lineEdit
            property bool firstUserInput: true
            inputHeight: 29
            inputPaddingLeft: 10
            inputPaddingBottom: 2
            inputPaddingRight: 0
            borderDisabled: true
            visible: !wordText.visible
            fontSize: 16
            fontBold: true
            text: ""
            tabNavigationEnabled: false
            onTextChanged: {
                if (lineEdit.text.length == wordText.text.length) {
                    firstUserInput = false;
                }
            }
            onBacktabPressed: focusOnPreviousField()
            onTabPressed: focusOnNextField()
        }

        MonzeroComponents.Label {
            id: wordText
            Layout.leftMargin: 10
            color: MonzeroComponents.Style.defaultFontColor
            fontSize: seedListItem.focus ? 19 : 16
            fontBold: true
            text: word
            themeTransition: false
        }

        MonzeroComponents.TextPlain {
            id: icon
            Layout.leftMargin: wordsMatch ? 10 : 0
            property bool wordsMatch: lineEdit.text === wordText.text
            property bool partialWordMatches: lineEdit.text === wordText.text.substring(0, lineEdit.text.length)
            visible: lineEdit.text.length > 0 && !lineEdit.firstUserInput || lineEdit.firstUserInput && !partialWordMatches
            font.family: FontAwesome.fontFamilySolid
            font.styleName: "Solid"
            font.pixelSize: 15
            text: wordsMatch ? FontAwesome.checkCircle : FontAwesome.exclamationCircle
            color: wordsMatch ? (MonzeroComponents.Style.blackTheme ? "#00FF00" : "#008000") : "#FF0000"
            themeTransition: false
            onTextChanged: {
                if (wizardCreateWallet2.seedListGrid && wordsMatch) {
                    if (wordNumber < 20) {
                        focusOnNextField();
                    }
                    lineEdit.readOnly = true;
                }
            }
        }
    }

    Rectangle {
        id: underLine
        color: lineEdit.inputHasFocus ? MonzeroComponents.Style.defaultFontColor : MonzeroComponents.Style.appWindowBorderColor
        Layout.fillWidth: true
        height: 1
    }
}