blob: 9e9f9e690558ba6b7d06fab75084d75b02544915 (
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
|
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQml
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts
import GameOfLifeModel
ApplicationWindow {
id: root
visible: true
width: 760
height: 810
minimumWidth: 475
minimumHeight: 300
color: "#09102B"
title: qsTr("Conway’s Game of Life")
//! [tableview]
TableView {
id: tableView
anchors.fill: parent
rowSpacing: 1
columnSpacing: 1
ScrollBar.horizontal: ScrollBar {}
ScrollBar.vertical: ScrollBar {}
delegate: Rectangle {
id: cell
implicitWidth: 15
implicitHeight: 15
required property var model
required property bool value
color: value ? "#f3f3f4" : "#b5b7bf"
MouseArea {
anchors.fill: parent
onClicked: parent.model.value = !parent.value
}
}
//! [tableview]
//! [model]
model: GameOfLifeModel {
id: gameOfLifeModel
}
//! [model]
//! [scroll]
contentX: (contentWidth - width) / 2;
contentY: (contentHeight - height) / 2;
//! [scroll]
}
footer: Rectangle {
signal nextStep
id: footer
height: 50
color: "#F3F3F4"
RowLayout {
anchors.centerIn: parent
//! [next]
Button {
text: qsTr("Next")
onClicked: gameOfLifeModel.nextStep()
}
//! [next]
Item {
width: 50
}
Slider {
id: slider
x: 245
y: 17
from: 0
to: 1
value: 0.9
}
Button {
text: timer.running ? "❙❙" : "▶️"
onClicked: timer.running = !timer.running
}
}
Timer {
id: timer
interval: 1000 - (980 * slider.value)
running: true
repeat: true
onTriggered: gameOfLifeModel.nextStep()
}
}
Component.onCompleted: {
gameOfLifeModel.loadFile(":/gosperglidergun.cells");
}
}
|