[VDE] Add selection model (#6354)

Took 22 minutes

Took 1 minute


Took 17 seconds

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-11-27 22:16:12 +01:00 committed by GitHub
parent 1c5bfdbabe
commit c75a483ee6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 303 additions and 69 deletions

View file

@ -176,20 +176,74 @@ void TabDeckEditorVisual::changeModelIndexToCard(const ExactCard &activeCard)
if (!index.isValid()) {
index = deckDockWidget->deckModel->findCard(cardName, DECK_ZONE_SIDE);
}
deckDockWidget->deckView->setCurrentIndex(index);
if (!deckDockWidget->getSelectionModel()->hasSelection()) {
deckDockWidget->getSelectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
}
}
/** @brief Handles clicks on cards in the mainboard deck. */
void TabDeckEditorVisual::processMainboardCardClick(QMouseEvent *event,
CardInfoPictureWithTextOverlayWidget *instance,
QString zoneName)
const QString &zoneName)
{
auto card = instance->getCard();
// Get the model index for the card
QModelIndex idx = deckDockWidget->deckModel->findCard(card.getName(), zoneName);
if (!idx.isValid()) {
return;
}
QItemSelectionModel *sel = deckDockWidget->getSelectionModel();
// Double click = swap
if (event->type() == QEvent::MouseButtonDblClick && event->button() == Qt::LeftButton) {
actSwapCard(card, zoneName);
idx = deckDockWidget->deckModel->findCard(card.getName(), zoneName);
sel->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
return;
}
// Right-click = decrement
if (event->button() == Qt::RightButton) {
actDecrementCard(card);
// Keep selection intact.
return;
}
// Alt + Left click = increment
if (event->button() == Qt::LeftButton && event->modifiers().testFlag(Qt::AltModifier)) {
// actIncrementCard(card);
// Keep selection intact.
return;
}
// Normal selection behavior
if (event->button() == Qt::LeftButton) {
actSwapCard(instance->getCard(), zoneName);
} else if (event->button() == Qt::RightButton) {
actDecrementCard(instance->getCard());
} else if (event->button() == Qt::MiddleButton) {
deckDockWidget->actRemoveCard();
Qt::KeyboardModifiers mods = event->modifiers();
QItemSelectionModel::SelectionFlags flags;
if (mods.testFlag(Qt::ControlModifier)) {
// CTRL + click = toggle selection
flags = QItemSelectionModel::Toggle;
} else if (mods.testFlag(Qt::ShiftModifier)) {
// SHIFT + click = select range
QModelIndex anchor = sel->currentIndex();
if (!anchor.isValid()) {
anchor = idx;
}
QItemSelection range(anchor, idx);
sel->select(range, QItemSelectionModel::SelectCurrent);
sel->setCurrentIndex(idx, QItemSelectionModel::NoUpdate);
return;
} else {
// Normal click = clear selection, select this, set current
deckDockWidget->deckView->setCurrentIndex(idx);
deckDockWidget->deckView->scrollTo(idx);
return;
}
sel->setCurrentIndex(idx, flags);
}
}

View file

@ -176,8 +176,9 @@ public slots:
* @param instance Widget representing the clicked card.
* @param zoneName Deck zone of the card.
*/
void
processMainboardCardClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *instance, QString zoneName);
void processMainboardCardClick(QMouseEvent *event,
CardInfoPictureWithTextOverlayWidget *instance,
const QString &zoneName);
/**
* @brief Handle card clicks in the database visual display.

View file

@ -28,7 +28,7 @@ TabDeckEditorVisualTabWidget::TabDeckEditorVisualTabWidget(QWidget *parent,
layout = new QVBoxLayout(this);
setLayout(layout);
visualDeckView = new VisualDeckEditorWidget(this, deckModel);
visualDeckView = new VisualDeckEditorWidget(this, deckModel, _deckEditor->deckDockWidget->getSelectionModel());
visualDeckView->setObjectName("visualDeckView");
connect(visualDeckView, &VisualDeckEditorWidget::activeCardChanged, this,
&TabDeckEditorVisualTabWidget::onCardChanged);