, #UmNyobe. , QML , , . . , - ( ) QML, .
import QtQuick 1.1
GridView {
id: mainGrid
cellWidth: 165; cellHeight: 95
width: 5*cellWidth; height: 4*cellHeight
model: myModel
delegate: myButton
property string animate: "no"
property int busy: 0
signal busyPlus
signal busyMinus
onBusyPlus: {
busy++
}
onBusyMinus: {
busy--
if (busy == 0) mainGrid.model.algorithm()
}
ListModel {
id: myModel
property int step: 0
property int one: 0
function createModel() {
for (var i=1; i<=20; i++) {
append({"display": i})
}
}
function algorithm() {
if (step == 0) {
move(0,19,1)
one = 0
step++
}
else if (step == 1) {
if (one < 19) {
move(one,one+1,1)
one++
if (one == 19) step++
}
}
else if (step == 2) {
move(0,1,1)
move(5,6,1)
move(10,11,1)
move(15,16,1)
step++
}
}
Component.onCompleted: {
createModel()
mainGrid.animate = "yes"
algorithm()
}
}
Component {
id: myButton
Item {
id: item
width: mainGrid.cellWidth-5; height: mainGrid.cellHeight-5;
Rectangle {
id: box
parent: mainGrid
x: item.x; y: item.y;
width: item.width; height: item.height;
border.width: 1
Text {
anchors.centerIn: parent
text: display
font.pixelSize: 48
}
Behavior on x {
enabled: mainGrid.animate == "yes"
NumberAnimation {
id: animationX;
duration: 1000;
onRunningChanged: {
if (animationX.running) mainGrid.busyPlus()
else mainGrid.busyMinus()
}
}
}
Behavior on y {
enabled: mainGrid.animate == "yes"
NumberAnimation {
id: animationY;
duration: 1000;
onRunningChanged: {
if (animationY.running) mainGrid.busyPlus()
else mainGrid.busyMinus()
}
}
}
}
}
}
}