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;
|
2023-05-18 23:45:21 +00:00
|
|
|
card.showDetail = false;
|
2022-04-30 07:27:56 +00:00
|
|
|
card.selectedChanged.disconnect(adjustCards);
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableCards(cardIds)
|
|
|
|
{
|
|
|
|
let card, i;
|
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.selectable = cardIds.contains(card.cid);
|
|
|
|
if (!card.selectable) {
|
|
|
|
card.selected = false;
|
|
|
|
unselectCard(card);
|
|
|
|
}
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
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
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
let i, card;
|
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
if (card.selected)
|
|
|
|
card.origY -= 20;
|
2022-03-23 11:40:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (animated) {
|
|
|
|
for (i = 0; i < cards.length; i++)
|
|
|
|
cards[i].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) {
|
|
|
|
if (!selectedCards.contains(card))
|
|
|
|
selectCard(card);
|
|
|
|
} else {
|
|
|
|
if (selectedCards.contains(card))
|
|
|
|
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
|
|
|
}
|