From 1a7c61dfb1da9de54e276e241495359d40c80ef7 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Fri, 10 Apr 2020 01:06:07 +0200
Subject: Added working selector and mover
---
qml/Functions.qml | 40 +++++++++++++++++++++++++++++++---------
qml/Square.qml | 8 ++++++--
qml/images/bb.svg | 17 +++++++++++++++++
qml/images/bbishop.svg | 17 -----------------
qml/images/bk.svg | 25 +++++++++++++++++++++++++
qml/images/bking.svg | 25 -------------------------
qml/images/bknight.svg | 14 --------------
qml/images/bn.svg | 14 ++++++++++++++
qml/images/bp.svg | 7 +++++++
qml/images/bpawn.svg | 7 -------
qml/images/bq.svg | 34 ++++++++++++++++++++++++++++++++++
qml/images/bqueen.svg | 34 ----------------------------------
qml/images/br.svg | 39 +++++++++++++++++++++++++++++++++++++++
qml/images/brook.svg | 39 ---------------------------------------
qml/images/wb.svg | 17 +++++++++++++++++
qml/images/wbishop.svg | 17 -----------------
qml/images/wk.svg | 27 +++++++++++++++++++++++++++
qml/images/wking.svg | 27 ---------------------------
qml/images/wknight.svg | 13 -------------
qml/images/wn.svg | 13 +++++++++++++
qml/images/wp.svg | 7 +++++++
qml/images/wpawn.svg | 7 -------
qml/images/wq.svg | 33 +++++++++++++++++++++++++++++++++
qml/images/wqueen.svg | 33 ---------------------------------
qml/images/wr.svg | 25 +++++++++++++++++++++++++
qml/images/wrook.svg | 25 -------------------------
qml/pages/Board.qml | 2 +-
src/harbour-sailchess.cpp | 10 ----------
28 files changed, 296 insertions(+), 280 deletions(-)
create mode 100644 qml/images/bb.svg
delete mode 100644 qml/images/bbishop.svg
create mode 100644 qml/images/bk.svg
delete mode 100644 qml/images/bking.svg
delete mode 100644 qml/images/bknight.svg
create mode 100644 qml/images/bn.svg
create mode 100644 qml/images/bp.svg
delete mode 100644 qml/images/bpawn.svg
create mode 100644 qml/images/bq.svg
delete mode 100644 qml/images/bqueen.svg
create mode 100644 qml/images/br.svg
delete mode 100644 qml/images/brook.svg
create mode 100644 qml/images/wb.svg
delete mode 100644 qml/images/wbishop.svg
create mode 100644 qml/images/wk.svg
delete mode 100644 qml/images/wking.svg
delete mode 100644 qml/images/wknight.svg
create mode 100644 qml/images/wn.svg
create mode 100644 qml/images/wp.svg
delete mode 100644 qml/images/wpawn.svg
create mode 100644 qml/images/wq.svg
delete mode 100644 qml/images/wqueen.svg
create mode 100644 qml/images/wr.svg
delete mode 100644 qml/images/wrook.svg
diff --git a/qml/Functions.qml b/qml/Functions.qml
index 7e32f4e..4b90cc7 100644
--- a/qml/Functions.qml
+++ b/qml/Functions.qml
@@ -5,21 +5,43 @@ Item {
id: functions
function get_piece(i) {
- if (i === 0 || i === 7) return "rook";
- else if (i === 1 || i === 6) return "knight";
- else if (i === 2 || i === 5) return "bishop";
- else if (i === 3) return "queen";
- else if (i === 4) return "king";
- else if (i >= 8 && i <= 15) return "pawn";
+ if (i === 0 || i === 7) return "r";
+ else if (i === 1 || i === 6) return "n";
+ else if (i === 2 || i === 5) return "b";
+ else if (i === 3) return "q";
+ else if (i === 4) return "k";
+ else if (i >= 8 && i <= 15) return "p";
}
function fill() {
for (var i = 0; i < 16; i++) {
const piece = get_piece(i);
- repeater.itemAt(i).image = piece !== "" ? "images/b" + piece + ".svg" : "";
- repeater.itemAt(-i + 63).image = piece !== "" ? "images/w" + piece + ".svg" : "";
+
+ board.itemAt(i).piece = "b" + piece;
+ board.itemAt(-i + 63).piece = "w" + piece;
}
// Swap white king & queen
- repeater.itemAt(60).image = [repeater.itemAt(59).image, repeater.itemAt(59).image = repeater.itemAt(60).image][0];
+ board.itemAt(60).piece = [board.itemAt(59).piece, board.itemAt(59).piece = board.itemAt(60).piece][0];
+ }
+
+ property var selected: []
+ function select(i) {
+ if (selected.length < 2) {
+ if (selected.indexOf(i) === -1) selected.push(i)
+ else selected.splice(selected.indexOf(i), 1)
+
+ if (selected.length === 2) {
+ board.itemAt(selected[0]).border.width = 0;
+ move(selected[0], selected[1]);
+ } else {
+ board.itemAt(i).border.width ^= parseInt(0.1 * board.itemAt(i).width);
+ }
+ }
+ }
+
+ function move(from, to) {
+ board.itemAt(to).piece = board.itemAt(from).piece;
+ board.itemAt(from).piece = "";
+ selected = [];
}
}
diff --git a/qml/Square.qml b/qml/Square.qml
index 78b7a5d..b1e3e0c 100644
--- a/qml/Square.qml
+++ b/qml/Square.qml
@@ -2,17 +2,21 @@ import QtQuick 2.0
Rectangle {
property int i: 0
- property string image: ""
+ property string piece: ""
+ property string image: piece !== "" ? "images/" + piece + ".svg" : ""
+
width: page.width / 8
height: this.width
color: ((i >> 3 ^ i) & 1) == 0 ? "#e8ebef" : "#7d8796"
border.color: "yellow"
border.width: 0
+
MouseArea {
anchors.fill: parent
- onClicked: parent.border.width ^= parseInt(0.1 * parent.width)
+ onClicked: functions.select(i);
}
Image {
+ id: piece_image
sourceSize.width: parent.width
sourceSize.height: parent.height
source: image
diff --git a/qml/images/bb.svg b/qml/images/bb.svg
new file mode 100644
index 0000000..4ce248f
--- /dev/null
+++ b/qml/images/bb.svg
@@ -0,0 +1,17 @@
+
+
+
diff --git a/qml/images/bbishop.svg b/qml/images/bbishop.svg
deleted file mode 100644
index 4ce248f..0000000
--- a/qml/images/bbishop.svg
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
diff --git a/qml/images/bk.svg b/qml/images/bk.svg
new file mode 100644
index 0000000..d90dc73
--- /dev/null
+++ b/qml/images/bk.svg
@@ -0,0 +1,25 @@
+
+
+
diff --git a/qml/images/bking.svg b/qml/images/bking.svg
deleted file mode 100644
index d90dc73..0000000
--- a/qml/images/bking.svg
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
diff --git a/qml/images/bknight.svg b/qml/images/bknight.svg
deleted file mode 100644
index 02b0894..0000000
--- a/qml/images/bknight.svg
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
diff --git a/qml/images/bn.svg b/qml/images/bn.svg
new file mode 100644
index 0000000..02b0894
--- /dev/null
+++ b/qml/images/bn.svg
@@ -0,0 +1,14 @@
+
+
+
diff --git a/qml/images/bp.svg b/qml/images/bp.svg
new file mode 100644
index 0000000..072f2fe
--- /dev/null
+++ b/qml/images/bp.svg
@@ -0,0 +1,7 @@
+
+
+
diff --git a/qml/images/bpawn.svg b/qml/images/bpawn.svg
deleted file mode 100644
index 072f2fe..0000000
--- a/qml/images/bpawn.svg
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
diff --git a/qml/images/bq.svg b/qml/images/bq.svg
new file mode 100644
index 0000000..6f1e4a5
--- /dev/null
+++ b/qml/images/bq.svg
@@ -0,0 +1,34 @@
+
+
+
diff --git a/qml/images/bqueen.svg b/qml/images/bqueen.svg
deleted file mode 100644
index 6f1e4a5..0000000
--- a/qml/images/bqueen.svg
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
diff --git a/qml/images/br.svg b/qml/images/br.svg
new file mode 100644
index 0000000..337af8f
--- /dev/null
+++ b/qml/images/br.svg
@@ -0,0 +1,39 @@
+
+
+
diff --git a/qml/images/brook.svg b/qml/images/brook.svg
deleted file mode 100644
index 337af8f..0000000
--- a/qml/images/brook.svg
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
diff --git a/qml/images/wb.svg b/qml/images/wb.svg
new file mode 100644
index 0000000..0f28d08
--- /dev/null
+++ b/qml/images/wb.svg
@@ -0,0 +1,17 @@
+
+
+
diff --git a/qml/images/wbishop.svg b/qml/images/wbishop.svg
deleted file mode 100644
index 0f28d08..0000000
--- a/qml/images/wbishop.svg
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
diff --git a/qml/images/wk.svg b/qml/images/wk.svg
new file mode 100644
index 0000000..8b2d7b7
--- /dev/null
+++ b/qml/images/wk.svg
@@ -0,0 +1,27 @@
+
+
+
diff --git a/qml/images/wking.svg b/qml/images/wking.svg
deleted file mode 100644
index 8b2d7b7..0000000
--- a/qml/images/wking.svg
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
diff --git a/qml/images/wknight.svg b/qml/images/wknight.svg
deleted file mode 100644
index 644d6e8..0000000
--- a/qml/images/wknight.svg
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
diff --git a/qml/images/wn.svg b/qml/images/wn.svg
new file mode 100644
index 0000000..644d6e8
--- /dev/null
+++ b/qml/images/wn.svg
@@ -0,0 +1,13 @@
+
+
+
diff --git a/qml/images/wp.svg b/qml/images/wp.svg
new file mode 100644
index 0000000..1142516
--- /dev/null
+++ b/qml/images/wp.svg
@@ -0,0 +1,7 @@
+
+
+
diff --git a/qml/images/wpawn.svg b/qml/images/wpawn.svg
deleted file mode 100644
index 1142516..0000000
--- a/qml/images/wpawn.svg
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
diff --git a/qml/images/wq.svg b/qml/images/wq.svg
new file mode 100644
index 0000000..97043c5
--- /dev/null
+++ b/qml/images/wq.svg
@@ -0,0 +1,33 @@
+
+
+
diff --git a/qml/images/wqueen.svg b/qml/images/wqueen.svg
deleted file mode 100644
index 97043c5..0000000
--- a/qml/images/wqueen.svg
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
diff --git a/qml/images/wr.svg b/qml/images/wr.svg
new file mode 100644
index 0000000..8d2d932
--- /dev/null
+++ b/qml/images/wr.svg
@@ -0,0 +1,25 @@
+
+
+
diff --git a/qml/images/wrook.svg b/qml/images/wrook.svg
deleted file mode 100644
index 8d2d932..0000000
--- a/qml/images/wrook.svg
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml
index efa79f7..4bb5d9c 100644
--- a/qml/pages/Board.qml
+++ b/qml/pages/Board.qml
@@ -34,7 +34,7 @@ Page {
columns: 8
rows: 8
Repeater {
- id: repeater
+ id: board
model: 64
delegate: Square {
i: index
diff --git a/src/harbour-sailchess.cpp b/src/harbour-sailchess.cpp
index e7df625..819f873 100644
--- a/src/harbour-sailchess.cpp
+++ b/src/harbour-sailchess.cpp
@@ -6,15 +6,5 @@
int main(int argc, char *argv[])
{
- // SailfishApp::main() will display "qml/harbour-sailchess.qml", if you need more
- // control over initialization, you can use:
- //
- // - SailfishApp::application(int, char *[]) to get the QGuiApplication *
- // - SailfishApp::createView() to get a new QQuickView * instance
- // - SailfishApp::pathTo(QString) to get a QUrl to a resource file
- // - SailfishApp::pathToMainQml() to get a QUrl to the main QML file
- //
- // To display the view, call "show()" (will show fullscreen on device).
-
return SailfishApp::main(argc, argv);
}
--
cgit v1.2.3