2023-04-09 13:35:35 +08:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
import QtQuick
|
2023-05-19 10:08:36 +08:00
|
|
|
import Fk
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
Item {
|
2022-04-30 15:27:56 +08:00
|
|
|
property alias cards: cardArea.cards
|
|
|
|
property alias length: cardArea.length
|
|
|
|
property var selectedCards: []
|
|
|
|
|
|
|
|
signal cardSelected(int cardId, bool selected)
|
|
|
|
|
|
|
|
id: area
|
|
|
|
|
|
|
|
CardArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
id: cardArea
|
|
|
|
onLengthChanged: area.updateCardPosition(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function add(inputs)
|
|
|
|
{
|
|
|
|
cardArea.add(inputs);
|
|
|
|
if (inputs instanceof Array) {
|
|
|
|
for (let i = 0; i < inputs.length; i++)
|
|
|
|
filterInputCard(inputs[i]);
|
|
|
|
} else {
|
|
|
|
filterInputCard(inputs);
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function filterInputCard(card)
|
|
|
|
{
|
|
|
|
card.autoBack = true;
|
|
|
|
card.draggable = true;
|
|
|
|
card.selectable = false;
|
|
|
|
card.clicked.connect(adjustCards);
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(outputs)
|
|
|
|
{
|
2023-06-09 17:23:02 +08:00
|
|
|
const result = cardArea.remove(outputs);
|
2022-04-30 15:27:56 +08:00
|
|
|
let card;
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
card = result[i];
|
|
|
|
card.draggable = false;
|
|
|
|
card.selectable = false;
|
|
|
|
card.selectedChanged.disconnect(adjustCards);
|
2023-09-19 14:27:54 +08:00
|
|
|
card.prohibitReason = "";
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableCards(cardIds)
|
|
|
|
{
|
|
|
|
let card, i;
|
2023-06-24 14:48:49 +08:00
|
|
|
cards.forEach(card => {
|
2024-01-25 03:23:29 +08:00
|
|
|
card.selectable = cardIds.includes(card.cid);
|
2022-04-30 15:27:56 +08:00
|
|
|
if (!card.selectable) {
|
|
|
|
card.selected = false;
|
|
|
|
unselectCard(card);
|
|
|
|
}
|
2023-06-24 14:48:49 +08:00
|
|
|
});
|
|
|
|
updateCardPosition(true);
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
cardArea.updateCardPosition(false);
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2023-06-24 14:48:49 +08:00
|
|
|
cards.forEach(card => {
|
|
|
|
if (card.selected) {
|
2022-04-30 15:27:56 +08:00
|
|
|
card.origY -= 20;
|
2023-06-24 14:48:49 +08:00
|
|
|
}
|
|
|
|
if (!card.selectable) {
|
|
|
|
if (config.hideUseless) {
|
|
|
|
card.origY += 60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-03-23 19:40:28 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
if (animated) {
|
2023-06-24 14:48:49 +08:00
|
|
|
cards.forEach(card => card.goBack(true));
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function adjustCards()
|
|
|
|
{
|
|
|
|
area.updateCardPosition(true);
|
|
|
|
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
2023-06-09 17:23:02 +08:00
|
|
|
const card = cards[i];
|
2022-04-30 15:27:56 +08:00
|
|
|
if (card.selected) {
|
2024-01-25 03:23:29 +08:00
|
|
|
if (!selectedCards.includes(card))
|
2022-04-30 15:27:56 +08:00
|
|
|
selectCard(card);
|
|
|
|
} else {
|
2024-01-25 03:23:29 +08:00
|
|
|
if (selectedCards.includes(card))
|
2022-04-30 15:27:56 +08:00
|
|
|
unselectCard(card);
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectCard(card)
|
|
|
|
{
|
|
|
|
selectedCards.push(card);
|
|
|
|
cardSelected(card.cid, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function unselectCard(card)
|
|
|
|
{
|
|
|
|
for (let i = 0; i < selectedCards.length; i++) {
|
|
|
|
if (selectedCards[i] === card) {
|
|
|
|
selectedCards.splice(i, 1);
|
|
|
|
cardSelected(card.cid, false);
|
|
|
|
break;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function unselectAll(exceptId) {
|
|
|
|
let card = undefined;
|
|
|
|
for (let i = 0; i < selectedCards.length; i++) {
|
|
|
|
if (selectedCards[i].cid !== exceptId) {
|
|
|
|
selectedCards[i].selected = false;
|
|
|
|
} else {
|
|
|
|
card = selectedCards[i];
|
|
|
|
card.selected = true;
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
if (card === undefined) {
|
|
|
|
selectedCards = [];
|
|
|
|
} else {
|
|
|
|
selectedCards = [card];
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
updateCardPosition(true);
|
|
|
|
}
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|