Warning, /games/kreversi/src/qml/Board.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2013 Denis Kuplyakov <dener.kup@gmail.com>
0003
0004 SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006
0007 import QtQuick 2.3
0008 import "globals.js" as Globals
0009
0010 /**
0011 * Board
0012 *
0013 * Represents board with chips.
0014 */
0015
0016 Item {
0017 id: boardContainer
0018
0019 /**
0020 * Is board showing labels or not
0021 */
0022 property bool isShowingLabels: false
0023 /**
0024 * Chips image's ID prefix at SVG theme file to use.
0025 */
0026 property string chipsImagePrefix: "chip_bw"
0027 /**
0028 * Duration of chip's turning animation
0029 */
0030 property int chipsAnimationTime: 25 * 12
0031 /**
0032 * Emitted when user clicks (row, column) cell
0033 * @param row row index of cell (starting from 0)
0034 * @param column column index of cell (starting from 0)
0035 */
0036 signal cellClicked(int row, int column)
0037
0038 /**
0039 * Enables/disables hint at (row, column) cell
0040 * @param row row index of cell (starting from 0)
0041 * @param column column index of cell (starting from 0)
0042 * @param value @c true show hint
0043 * @c false hide hint
0044 */
0045 function setHint(row, column, value) {
0046 cells.itemAt(row * Globals.COLUMN_COUNT + column).isHint = value
0047 }
0048
0049 /**
0050 * Enables/disables legal marker at (row, column) cell
0051 * @param row row index of cell (starting from 0)
0052 * @param column column index of cell (starting from 0)
0053 * @param value @c true show legal marker
0054 * @c false hide legal marker
0055 */
0056 function setLegal(row, column, value) {
0057 cells.itemAt(row * Globals.COLUMN_COUNT + column).isLegal = value
0058 }
0059
0060 /**
0061 * Turn chip to White/Black at (row, column) cell
0062 * @param row row index of cell (starting from 0)
0063 * @param column column index of cell (starting from 0)
0064 * @param value @c "Black" turn chip to black
0065 * @c "White turn chip to white
0066 * @c "" (empty string) hide chip
0067 */
0068 function setChipState(row, column, value) {
0069 cells.itemAt(row * Globals.COLUMN_COUNT + column).chipState = value
0070 }
0071
0072 /**
0073 * Enables/disables last move marker at (row, column) cell
0074 * @param row row index of cell (starting from 0)
0075 * @param column column index of cell (starting from 0)
0076 * @param value @c true show last move marker
0077 * @c false hide last move marker
0078 */
0079 function setLastMove(row, column, value) {
0080 cells.itemAt(row * Globals.COLUMN_COUNT + column).isLastMove = value
0081 }
0082
0083 /**
0084 * Sets time to wait before starting animation
0085 * @param row row index of cell (starting from 0)
0086 * @param column column index of cell (starting from 0)
0087 * @param value time to wait
0088 */
0089 function setPreAnimationTime(row, column, value) {
0090 cells.itemAt(row * Globals.COLUMN_COUNT + column).chipPreAnimationTime = value
0091 }
0092
0093 CanvasItem {
0094 id: boardLabels
0095 anchors.fill: parent
0096 visible: isShowingLabels
0097 spriteKey: "board_numbers"
0098 }
0099
0100 Item {
0101 anchors.horizontalCenter: parent.horizontalCenter
0102 anchors.verticalCenter: parent.verticalCenter
0103
0104 x: Globals.GRID_OFFSET_X_PERCENT * boardContainer.width
0105 y: Globals.GRID_OFFSET_Y_PERCENT * boardContainer.height
0106
0107 width: Globals.GRID_WIDTH_PERCENT * boardContainer.width
0108 height: Globals.GRID_HEIGHT_PERCENT * boardContainer.height
0109
0110 Repeater {
0111 id: cells
0112 model: Globals.ROW_COUNT * Globals.COLUMN_COUNT
0113
0114 Cell {
0115 x: (index % Globals.COLUMN_COUNT)
0116 * Globals.GRID_WIDTH_PERCENT
0117 * boardContainer.width
0118 / Globals.COLUMN_COUNT;
0119 y: Math.floor(index / Globals.COLUMN_COUNT)
0120 * Globals.GRID_HEIGHT_PERCENT
0121 * boardContainer.height
0122 / Globals.ROW_COUNT;
0123
0124 width: Globals.GRID_WIDTH_PERCENT * boardContainer.width
0125 / Globals.COLUMN_COUNT
0126 height: Globals.GRID_HEIGHT_PERCENT * boardContainer.height
0127 / Globals.ROW_COUNT
0128
0129 chipImagePrefix: boardContainer.chipsImagePrefix
0130 chipAnimationTime: boardContainer.chipsAnimationTime
0131
0132 onClicked: boardContainer.cellClicked(index / Globals.COLUMN_COUNT,
0133 index % Globals.COLUMN_COUNT)
0134 }
0135 }
0136 }
0137 }