Warning, /games/knetwalk/src/qml/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013 Ashwin Rajeev <ashwin_rajeev@hotmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.3 0008 import "logic.js" as Logic 0009 0010 Item { 0011 id: main 0012 property int selected: 0 0013 property int rotateDuration: 300 0014 property bool reverseButtons: false 0015 property string state 0016 property alias rows: grid.rows 0017 property alias columns: grid.columns 0018 0019 signal clicked(int index) 0020 signal rotated(int index, int angle) 0021 0022 CanvasItem { 0023 id: background 0024 spriteKey: "background" 0025 anchors.fill: parent 0026 } 0027 0028 Grid { 0029 id: grid 0030 width: Logic.gridWidth() 0031 height: Logic.gridHeight() 0032 z: 1 0033 anchors.horizontalCenter: parent.horizontalCenter 0034 anchors.verticalCenter: parent.verticalCenter 0035 } 0036 0037 CanvasItem { 0038 spriteKey: "overlay" 0039 anchors.horizontalCenter: parent.horizontalCenter 0040 anchors.verticalCenter: parent.verticalCenter 0041 width: Logic.overlaySize() 0042 height: width 0043 } 0044 0045 Rectangle { 0046 id: highlight 0047 color: "white" 0048 x: grid.x + ((Logic.cells.length > selected)? Logic.cells[selected].x : 0) 0049 y: grid.y + ((Logic.cells.length > selected)? Logic.cells[selected].y : 0) 0050 width: grid.width / grid.columns 0051 height: width 0052 opacity: (main.state === "running")? 0.2 : 0 0053 } 0054 0055 Rectangle { 0056 id: pauseMessage 0057 width: parent.width / 2 0058 height: parent.height / 4 0059 anchors.horizontalCenter: parent.horizontalCenter 0060 anchors.verticalCenter: parent.verticalCenter 0061 color: "black"; radius: 10; z: 1 0062 opacity: (main.state === "paused") ? 0.8 : 0 0063 0064 Text { 0065 color: "white" 0066 text: i18n("Paused") 0067 anchors.horizontalCenter: parent.horizontalCenter 0068 anchors.verticalCenter: parent.verticalCenter 0069 font.pixelSize: parent.width / 8 0070 } 0071 } 0072 0073 function addCell(cable, type) { 0074 Logic.addCell(cable, type); 0075 } 0076 0077 function setBoardSize(width, height) { 0078 Logic.reset(width, height); 0079 } 0080 0081 function rotateClockwise() { 0082 Logic.rotate("clockwise"); 0083 } 0084 0085 function rotateCounterclockwise() { 0086 Logic.rotate("counterclockwise"); 0087 } 0088 0089 function pause(paused) { 0090 state = (paused)? "paused" : "running"; 0091 } 0092 0093 function kbGoUp() { 0094 if(state === "running") { 0095 selected += (selected < columns)? columns * (rows - 1) : -columns; 0096 } 0097 } 0098 0099 function kbGoDown() { 0100 if(state === "running") { 0101 selected += (selected < columns * (rows - 1))? columns : -columns * (rows - 1); 0102 } 0103 } 0104 0105 function kbGoLeft() { 0106 if(state === "running") { 0107 selected += (selected % columns == 0)? columns - 1 : - 1; 0108 } 0109 } 0110 0111 function kbGoRight() { 0112 if (state === "running") { 0113 selected += (selected % columns == columns - 1)? -columns + 1 : 1; 0114 } 0115 } 0116 0117 function toggleLock() { 0118 if(state === "running") { 0119 Logic.cells[selected].locked = !Logic.cells[selected].locked; 0120 } 0121 } 0122 0123 function lock(index) { 0124 Logic.cells[index].locked = true; 0125 } 0126 0127 function unlockAll() { 0128 Logic.unlockAll(); 0129 } 0130 0131 function setSprite(index, cable, type) { 0132 Logic.setSprite(index, cable, type); 0133 } 0134 0135 function gameOver(msg) { 0136 state = msg; 0137 } 0138 }