2022-03-23 19:40:28 +08:00
|
|
|
import QtQuick 2.15
|
2022-04-14 18:22:00 +08:00
|
|
|
import "../../util.js" as Utility
|
2022-03-23 19:40:28 +08:00
|
|
|
|
|
|
|
Item {
|
|
|
|
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) {
|
2022-03-30 14:14:40 +08:00
|
|
|
for (let i = 0; i < inputs.length; i++)
|
2022-03-23 19:40:28 +08:00
|
|
|
filterInputCard(inputs[i]);
|
|
|
|
} else {
|
|
|
|
filterInputCard(inputs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterInputCard(card)
|
|
|
|
{
|
|
|
|
card.autoBack = true;
|
|
|
|
card.draggable = true;
|
|
|
|
card.selectable = false;
|
|
|
|
card.clicked.connect(adjustCards);
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(outputs)
|
|
|
|
{
|
2022-03-30 14:14:40 +08:00
|
|
|
let result = cardArea.remove(outputs);
|
|
|
|
let card;
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
2022-03-23 19:40:28 +08:00
|
|
|
card = result[i];
|
|
|
|
card.draggable = false;
|
|
|
|
card.selectable = false;
|
|
|
|
card.selectedChanged.disconnect(adjustCards);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableCards(cardIds)
|
|
|
|
{
|
2022-03-30 14:14:40 +08:00
|
|
|
let card, i;
|
2022-03-23 19:40:28 +08:00
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
card.selectable = cardIds.contains(card.cid);
|
|
|
|
if (!card.selectable) {
|
|
|
|
card.selected = false;
|
|
|
|
unselectCard(card);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCardPosition(animated)
|
|
|
|
{
|
|
|
|
cardArea.updateCardPosition(false);
|
|
|
|
|
2022-03-30 14:14:40 +08:00
|
|
|
let i, card;
|
2022-03-23 19:40:28 +08:00
|
|
|
for (i = 0; i < cards.length; i++) {
|
|
|
|
card = cards[i];
|
|
|
|
if (card.selected)
|
2022-04-14 18:22:00 +08:00
|
|
|
card.origY -= 20;
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (animated) {
|
|
|
|
for (i = 0; i < cards.length; i++)
|
2022-04-14 18:22:00 +08:00
|
|
|
cards[i].goBack(true)
|
2022-03-23 19:40:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustCards()
|
|
|
|
{
|
|
|
|
area.updateCardPosition(true);
|
|
|
|
|
2022-03-30 14:14:40 +08:00
|
|
|
for (let i = 0; i < cards.length; i++) {
|
|
|
|
let card = cards[i];
|
2022-03-23 19:40:28 +08:00
|
|
|
if (card.selected) {
|
|
|
|
if (!selectedCards.contains(card))
|
|
|
|
selectCard(card);
|
|
|
|
} else {
|
|
|
|
if (selectedCards.contains(card))
|
|
|
|
unselectCard(card);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectCard(card)
|
|
|
|
{
|
|
|
|
selectedCards.push(card);
|
|
|
|
cardSelected(card.cid, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function unselectCard(card)
|
|
|
|
{
|
2022-03-30 14:14:40 +08:00
|
|
|
for (let i = 0; i < selectedCards.length; i++) {
|
2022-03-23 19:40:28 +08:00
|
|
|
if (selectedCards[i] === card) {
|
|
|
|
selectedCards.splice(i, 1);
|
|
|
|
cardSelected(card.cid, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function unselectAll(exceptId) {
|
|
|
|
let card = undefined;
|
2022-03-30 14:14:40 +08:00
|
|
|
for (let i = 0; i < selectedCards.length; i++) {
|
2022-03-23 19:40:28 +08:00
|
|
|
if (selectedCards[i].cid !== exceptId) {
|
|
|
|
selectedCards[i].selected = false;
|
|
|
|
} else {
|
|
|
|
card = selectedCards[i];
|
|
|
|
card.selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (card === undefined) {
|
|
|
|
selectedCards = [];
|
|
|
|
} else {
|
|
|
|
selectedCards = [card];
|
|
|
|
}
|
|
|
|
updateCardPosition(true);
|
|
|
|
}
|
|
|
|
}
|