mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 19:43:55 -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
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
|
CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *_deckListModel,
|
DeckListModel *_deckListModel,
|
||||||
|
QItemSelectionModel *_selectionModel,
|
||||||
QPersistentModelIndex _trackedIndex,
|
QPersistentModelIndex _trackedIndex,
|
||||||
QString _zoneName,
|
QString _zoneName,
|
||||||
QString _cardGroupCategory,
|
QString _cardGroupCategory,
|
||||||
|
|
@ -17,8 +18,8 @@ CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
|
||||||
QStringList _activeSortCriteria,
|
QStringList _activeSortCriteria,
|
||||||
int bannerOpacity,
|
int bannerOpacity,
|
||||||
CardSizeWidget *_cardSizeWidget)
|
CardSizeWidget *_cardSizeWidget)
|
||||||
: QWidget(parent), deckListModel(_deckListModel), trackedIndex(_trackedIndex), zoneName(_zoneName),
|
: QWidget(parent), deckListModel(_deckListModel), selectionModel(_selectionModel), trackedIndex(_trackedIndex),
|
||||||
cardGroupCategory(_cardGroupCategory), activeGroupCriteria(_activeGroupCriteria),
|
zoneName(_zoneName), cardGroupCategory(_cardGroupCategory), activeGroupCriteria(_activeGroupCriteria),
|
||||||
activeSortCriteria(_activeSortCriteria), cardSizeWidget(_cardSizeWidget)
|
activeSortCriteria(_activeSortCriteria), cardSizeWidget(_cardSizeWidget)
|
||||||
{
|
{
|
||||||
layout = new QVBoxLayout(this);
|
layout = new QVBoxLayout(this);
|
||||||
|
|
@ -32,9 +33,47 @@ CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
|
||||||
CardGroupDisplayWidget::updateCardDisplays();
|
CardGroupDisplayWidget::updateCardDisplays();
|
||||||
|
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &CardGroupDisplayWidget::onCardAddition);
|
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &CardGroupDisplayWidget::onCardAddition);
|
||||||
|
connect(selectionModel, &QItemSelectionModel::selectionChanged, this, &CardGroupDisplayWidget::onSelectionChanged);
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
|
{
|
||||||
|
auto proxyModel = qobject_cast<QAbstractProxyModel *>(selectionModel->model());
|
||||||
|
|
||||||
|
for (auto &range : selected) {
|
||||||
|
for (int row = range.top(); row <= range.bottom(); ++row) {
|
||||||
|
QModelIndex idx = range.model()->index(row, 0, range.parent());
|
||||||
|
|
||||||
|
if (proxyModel) {
|
||||||
|
idx = proxyModel->mapToSource(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
|
if (it != indexToWidgetMap.end()) {
|
||||||
|
if (auto displayWidget = qobject_cast<CardInfoPictureWithTextOverlayWidget *>(it.value())) {
|
||||||
|
displayWidget->setHighlighted(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &range : deselected) {
|
||||||
|
for (int row = range.top(); row <= range.bottom(); ++row) {
|
||||||
|
QModelIndex idx = range.model()->index(row, 0, range.parent());
|
||||||
|
if (proxyModel)
|
||||||
|
idx = proxyModel->mapToSource(idx);
|
||||||
|
|
||||||
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
|
if (it != indexToWidgetMap.end()) {
|
||||||
|
if (auto displayWidget = qobject_cast<CardInfoPictureWithTextOverlayWidget *>(it.value())) {
|
||||||
|
displayWidget->setHighlighted(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CardGroupDisplayWidget::clearAllDisplayWidgets()
|
void CardGroupDisplayWidget::clearAllDisplayWidgets()
|
||||||
{
|
{
|
||||||
for (auto idx : indexToWidgetMap.keys()) {
|
for (auto idx : indexToWidgetMap.keys()) {
|
||||||
|
|
@ -138,6 +177,12 @@ void CardGroupDisplayWidget::onActiveSortCriteriaChanged(QStringList _activeSort
|
||||||
updateCardDisplays();
|
updateCardDisplays();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardGroupDisplayWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::mousePressEvent(event);
|
||||||
|
selectionModel->clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
void CardGroupDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card)
|
void CardGroupDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card)
|
||||||
{
|
{
|
||||||
emit cardClicked(event, card);
|
emit cardClicked(event, card);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "../card_info_picture_with_text_overlay_widget.h"
|
#include "../card_info_picture_with_text_overlay_widget.h"
|
||||||
#include "../card_size_widget.h"
|
#include "../card_size_widget.h"
|
||||||
|
|
||||||
|
#include <QItemSelectionModel>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
@ -24,6 +25,7 @@ class CardGroupDisplayWidget : public QWidget
|
||||||
public:
|
public:
|
||||||
CardGroupDisplayWidget(QWidget *parent,
|
CardGroupDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *deckListModel,
|
DeckListModel *deckListModel,
|
||||||
|
QItemSelectionModel *selectionModel,
|
||||||
QPersistentModelIndex trackedIndex,
|
QPersistentModelIndex trackedIndex,
|
||||||
QString zoneName,
|
QString zoneName,
|
||||||
QString cardGroupCategory,
|
QString cardGroupCategory,
|
||||||
|
|
@ -31,9 +33,11 @@ public:
|
||||||
QStringList activeSortCriteria,
|
QStringList activeSortCriteria,
|
||||||
int bannerOpacity,
|
int bannerOpacity,
|
||||||
CardSizeWidget *cardSizeWidget);
|
CardSizeWidget *cardSizeWidget);
|
||||||
|
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void clearAllDisplayWidgets();
|
void clearAllDisplayWidgets();
|
||||||
|
|
||||||
DeckListModel *deckListModel;
|
DeckListModel *deckListModel;
|
||||||
|
QItemSelectionModel *selectionModel;
|
||||||
QPersistentModelIndex trackedIndex;
|
QPersistentModelIndex trackedIndex;
|
||||||
QHash<QPersistentModelIndex, QWidget *> indexToWidgetMap;
|
QHash<QPersistentModelIndex, QWidget *> indexToWidgetMap;
|
||||||
QString zoneName;
|
QString zoneName;
|
||||||
|
|
@ -43,6 +47,7 @@ public:
|
||||||
CardSizeWidget *cardSizeWidget;
|
CardSizeWidget *cardSizeWidget;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);
|
void onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);
|
||||||
void onHover(const ExactCard &card);
|
void onHover(const ExactCard &card);
|
||||||
virtual QWidget *constructWidgetForIndex(QPersistentModelIndex index);
|
virtual QWidget *constructWidgetForIndex(QPersistentModelIndex index);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
FlatCardGroupDisplayWidget::FlatCardGroupDisplayWidget(QWidget *parent,
|
FlatCardGroupDisplayWidget::FlatCardGroupDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *_deckListModel,
|
DeckListModel *_deckListModel,
|
||||||
|
QItemSelectionModel *_selectionModel,
|
||||||
QPersistentModelIndex _trackedIndex,
|
QPersistentModelIndex _trackedIndex,
|
||||||
QString _zoneName,
|
QString _zoneName,
|
||||||
QString _cardGroupCategory,
|
QString _cardGroupCategory,
|
||||||
|
|
@ -19,6 +20,7 @@ FlatCardGroupDisplayWidget::FlatCardGroupDisplayWidget(QWidget *parent,
|
||||||
CardSizeWidget *_cardSizeWidget)
|
CardSizeWidget *_cardSizeWidget)
|
||||||
: CardGroupDisplayWidget(parent,
|
: CardGroupDisplayWidget(parent,
|
||||||
_deckListModel,
|
_deckListModel,
|
||||||
|
_selectionModel,
|
||||||
std::move(_trackedIndex),
|
std::move(_trackedIndex),
|
||||||
_zoneName,
|
_zoneName,
|
||||||
_cardGroupCategory,
|
_cardGroupCategory,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class FlatCardGroupDisplayWidget : public CardGroupDisplayWidget
|
||||||
public:
|
public:
|
||||||
FlatCardGroupDisplayWidget(QWidget *parent,
|
FlatCardGroupDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *deckListModel,
|
DeckListModel *deckListModel,
|
||||||
|
QItemSelectionModel *selectionModel,
|
||||||
QPersistentModelIndex trackedIndex,
|
QPersistentModelIndex trackedIndex,
|
||||||
QString zoneName,
|
QString zoneName,
|
||||||
QString cardGroupCategory,
|
QString cardGroupCategory,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
#include "overlapped_card_group_display_widget.h"
|
#include "overlapped_card_group_display_widget.h"
|
||||||
|
|
||||||
#include "../card_info_picture_with_text_overlay_widget.h"
|
|
||||||
|
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <libcockatrice/card/card_info_comparator.h>
|
|
||||||
#include <libcockatrice/card/database/card_database_manager.h>
|
#include <libcockatrice/card/database/card_database_manager.h>
|
||||||
#include <libcockatrice/models/deck_list/deck_list_model.h>
|
#include <libcockatrice/models/deck_list/deck_list_model.h>
|
||||||
|
|
||||||
OverlappedCardGroupDisplayWidget::OverlappedCardGroupDisplayWidget(QWidget *parent,
|
OverlappedCardGroupDisplayWidget::OverlappedCardGroupDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *_deckListModel,
|
DeckListModel *_deckListModel,
|
||||||
|
QItemSelectionModel *_selectionModel,
|
||||||
QPersistentModelIndex _trackedIndex,
|
QPersistentModelIndex _trackedIndex,
|
||||||
QString _zoneName,
|
QString _zoneName,
|
||||||
QString _cardGroupCategory,
|
QString _cardGroupCategory,
|
||||||
|
|
@ -18,6 +16,7 @@ OverlappedCardGroupDisplayWidget::OverlappedCardGroupDisplayWidget(QWidget *pare
|
||||||
CardSizeWidget *_cardSizeWidget)
|
CardSizeWidget *_cardSizeWidget)
|
||||||
: CardGroupDisplayWidget(parent,
|
: CardGroupDisplayWidget(parent,
|
||||||
_deckListModel,
|
_deckListModel,
|
||||||
|
_selectionModel,
|
||||||
_trackedIndex,
|
_trackedIndex,
|
||||||
_zoneName,
|
_zoneName,
|
||||||
_cardGroupCategory,
|
_cardGroupCategory,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class OverlappedCardGroupDisplayWidget : public CardGroupDisplayWidget
|
||||||
public:
|
public:
|
||||||
OverlappedCardGroupDisplayWidget(QWidget *parent,
|
OverlappedCardGroupDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *deckListModel,
|
DeckListModel *deckListModel,
|
||||||
|
QItemSelectionModel *selectionModel,
|
||||||
QPersistentModelIndex trackedIndex,
|
QPersistentModelIndex trackedIndex,
|
||||||
QString zoneName,
|
QString zoneName,
|
||||||
QString cardGroupCategory,
|
QString cardGroupCategory,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ CardInfoPictureWithTextOverlayWidget::CardInfoPictureWithTextOverlayWidget(QWidg
|
||||||
const int fontSize,
|
const int fontSize,
|
||||||
const Qt::Alignment alignment)
|
const Qt::Alignment alignment)
|
||||||
: CardInfoPictureWidget(parent, hoverToZoomEnabled, raiseOnEnter), textColor(textColor), outlineColor(outlineColor),
|
: CardInfoPictureWidget(parent, hoverToZoomEnabled, raiseOnEnter), textColor(textColor), outlineColor(outlineColor),
|
||||||
fontSize(fontSize), textAlignment(alignment)
|
fontSize(fontSize), textAlignment(alignment), highlighted(false)
|
||||||
{
|
{
|
||||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
}
|
}
|
||||||
|
|
@ -82,6 +82,16 @@ void CardInfoPictureWithTextOverlayWidget::setTextAlignment(const Qt::Alignment
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardInfoPictureWithTextOverlayWidget::setHighlighted(bool _highlighted)
|
||||||
|
{
|
||||||
|
if (highlighted == _highlighted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
highlighted = _highlighted;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void CardInfoPictureWithTextOverlayWidget::mousePressEvent(QMouseEvent *event)
|
void CardInfoPictureWithTextOverlayWidget::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
emit imageClicked(event, this);
|
emit imageClicked(event, this);
|
||||||
|
|
@ -98,11 +108,6 @@ void CardInfoPictureWithTextOverlayWidget::paintEvent(QPaintEvent *event)
|
||||||
// Call the base class's paintEvent to draw the card image
|
// Call the base class's paintEvent to draw the card image
|
||||||
CardInfoPictureWidget::paintEvent(event);
|
CardInfoPictureWidget::paintEvent(event);
|
||||||
|
|
||||||
// If no overlay text, skip drawing the text
|
|
||||||
if (overlayText.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStylePainter painter(this);
|
QStylePainter painter(this);
|
||||||
|
|
||||||
// Get the pixmap from the base class using the getter
|
// Get the pixmap from the base class using the getter
|
||||||
|
|
@ -116,6 +121,36 @@ void CardInfoPictureWithTextOverlayWidget::paintEvent(QPaintEvent *event)
|
||||||
const QPoint topLeft{(width() - scaledSize.width()) / 2, (height() - scaledSize.height()) / 2};
|
const QPoint topLeft{(width() - scaledSize.width()) / 2, (height() - scaledSize.height()) / 2};
|
||||||
const QRect pixmapRect(topLeft, scaledSize);
|
const QRect pixmapRect(topLeft, scaledSize);
|
||||||
|
|
||||||
|
if (highlighted) {
|
||||||
|
painter.save();
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
|
||||||
|
// Soft glow and border around the pixmap
|
||||||
|
const int padding = 4; // glow extends a little beyond image
|
||||||
|
QRect glowRect = pixmapRect.adjusted(-padding, -padding, padding, padding);
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
|
int radius = 8; // rounded corners
|
||||||
|
path.addRoundedRect(glowRect, radius, radius);
|
||||||
|
|
||||||
|
// Soft outer glow
|
||||||
|
QColor glowColor(0, 150, 255, 80); // subtle blu
|
||||||
|
painter.setPen(QPen(glowColor, 6));
|
||||||
|
painter.drawPath(path);
|
||||||
|
|
||||||
|
// Thin inner border for crispness
|
||||||
|
QColor borderColor(0, 150, 255, 200);
|
||||||
|
painter.setPen(QPen(borderColor, 2));
|
||||||
|
painter.drawRoundedRect(pixmapRect, radius, radius);
|
||||||
|
|
||||||
|
painter.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no overlay text, skip drawing the text
|
||||||
|
if (overlayText.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the optimal font size
|
// Calculate the optimal font size
|
||||||
QFont font = painter.font();
|
QFont font = painter.font();
|
||||||
int optimalFontSize = fontSize; // Start with the user-defined font size
|
int optimalFontSize = fontSize; // Start with the user-defined font size
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ public:
|
||||||
void setOutlineColor(const QColor &color);
|
void setOutlineColor(const QColor &color);
|
||||||
void setFontSize(int size);
|
void setFontSize(int size);
|
||||||
void setTextAlignment(Qt::Alignment alignment);
|
void setTextAlignment(Qt::Alignment alignment);
|
||||||
|
void setHighlighted(bool _highlighted);
|
||||||
|
|
||||||
[[nodiscard]] QSize sizeHint() const override;
|
[[nodiscard]] QSize sizeHint() const override;
|
||||||
signals:
|
signals:
|
||||||
|
|
@ -53,6 +54,7 @@ private:
|
||||||
QColor outlineColor;
|
QColor outlineColor;
|
||||||
int fontSize;
|
int fontSize;
|
||||||
Qt::Alignment textAlignment;
|
Qt::Alignment textAlignment;
|
||||||
|
bool highlighted;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CARD_PICTURE_WITH_TEXT_OVERLAY_H
|
#endif // CARD_PICTURE_WITH_TEXT_OVERLAY_H
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
|
DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *_deckListModel,
|
DeckListModel *_deckListModel,
|
||||||
|
QItemSelectionModel *_selectionModel,
|
||||||
QPersistentModelIndex _trackedIndex,
|
QPersistentModelIndex _trackedIndex,
|
||||||
QString _zoneName,
|
QString _zoneName,
|
||||||
QString _activeGroupCriteria,
|
QString _activeGroupCriteria,
|
||||||
|
|
@ -17,9 +18,10 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
|
||||||
int bannerOpacity,
|
int bannerOpacity,
|
||||||
int subBannerOpacity,
|
int subBannerOpacity,
|
||||||
CardSizeWidget *_cardSizeWidget)
|
CardSizeWidget *_cardSizeWidget)
|
||||||
: QWidget(parent), deckListModel(_deckListModel), trackedIndex(_trackedIndex), zoneName(_zoneName),
|
: QWidget(parent), deckListModel(_deckListModel), selectionModel(_selectionModel), trackedIndex(_trackedIndex),
|
||||||
activeGroupCriteria(_activeGroupCriteria), activeSortCriteria(_activeSortCriteria), displayType(_displayType),
|
zoneName(_zoneName), activeGroupCriteria(_activeGroupCriteria), activeSortCriteria(_activeSortCriteria),
|
||||||
bannerOpacity(bannerOpacity), subBannerOpacity(subBannerOpacity), cardSizeWidget(_cardSizeWidget)
|
displayType(_displayType), bannerOpacity(bannerOpacity), subBannerOpacity(subBannerOpacity),
|
||||||
|
cardSizeWidget(_cardSizeWidget)
|
||||||
{
|
{
|
||||||
layout = new QVBoxLayout(this);
|
layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
@ -37,9 +39,34 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
|
||||||
displayCards();
|
displayCards();
|
||||||
|
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &DeckCardZoneDisplayWidget::onCategoryAddition);
|
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &DeckCardZoneDisplayWidget::onCategoryAddition);
|
||||||
|
connect(selectionModel, &QItemSelectionModel::selectionChanged, this,
|
||||||
|
&DeckCardZoneDisplayWidget::onSelectionChanged);
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &DeckCardZoneDisplayWidget::onCategoryRemoval);
|
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &DeckCardZoneDisplayWidget::onCategoryRemoval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckCardZoneDisplayWidget::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
|
{
|
||||||
|
for (auto &range : selected) {
|
||||||
|
for (int row = range.top(); row <= range.bottom(); ++row) {
|
||||||
|
QModelIndex idx = range.model()->index(row, 0, range.parent());
|
||||||
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
|
if (it != indexToWidgetMap.end()) {
|
||||||
|
// it.value()->setHighlighted(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &range : deselected) {
|
||||||
|
for (int row = range.top(); row <= range.bottom(); ++row) {
|
||||||
|
QModelIndex idx = range.model()->index(row, 0, range.parent());
|
||||||
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
|
if (it != indexToWidgetMap.end()) {
|
||||||
|
// it.value()->setHighlighted(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::cleanupInvalidCardGroup(CardGroupDisplayWidget *displayWidget)
|
void DeckCardZoneDisplayWidget::cleanupInvalidCardGroup(CardGroupDisplayWidget *displayWidget)
|
||||||
{
|
{
|
||||||
cardGroupLayout->removeWidget(displayWidget);
|
cardGroupLayout->removeWidget(displayWidget);
|
||||||
|
|
@ -60,8 +87,8 @@ void DeckCardZoneDisplayWidget::constructAppropriateWidget(QPersistentModelIndex
|
||||||
}
|
}
|
||||||
if (displayType == DisplayType::Overlap) {
|
if (displayType == DisplayType::Overlap) {
|
||||||
auto *displayWidget = new OverlappedCardGroupDisplayWidget(
|
auto *displayWidget = new OverlappedCardGroupDisplayWidget(
|
||||||
cardGroupContainer, deckListModel, index, zoneName, categoryName, activeGroupCriteria, activeSortCriteria,
|
cardGroupContainer, deckListModel, selectionModel, index, zoneName, categoryName, activeGroupCriteria,
|
||||||
subBannerOpacity, cardSizeWidget);
|
activeSortCriteria, subBannerOpacity, cardSizeWidget);
|
||||||
connect(displayWidget, &OverlappedCardGroupDisplayWidget::cardClicked, this,
|
connect(displayWidget, &OverlappedCardGroupDisplayWidget::cardClicked, this,
|
||||||
&DeckCardZoneDisplayWidget::onClick);
|
&DeckCardZoneDisplayWidget::onClick);
|
||||||
connect(displayWidget, &OverlappedCardGroupDisplayWidget::cardHovered, this,
|
connect(displayWidget, &OverlappedCardGroupDisplayWidget::cardHovered, this,
|
||||||
|
|
@ -73,9 +100,9 @@ void DeckCardZoneDisplayWidget::constructAppropriateWidget(QPersistentModelIndex
|
||||||
cardGroupLayout->addWidget(displayWidget);
|
cardGroupLayout->addWidget(displayWidget);
|
||||||
indexToWidgetMap.insert(index, displayWidget);
|
indexToWidgetMap.insert(index, displayWidget);
|
||||||
} else if (displayType == DisplayType::Flat) {
|
} else if (displayType == DisplayType::Flat) {
|
||||||
auto *displayWidget =
|
auto *displayWidget = new FlatCardGroupDisplayWidget(cardGroupContainer, deckListModel, selectionModel, index,
|
||||||
new FlatCardGroupDisplayWidget(cardGroupContainer, deckListModel, index, zoneName, categoryName,
|
zoneName, categoryName, activeGroupCriteria,
|
||||||
activeGroupCriteria, activeSortCriteria, subBannerOpacity, cardSizeWidget);
|
activeSortCriteria, subBannerOpacity, cardSizeWidget);
|
||||||
connect(displayWidget, &FlatCardGroupDisplayWidget::cardClicked, this, &DeckCardZoneDisplayWidget::onClick);
|
connect(displayWidget, &FlatCardGroupDisplayWidget::cardClicked, this, &DeckCardZoneDisplayWidget::onClick);
|
||||||
connect(displayWidget, &FlatCardGroupDisplayWidget::cardHovered, this, &DeckCardZoneDisplayWidget::onHover);
|
connect(displayWidget, &FlatCardGroupDisplayWidget::cardHovered, this, &DeckCardZoneDisplayWidget::onHover);
|
||||||
connect(displayWidget, &CardGroupDisplayWidget::cleanupRequested, this,
|
connect(displayWidget, &CardGroupDisplayWidget::cleanupRequested, this,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ class DeckCardZoneDisplayWidget : public QWidget
|
||||||
public:
|
public:
|
||||||
DeckCardZoneDisplayWidget(QWidget *parent,
|
DeckCardZoneDisplayWidget(QWidget *parent,
|
||||||
DeckListModel *deckListModel,
|
DeckListModel *deckListModel,
|
||||||
|
QItemSelectionModel *selectionModel,
|
||||||
QPersistentModelIndex trackedIndex,
|
QPersistentModelIndex trackedIndex,
|
||||||
QString zoneName,
|
QString zoneName,
|
||||||
QString activeGroupCriteria,
|
QString activeGroupCriteria,
|
||||||
|
|
@ -34,7 +35,9 @@ public:
|
||||||
int bannerOpacity,
|
int bannerOpacity,
|
||||||
int subBannerOpacity,
|
int subBannerOpacity,
|
||||||
CardSizeWidget *_cardSizeWidget);
|
CardSizeWidget *_cardSizeWidget);
|
||||||
|
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
DeckListModel *deckListModel;
|
DeckListModel *deckListModel;
|
||||||
|
QItemSelectionModel *selectionModel;
|
||||||
QPersistentModelIndex trackedIndex;
|
QPersistentModelIndex trackedIndex;
|
||||||
QString zoneName;
|
QString zoneName;
|
||||||
void addCardsToOverlapWidget();
|
void addCardsToOverlapWidget();
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,11 @@ public:
|
||||||
return activeGroupCriteriaComboBox;
|
return activeGroupCriteriaComboBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QItemSelectionModel *getSelectionModel() const
|
||||||
|
{
|
||||||
|
return deckView->selectionModel();
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cleanDeck();
|
void cleanDeck();
|
||||||
void updateBannerCardComboBox();
|
void updateBannerCardComboBox();
|
||||||
|
|
|
||||||
|
|
@ -176,20 +176,74 @@ void TabDeckEditorVisual::changeModelIndexToCard(const ExactCard &activeCard)
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
index = deckDockWidget->deckModel->findCard(cardName, DECK_ZONE_SIDE);
|
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,
|
void TabDeckEditorVisual::processMainboardCardClick(QMouseEvent *event,
|
||||||
CardInfoPictureWithTextOverlayWidget *instance,
|
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) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
actSwapCard(instance->getCard(), zoneName);
|
Qt::KeyboardModifiers mods = event->modifiers();
|
||||||
} else if (event->button() == Qt::RightButton) {
|
QItemSelectionModel::SelectionFlags flags;
|
||||||
actDecrementCard(instance->getCard());
|
|
||||||
} else if (event->button() == Qt::MiddleButton) {
|
if (mods.testFlag(Qt::ControlModifier)) {
|
||||||
deckDockWidget->actRemoveCard();
|
// 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 instance Widget representing the clicked card.
|
||||||
* @param zoneName Deck zone of the card.
|
* @param zoneName Deck zone of the card.
|
||||||
*/
|
*/
|
||||||
void
|
void processMainboardCardClick(QMouseEvent *event,
|
||||||
processMainboardCardClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *instance, QString zoneName);
|
CardInfoPictureWithTextOverlayWidget *instance,
|
||||||
|
const QString &zoneName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Handle card clicks in the database visual display.
|
* @brief Handle card clicks in the database visual display.
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ TabDeckEditorVisualTabWidget::TabDeckEditorVisualTabWidget(QWidget *parent,
|
||||||
layout = new QVBoxLayout(this);
|
layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
visualDeckView = new VisualDeckEditorWidget(this, deckModel);
|
visualDeckView = new VisualDeckEditorWidget(this, deckModel, _deckEditor->deckDockWidget->getSelectionModel());
|
||||||
visualDeckView->setObjectName("visualDeckView");
|
visualDeckView->setObjectName("visualDeckView");
|
||||||
connect(visualDeckView, &VisualDeckEditorWidget::activeCardChanged, this,
|
connect(visualDeckView, &VisualDeckEditorWidget::activeCardChanged, this,
|
||||||
&TabDeckEditorVisualTabWidget::onCardChanged);
|
&TabDeckEditorVisualTabWidget::onCardChanged);
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,10 @@
|
||||||
#include <libcockatrice/models/deck_list/deck_list_model.h>
|
#include <libcockatrice/models/deck_list/deck_list_model.h>
|
||||||
#include <qscrollarea.h>
|
#include <qscrollarea.h>
|
||||||
|
|
||||||
VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent, DeckListModel *_deckListModel)
|
VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
|
||||||
: QWidget(parent), deckListModel(_deckListModel)
|
DeckListModel *_deckListModel,
|
||||||
|
QItemSelectionModel *_selectionModel)
|
||||||
|
: QWidget(parent), deckListModel(_deckListModel), selectionModel(_selectionModel)
|
||||||
{
|
{
|
||||||
// The Main Widget and Main Layout, which contain a single Widget: The Scroll Area
|
// The Main Widget and Main Layout, which contain a single Widget: The Scroll Area
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
@ -204,6 +206,11 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent, DeckListModel *_
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &VisualDeckEditorWidget::onCardRemoval);
|
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &VisualDeckEditorWidget::onCardRemoval);
|
||||||
constructZoneWidgetsFromDeckListModel();
|
constructZoneWidgetsFromDeckListModel();
|
||||||
|
|
||||||
|
if (selectionModel) {
|
||||||
|
connect(selectionModel, &QItemSelectionModel::selectionChanged, this,
|
||||||
|
&VisualDeckEditorWidget::onSelectionChanged);
|
||||||
|
}
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,6 +226,47 @@ void VisualDeckEditorWidget::retranslateUi()
|
||||||
tr("Change how cards are displayed within zones (i.e. overlapped or fully visible.)"));
|
tr("Change how cards are displayed within zones (i.e. overlapped or fully visible.)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::setSelectionModel(QItemSelectionModel *model)
|
||||||
|
{
|
||||||
|
if (selectionModel == model) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectionModel) {
|
||||||
|
// TODO: Possibly disconnect old ones?
|
||||||
|
}
|
||||||
|
|
||||||
|
selectionModel = model;
|
||||||
|
|
||||||
|
if (selectionModel) {
|
||||||
|
connect(selectionModel, &QItemSelectionModel::selectionChanged, this,
|
||||||
|
&VisualDeckEditorWidget::onSelectionChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
|
{
|
||||||
|
for (auto &range : selected) {
|
||||||
|
for (int row = range.top(); row <= range.bottom(); ++row) {
|
||||||
|
QModelIndex idx = range.model()->index(row, 0, range.parent());
|
||||||
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
|
if (it != indexToWidgetMap.end()) {
|
||||||
|
// it.value()->setHighlighted(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &range : deselected) {
|
||||||
|
for (int row = range.top(); row <= range.bottom(); ++row) {
|
||||||
|
QModelIndex idx = range.model()->index(row, 0, range.parent());
|
||||||
|
auto it = indexToWidgetMap.find(QPersistentModelIndex(idx));
|
||||||
|
if (it != indexToWidgetMap.end()) {
|
||||||
|
// it.value()->setHighlighted(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::clearAllDisplayWidgets()
|
void VisualDeckEditorWidget::clearAllDisplayWidgets()
|
||||||
{
|
{
|
||||||
for (auto idx : indexToWidgetMap.keys()) {
|
for (auto idx : indexToWidgetMap.keys()) {
|
||||||
|
|
@ -250,25 +298,7 @@ void VisualDeckEditorWidget::onCardAddition(const QModelIndex &parent, int first
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckCardZoneDisplayWidget *zoneDisplayWidget = new DeckCardZoneDisplayWidget(
|
constructZoneWidgetForIndex(index);
|
||||||
zoneContainer, deckListModel, index,
|
|
||||||
deckListModel->data(index.sibling(index.row(), 1), Qt::EditRole).toString(), activeGroupCriteria,
|
|
||||||
activeSortCriteria, currentDisplayType, 20, 10, cardSizeWidget);
|
|
||||||
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::cardHovered, this, &VisualDeckEditorWidget::onHover);
|
|
||||||
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::cardClicked, this,
|
|
||||||
&VisualDeckEditorWidget::onCardClick);
|
|
||||||
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::requestCleanup, this,
|
|
||||||
&VisualDeckEditorWidget::cleanupInvalidZones);
|
|
||||||
connect(this, &VisualDeckEditorWidget::activeSortCriteriaChanged, zoneDisplayWidget,
|
|
||||||
&DeckCardZoneDisplayWidget::onActiveSortCriteriaChanged);
|
|
||||||
connect(this, &VisualDeckEditorWidget::activeGroupCriteriaChanged, zoneDisplayWidget,
|
|
||||||
&DeckCardZoneDisplayWidget::onActiveGroupCriteriaChanged);
|
|
||||||
connect(this, &VisualDeckEditorWidget::displayTypeChanged, zoneDisplayWidget,
|
|
||||||
&DeckCardZoneDisplayWidget::refreshDisplayType);
|
|
||||||
zoneDisplayWidget->refreshDisplayType(currentDisplayType);
|
|
||||||
zoneContainerLayout->addWidget(zoneDisplayWidget);
|
|
||||||
|
|
||||||
indexToWidgetMap.insert(index, zoneDisplayWidget);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -287,6 +317,28 @@ void VisualDeckEditorWidget::onCardRemoval(const QModelIndex &parent, int first,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::constructZoneWidgetForIndex(QPersistentModelIndex persistent)
|
||||||
|
{
|
||||||
|
DeckCardZoneDisplayWidget *zoneDisplayWidget = new DeckCardZoneDisplayWidget(
|
||||||
|
zoneContainer, deckListModel, selectionModel, persistent,
|
||||||
|
deckListModel->data(persistent.sibling(persistent.row(), 1), Qt::EditRole).toString(), activeGroupCriteria,
|
||||||
|
activeSortCriteria, currentDisplayType, 20, 10, cardSizeWidget);
|
||||||
|
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::cardHovered, this, &VisualDeckEditorWidget::onHover);
|
||||||
|
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::cardClicked, this, &VisualDeckEditorWidget::onCardClick);
|
||||||
|
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::requestCleanup, this,
|
||||||
|
&VisualDeckEditorWidget::cleanupInvalidZones);
|
||||||
|
connect(this, &VisualDeckEditorWidget::activeSortCriteriaChanged, zoneDisplayWidget,
|
||||||
|
&DeckCardZoneDisplayWidget::onActiveSortCriteriaChanged);
|
||||||
|
connect(this, &VisualDeckEditorWidget::activeGroupCriteriaChanged, zoneDisplayWidget,
|
||||||
|
&DeckCardZoneDisplayWidget::onActiveGroupCriteriaChanged);
|
||||||
|
connect(this, &VisualDeckEditorWidget::displayTypeChanged, zoneDisplayWidget,
|
||||||
|
&DeckCardZoneDisplayWidget::refreshDisplayType);
|
||||||
|
zoneDisplayWidget->refreshDisplayType(currentDisplayType);
|
||||||
|
zoneContainerLayout->addWidget(zoneDisplayWidget);
|
||||||
|
|
||||||
|
indexToWidgetMap.insert(persistent, zoneDisplayWidget);
|
||||||
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::constructZoneWidgetsFromDeckListModel()
|
void VisualDeckEditorWidget::constructZoneWidgetsFromDeckListModel()
|
||||||
{
|
{
|
||||||
QSortFilterProxyModel proxy;
|
QSortFilterProxyModel proxy;
|
||||||
|
|
@ -305,23 +357,7 @@ void VisualDeckEditorWidget::constructZoneWidgetsFromDeckListModel()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckCardZoneDisplayWidget *zoneDisplayWidget = new DeckCardZoneDisplayWidget(
|
constructZoneWidgetForIndex(persistent);
|
||||||
zoneContainer, deckListModel, persistent,
|
|
||||||
deckListModel->data(persistent.sibling(persistent.row(), 1), Qt::EditRole).toString(), activeGroupCriteria,
|
|
||||||
activeSortCriteria, currentDisplayType, 20, 10, cardSizeWidget);
|
|
||||||
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::cardHovered, this, &VisualDeckEditorWidget::onHover);
|
|
||||||
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::cardClicked, this, &VisualDeckEditorWidget::onCardClick);
|
|
||||||
connect(zoneDisplayWidget, &DeckCardZoneDisplayWidget::requestCleanup, this,
|
|
||||||
&VisualDeckEditorWidget::cleanupInvalidZones);
|
|
||||||
connect(this, &VisualDeckEditorWidget::activeSortCriteriaChanged, zoneDisplayWidget,
|
|
||||||
&DeckCardZoneDisplayWidget::onActiveSortCriteriaChanged);
|
|
||||||
connect(this, &VisualDeckEditorWidget::activeGroupCriteriaChanged, zoneDisplayWidget,
|
|
||||||
&DeckCardZoneDisplayWidget::onActiveGroupCriteriaChanged);
|
|
||||||
connect(this, &VisualDeckEditorWidget::displayTypeChanged, zoneDisplayWidget,
|
|
||||||
&DeckCardZoneDisplayWidget::refreshDisplayType);
|
|
||||||
zoneContainerLayout->addWidget(zoneDisplayWidget);
|
|
||||||
|
|
||||||
indexToWidgetMap.insert(persistent, zoneDisplayWidget);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,7 +425,16 @@ void VisualDeckEditorWidget::decklistDataChanged(QModelIndex topLeft, QModelInde
|
||||||
|
|
||||||
void VisualDeckEditorWidget::onHover(const ExactCard &hoveredCard)
|
void VisualDeckEditorWidget::onHover(const ExactCard &hoveredCard)
|
||||||
{
|
{
|
||||||
|
// If user has any card selected, ignore hover
|
||||||
|
if (selectionModel->hasSelection()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nothing is selected -> this is our "active/preview" card
|
||||||
emit activeCardChanged(hoveredCard);
|
emit activeCardChanged(hoveredCard);
|
||||||
|
|
||||||
|
// TODO: highlight hovered card visually:
|
||||||
|
// highlightHoveredCard(hoveredCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::onCardClick(QMouseEvent *event,
|
void VisualDeckEditorWidget::onCardClick(QMouseEvent *event,
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,20 @@ class VisualDeckEditorWidget : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit VisualDeckEditorWidget(QWidget *parent, DeckListModel *deckListModel);
|
explicit VisualDeckEditorWidget(QWidget *parent, DeckListModel *deckListModel, QItemSelectionModel *selectionModel);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void clearAllDisplayWidgets();
|
void clearAllDisplayWidgets();
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
void setDeckList(const DeckList &_deckListModel);
|
void setDeckList(const DeckList &_deckListModel);
|
||||||
|
|
||||||
|
void setSelectionModel(QItemSelectionModel *model);
|
||||||
|
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
|
QItemSelectionModel *getSelectionModel() const
|
||||||
|
{
|
||||||
|
return selectionModel;
|
||||||
|
}
|
||||||
|
|
||||||
QLineEdit *searchBar;
|
QLineEdit *searchBar;
|
||||||
CardSizeWidget *cardSizeWidget;
|
CardSizeWidget *cardSizeWidget;
|
||||||
|
|
||||||
|
|
@ -53,6 +60,7 @@ public slots:
|
||||||
void cleanupInvalidZones(DeckCardZoneDisplayWidget *displayWidget);
|
void cleanupInvalidZones(DeckCardZoneDisplayWidget *displayWidget);
|
||||||
void onCardAddition(const QModelIndex &parent, int first, int last);
|
void onCardAddition(const QModelIndex &parent, int first, int last);
|
||||||
void onCardRemoval(const QModelIndex &parent, int first, int last);
|
void onCardRemoval(const QModelIndex &parent, int first, int last);
|
||||||
|
void constructZoneWidgetForIndex(QPersistentModelIndex persistent);
|
||||||
void constructZoneWidgetsFromDeckListModel();
|
void constructZoneWidgetsFromDeckListModel();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
@ -72,6 +80,7 @@ protected slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeckListModel *deckListModel;
|
DeckListModel *deckListModel;
|
||||||
|
QItemSelectionModel *selectionModel;
|
||||||
QVBoxLayout *mainLayout;
|
QVBoxLayout *mainLayout;
|
||||||
QWidget *searchContainer;
|
QWidget *searchContainer;
|
||||||
QHBoxLayout *searchLayout;
|
QHBoxLayout *searchLayout;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue