mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
[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:
parent
1c5bfdbabe
commit
c75a483ee6
16 changed files with 303 additions and 69 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue