b81a09a8069ed598756fd07bedbe7b0fb92414aa
[staging/HomeScreen.git] / sample-qml / imports / components / HexGrid.qml
1 /* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved.
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6  
7 import QtQuick 2.0
8
9 Item {
10     property real spacing: 0
11     property int columns: 3
12
13     width: childrenRect.width
14     height: childrenRect.height
15
16     Component.onCompleted: {
17         var sizeX = childrenRect.height
18         var sizeY = childrenRect.width
19         var column = 0
20         var row = 0
21
22         for (var n = 0; n < children.length; n++) {
23             children[n].x = column * (sizeX + spacing)
24             children[n].y = row * (0.5 * sizeY + spacing)
25             column += 2
26             if (column >= columns) {
27                 row++
28                 column = row % 2
29             }
30         }
31     }
32 }