aboutsummaryrefslogtreecommitdiffhomepage
path: root/qml/Bit.qml
blob: 7bb63ceac53f3d160153376f01a8d01509f0c41d (plain) (blame)
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
import QtQuick 2.0
import Sailfish.Silica 1.0

Loader {
    property int index: 0
    property int bits: 0

    Component {
        id: bit
        Switch {
            width: Theme.paddingLarge * 2
            height: width
            onClicked: root.check(index)
            Component.onCompleted: root.matrix[index] = 0
        }
    }

    Component {
        id: bit_index
        Label {
            text: parent.index.toString()
            width: Theme.paddingLarge * 2
            height: width
            horizontalAlignment: TextInput.AlignHCenter
            verticalAlignment: TextInput.AlignVCenter
            Component.onCompleted: {
                if (index > bits) {
                    var num = Math.floor(Math.random() * Math.pow(bits - 1, 2)) + 1;
                    this.text = num;
                    root.matrix[index] = num;
                } else {
                    this.text = "?";
                }
            }
        }
    }

    sourceComponent: (index % (bits + 1) == bits)
                     || (index <= bits) ? bit_index : bit
}