Skip to content
GridDraw.qml 2.1 KiB
Newer Older
Gabriel Aprigliano Fernandes's avatar
Gabriel Aprigliano Fernandes committed
/*
//    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);
            }
        }
    }
}