2023-04-09 05:35:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 05:01:10 +00:00
|
|
|
import QtQuick
|
2023-05-19 02:08:36 +00:00
|
|
|
import Fk
|
2022-03-23 11:40:28 +00:00
|
|
|
|
|
|
|
Item {
|
2022-04-30 07:27:56 +00: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 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function filterInputCard(card)
|
|
|
|
{
|
|
|
|
card.autoBack = true;
|
|
|
|
card.draggable = true;
|
|
|
|
card.selectable = false;
|
2023-05-18 23:45:21 +00:00
|
|
|
card.showDetail = true;
|
2022-04-30 07:27:56 +00:00
|
|
|
card.clicked.connect(adjustCards);
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(outputs)
|
|
|
|
{
|
2023-06-09 09:23:02 +00:00
|
|
|
const result = cardArea.remove(outputs);
|
2022-04-30 07:27:56 +00:00
|
|
|
let card;
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
card = result[i];
|
|
|
|
card.draggable = false;
|
|
|
|
card.selectable = false;
|
2024-01-24 19:23:29 +00:00
|
|
|
// card.showDetail = false;
|
2022-04-30 07:27:56 +00:00
|
|
|
card.selectedChanged.disconnect(adjustCards);
|
2023-09-19 06:27:54 +00:00
|
|
|
card.prohibitReason = "";
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableCards(cardIds)
|
|
|
|
{
|
|
|
|
let card, i;
|
2023-06-24 06:48:49 +00:00
|
|
|
cards.forEach(card => {
|
2024-01-24 19:23:29 +00:00
|
|
|
card.selectable = cardIds.includes(card.cid);
|
2022-04-30 07:27:56 +00:00
|
|
|
if (!card.selectable) {
|
|
|
|
card.selected = false;
|
|
|
|
unselectCard(card);
|
|
|
|
}
|
2023-06-24 06:48:49 +00:00
|
|
|
});
|
|
|
|
updateCardPosition(true);
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
cardArea.updateCardPosition(false);
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2023-06-24 06:48:49 +00:00
|
|
|
cards.forEach(card => {
|
|
|
|
if (card.selected) {
|
2022-04-30 07:27:56 +00:00
|
|
|
card.origY -= 20;
|
2023-06-24 06:48:49 +00:00
|
|
|
}
|
|
|
|
if (!card.selectable) {
|
|
|
|
if (config.hideUseless) {
|
|
|
|
card.origY += 60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-03-23 11:40:28 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (animated) {
|
2023-06-24 06:48:49 +00:00
|
|
|
cards.forEach(card => card.goBack(true));
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function adjustCards()
|
|
|
|
{
|
|
|
|
area.updateCardPosition(true);
|
|
|
|
|
|
|
|
for (let i = 0; i < cards.length; i++) {
|
2023-06-09 09:23:02 +00:00
|
|
|
const card = cards[i];
|
2022-04-30 07:27:56 +00:00
|
|
|
if (card.selected) {
|
2024-01-24 19:23:29 +00:00
|
|
|
if (!selectedCards.includes(card))
|
2022-04-30 07:27:56 +00:00
|
|
|
selectCard(card);
|
|
|
|
} else {
|
2024-01-24 19:23:29 +00:00
|
|
|
if (selectedCards.includes(card))
|
2022-04-30 07:27:56 +00:00
|
|
|
unselectCard(card);
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00: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 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00: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 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
if (card === undefined) {
|
|
|
|
selectedCards = [];
|
|
|
|
} else {
|
|
|
|
selectedCards = [card];
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
updateCardPosition(true);
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|