Newer
Older
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
/*
// PatherQuick: GridDraw.qml
// by gabriel.ufrj@gmail.com
// more info at:
// http://gaf.impa.br or http://www.gabrieldesign.com.br
//
// This file is part of PatherQuick.
//
// PatherQuick is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PatherQuick is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
Item {
id: root
width: 300
height: width
function drawMap(map) {
var div = map.length > map[0].length ? map.length : map[0].length
height = (width/div)*map.length
for (var i = 0; i < map.length; i++) {
for (var j = 0; j < map[0].length; j++) {
var theColor = "grey"
var theText = ""
if (map[i][j] == 1 ) { theColor = "black" }
if (map[i][j] == "X" ) { theColor = "green" }
if (map[i][j] == "S" ) { theColor = "blue"; theText = "S" }
if (map[i][j] == "!" ) { theColor = "orange"; theText = "!" }
if (map[i][j] == "E" ) { theColor = "red"; theText = "E" }
if (map[i][j] == 0 ) { theColor = "grey" }
var textComponentString = 'Text { text : "'+theText+'"; font.pixelSize: parent.height*0.5; color: "white"; anchors.centerIn: parent; }'
Qt.createQmlObject('import QtQuick 2.4; Rectangle { border.width: width*0.02 < 0.5 ? 0.5 : width*0.02; color: "'+theColor+'"; x:width*'+j+'; y:width*'+i+'; width: parent.width/'+div+'; height: width; '+textComponentString+'}', root);
}
}
}
}