mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-05 21:13:55 -07:00
[VDE] Minor cleanups, possibly fullscreen width-lock fix (#6438)
* Refactor some constructor things to their own methods. * Saner size policies, no manual resize management. Took 15 seconds Took 23 seconds * VDE doesn't need to manually resize either. Took 6 minutes * Add plate comments and re-order .cpp to be more structured. Took 9 minutes Took 30 seconds * Add plate comments and re-order DeckCardZoneDisplay.cpp to be more structured Took 7 minutes Took 5 seconds * Add plate comments and re-order CardGroupDisplayWidget.cpp to be more structured Took 7 minutes Took 4 minutes * Include declaration. Took 3 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
52547bbfe8
commit
a0d1359860
5 changed files with 264 additions and 206 deletions
|
|
@ -39,6 +39,34 @@ CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Just here so it can get overwritten in subclasses.
|
||||||
|
void CardGroupDisplayWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================================================================
|
||||||
|
// User Interaction
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
void CardGroupDisplayWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::mousePressEvent(event);
|
||||||
|
if (selectionModel) {
|
||||||
|
selectionModel->clearSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardGroupDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card)
|
||||||
|
{
|
||||||
|
emit cardClicked(event, card);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardGroupDisplayWidget::onHover(const ExactCard &card)
|
||||||
|
{
|
||||||
|
emit cardHovered(card);
|
||||||
|
}
|
||||||
|
|
||||||
void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
{
|
{
|
||||||
auto proxyModel = qobject_cast<QAbstractProxyModel *>(selectionModel->model());
|
auto proxyModel = qobject_cast<QAbstractProxyModel *>(selectionModel->model());
|
||||||
|
|
@ -76,15 +104,9 @@ void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardGroupDisplayWidget::clearAllDisplayWidgets()
|
// =====================================================================================================================
|
||||||
{
|
// Display Widget Management
|
||||||
for (auto idx : indexToWidgetMap.keys()) {
|
// =====================================================================================================================
|
||||||
auto displayWidget = indexToWidgetMap.value(idx);
|
|
||||||
removeFromLayout(displayWidget);
|
|
||||||
indexToWidgetMap.remove(idx);
|
|
||||||
delete displayWidget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *CardGroupDisplayWidget::constructWidgetForIndex(QPersistentModelIndex index)
|
QWidget *CardGroupDisplayWidget::constructWidgetForIndex(QPersistentModelIndex index)
|
||||||
{
|
{
|
||||||
|
|
@ -134,6 +156,20 @@ void CardGroupDisplayWidget::updateCardDisplays()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardGroupDisplayWidget::clearAllDisplayWidgets()
|
||||||
|
{
|
||||||
|
for (auto idx : indexToWidgetMap.keys()) {
|
||||||
|
auto displayWidget = indexToWidgetMap.value(idx);
|
||||||
|
removeFromLayout(displayWidget);
|
||||||
|
indexToWidgetMap.remove(idx);
|
||||||
|
delete displayWidget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================================================================
|
||||||
|
// DeckListModel Signal Responses
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
void CardGroupDisplayWidget::onCardAddition(const QModelIndex &parent, int first, int last)
|
void CardGroupDisplayWidget::onCardAddition(const QModelIndex &parent, int first, int last)
|
||||||
{
|
{
|
||||||
if (!trackedIndex.isValid()) {
|
if (!trackedIndex.isValid()) {
|
||||||
|
|
@ -178,27 +214,4 @@ void CardGroupDisplayWidget::onActiveSortCriteriaChanged(QStringList _activeSort
|
||||||
|
|
||||||
clearAllDisplayWidgets();
|
clearAllDisplayWidgets();
|
||||||
updateCardDisplays();
|
updateCardDisplays();
|
||||||
}
|
|
||||||
|
|
||||||
void CardGroupDisplayWidget::mousePressEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
QWidget::mousePressEvent(event);
|
|
||||||
if (selectionModel) {
|
|
||||||
selectionModel->clearSelection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardGroupDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card)
|
|
||||||
{
|
|
||||||
emit cardClicked(event, card);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardGroupDisplayWidget::onHover(const ExactCard &card)
|
|
||||||
{
|
|
||||||
emit cardHovered(card);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardGroupDisplayWidget::resizeEvent(QResizeEvent *event)
|
|
||||||
{
|
|
||||||
QWidget::resizeEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +23,7 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
|
||||||
displayType(_displayType), bannerOpacity(bannerOpacity), subBannerOpacity(subBannerOpacity),
|
displayType(_displayType), bannerOpacity(bannerOpacity), subBannerOpacity(subBannerOpacity),
|
||||||
cardSizeWidget(_cardSizeWidget)
|
cardSizeWidget(_cardSizeWidget)
|
||||||
{
|
{
|
||||||
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
layout = new QVBoxLayout(this);
|
layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
|
@ -46,6 +47,20 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &DeckCardZoneDisplayWidget::onCategoryRemoval);
|
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &DeckCardZoneDisplayWidget::onCategoryRemoval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =====================================================================================================================
|
||||||
|
// User Interaction
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
void DeckCardZoneDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card)
|
||||||
|
{
|
||||||
|
emit cardClicked(event, card, zoneName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckCardZoneDisplayWidget::onHover(const ExactCard &card)
|
||||||
|
{
|
||||||
|
emit cardHovered(card);
|
||||||
|
}
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
void DeckCardZoneDisplayWidget::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||||
{
|
{
|
||||||
for (auto &range : selected) {
|
for (auto &range : selected) {
|
||||||
|
|
@ -69,17 +84,9 @@ void DeckCardZoneDisplayWidget::onSelectionChanged(const QItemSelection &selecte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::cleanupInvalidCardGroup(CardGroupDisplayWidget *displayWidget)
|
// =====================================================================================================================
|
||||||
{
|
// Display Widget Management
|
||||||
cardGroupLayout->removeWidget(displayWidget);
|
// =====================================================================================================================
|
||||||
displayWidget->setParent(nullptr);
|
|
||||||
for (auto idx : indexToWidgetMap.keys()) {
|
|
||||||
if (!idx.isValid()) {
|
|
||||||
indexToWidgetMap.remove(idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete displayWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::constructAppropriateWidget(QPersistentModelIndex index)
|
void DeckCardZoneDisplayWidget::constructAppropriateWidget(QPersistentModelIndex index)
|
||||||
{
|
{
|
||||||
|
|
@ -141,6 +148,45 @@ void DeckCardZoneDisplayWidget::displayCards()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckCardZoneDisplayWidget::refreshDisplayType(const DisplayType &_displayType)
|
||||||
|
{
|
||||||
|
displayType = _displayType;
|
||||||
|
QLayoutItem *item;
|
||||||
|
while ((item = cardGroupLayout->takeAt(0)) != nullptr) {
|
||||||
|
if (item->widget()) {
|
||||||
|
item->widget()->deleteLater();
|
||||||
|
} else if (item->layout()) {
|
||||||
|
item->layout()->deleteLater();
|
||||||
|
}
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
indexToWidgetMap.clear();
|
||||||
|
|
||||||
|
// We gotta wait for all the deleteLater's to finish so we fire after the next event cycle
|
||||||
|
|
||||||
|
auto timer = new QTimer(this);
|
||||||
|
timer->setSingleShot(true);
|
||||||
|
connect(timer, &QTimer::timeout, this, [this]() { displayCards(); });
|
||||||
|
timer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckCardZoneDisplayWidget::cleanupInvalidCardGroup(CardGroupDisplayWidget *displayWidget)
|
||||||
|
{
|
||||||
|
cardGroupLayout->removeWidget(displayWidget);
|
||||||
|
displayWidget->setParent(nullptr);
|
||||||
|
for (auto idx : indexToWidgetMap.keys()) {
|
||||||
|
if (!idx.isValid()) {
|
||||||
|
indexToWidgetMap.remove(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete displayWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================================================================
|
||||||
|
// DeckListModel Signal Responses
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::onCategoryAddition(const QModelIndex &parent, int first, int last)
|
void DeckCardZoneDisplayWidget::onCategoryAddition(const QModelIndex &parent, int first, int last)
|
||||||
{
|
{
|
||||||
if (!trackedIndex.isValid()) {
|
if (!trackedIndex.isValid()) {
|
||||||
|
|
@ -173,48 +219,6 @@ void DeckCardZoneDisplayWidget::onCategoryRemoval(const QModelIndex &parent, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::resizeEvent(QResizeEvent *event)
|
|
||||||
{
|
|
||||||
QWidget::resizeEvent(event);
|
|
||||||
for (QObject *child : layout->children()) {
|
|
||||||
QWidget *widget = qobject_cast<QWidget *>(child);
|
|
||||||
if (widget) {
|
|
||||||
widget->setMaximumWidth(width());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void DeckCardZoneDisplayWidget::onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card)
|
|
||||||
{
|
|
||||||
emit cardClicked(event, card, zoneName);
|
|
||||||
}
|
|
||||||
void DeckCardZoneDisplayWidget::onHover(const ExactCard &card)
|
|
||||||
{
|
|
||||||
emit cardHovered(card);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::refreshDisplayType(const DisplayType &_displayType)
|
|
||||||
{
|
|
||||||
displayType = _displayType;
|
|
||||||
QLayoutItem *item;
|
|
||||||
while ((item = cardGroupLayout->takeAt(0)) != nullptr) {
|
|
||||||
if (item->widget()) {
|
|
||||||
item->widget()->deleteLater();
|
|
||||||
} else if (item->layout()) {
|
|
||||||
item->layout()->deleteLater();
|
|
||||||
}
|
|
||||||
delete item;
|
|
||||||
}
|
|
||||||
|
|
||||||
indexToWidgetMap.clear();
|
|
||||||
|
|
||||||
// We gotta wait for all the deleteLater's to finish so we fire after the next event cycle
|
|
||||||
|
|
||||||
auto timer = new QTimer(this);
|
|
||||||
timer->setSingleShot(true);
|
|
||||||
connect(timer, &QTimer::timeout, this, [this]() { displayCards(); });
|
|
||||||
timer->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeckCardZoneDisplayWidget::onActiveGroupCriteriaChanged(QString _activeGroupCriteria)
|
void DeckCardZoneDisplayWidget::onActiveGroupCriteriaChanged(QString _activeGroupCriteria)
|
||||||
{
|
{
|
||||||
activeGroupCriteria = _activeGroupCriteria;
|
activeGroupCriteria = _activeGroupCriteria;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ public:
|
||||||
QPersistentModelIndex trackedIndex;
|
QPersistentModelIndex trackedIndex;
|
||||||
QString zoneName;
|
QString zoneName;
|
||||||
void addCardsToOverlapWidget();
|
void addCardsToOverlapWidget();
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);
|
void onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,36 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
|
||||||
mainLayout->setContentsMargins(9, 0, 9, 5);
|
mainLayout->setContentsMargins(9, 0, 9, 5);
|
||||||
mainLayout->setSpacing(0);
|
mainLayout->setSpacing(0);
|
||||||
|
|
||||||
|
initializeDisplayOptionsAndSearchWidget();
|
||||||
|
|
||||||
|
initializeScrollAreaAndZoneContainer();
|
||||||
|
|
||||||
|
cardSizeWidget = new CardSizeWidget(this, nullptr, SettingsCache::instance().getVisualDeckEditorCardSize());
|
||||||
|
connect(cardSizeWidget, &CardSizeWidget::cardSizeSettingUpdated, &SettingsCache::instance(),
|
||||||
|
&SettingsCache::setVisualDeckEditorCardSize);
|
||||||
|
|
||||||
|
mainLayout->addWidget(displayOptionsAndSearch);
|
||||||
|
mainLayout->addWidget(scrollArea);
|
||||||
|
mainLayout->addWidget(cardSizeWidget);
|
||||||
|
|
||||||
|
connectDeckListModel();
|
||||||
|
|
||||||
|
constructZoneWidgetsFromDeckListModel();
|
||||||
|
|
||||||
|
if (selectionModel) {
|
||||||
|
connect(selectionModel, &QItemSelectionModel::selectionChanged, this,
|
||||||
|
&VisualDeckEditorWidget::onSelectionChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================================================================
|
||||||
|
// Constructor helpers
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::initializeSearchBarAndCompleter()
|
||||||
|
{
|
||||||
searchBar = new QLineEdit(this);
|
searchBar = new QLineEdit(this);
|
||||||
connect(searchBar, &QLineEdit::returnPressed, this, [=, this]() {
|
connect(searchBar, &QLineEdit::returnPressed, this, [=, this]() {
|
||||||
if (!searchBar->hasFocus())
|
if (!searchBar->hasFocus())
|
||||||
|
|
@ -109,12 +139,10 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
|
||||||
emit cardAdditionRequested(card);
|
emit cardAdditionRequested(card);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
displayOptionsAndSearch = new QWidget(this);
|
void VisualDeckEditorWidget::initializeDisplayOptionsWidget()
|
||||||
displayOptionsAndSearchLayout = new QHBoxLayout(displayOptionsAndSearch);
|
{
|
||||||
displayOptionsAndSearchLayout->setAlignment(Qt::AlignLeft);
|
|
||||||
displayOptionsAndSearch->setLayout(displayOptionsAndSearchLayout);
|
|
||||||
|
|
||||||
displayOptionsWidget = new VisualDeckDisplayOptionsWidget(this);
|
displayOptionsWidget = new VisualDeckDisplayOptionsWidget(this);
|
||||||
connect(displayOptionsWidget, &VisualDeckDisplayOptionsWidget::displayTypeChanged, this,
|
connect(displayOptionsWidget, &VisualDeckDisplayOptionsWidget::displayTypeChanged, this,
|
||||||
&VisualDeckEditorWidget::displayTypeChanged);
|
&VisualDeckEditorWidget::displayTypeChanged);
|
||||||
|
|
@ -122,11 +150,26 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
|
||||||
&VisualDeckEditorWidget::activeGroupCriteriaChanged);
|
&VisualDeckEditorWidget::activeGroupCriteriaChanged);
|
||||||
connect(displayOptionsWidget, &VisualDeckDisplayOptionsWidget::sortCriteriaChanged, this,
|
connect(displayOptionsWidget, &VisualDeckDisplayOptionsWidget::sortCriteriaChanged, this,
|
||||||
&VisualDeckEditorWidget::activeSortCriteriaChanged);
|
&VisualDeckEditorWidget::activeSortCriteriaChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::initializeDisplayOptionsAndSearchWidget()
|
||||||
|
{
|
||||||
|
initializeSearchBarAndCompleter();
|
||||||
|
|
||||||
|
initializeDisplayOptionsWidget();
|
||||||
|
|
||||||
|
displayOptionsAndSearch = new QWidget(this);
|
||||||
|
displayOptionsAndSearchLayout = new QHBoxLayout(displayOptionsAndSearch);
|
||||||
|
displayOptionsAndSearchLayout->setAlignment(Qt::AlignLeft);
|
||||||
|
displayOptionsAndSearch->setLayout(displayOptionsAndSearchLayout);
|
||||||
|
|
||||||
displayOptionsAndSearchLayout->addWidget(displayOptionsWidget);
|
displayOptionsAndSearchLayout->addWidget(displayOptionsWidget);
|
||||||
displayOptionsAndSearchLayout->addWidget(searchBar);
|
displayOptionsAndSearchLayout->addWidget(searchBar);
|
||||||
displayOptionsAndSearchLayout->addWidget(searchPushButton);
|
displayOptionsAndSearchLayout->addWidget(searchPushButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::initializeScrollAreaAndZoneContainer()
|
||||||
|
{
|
||||||
scrollArea = new QScrollArea(this);
|
scrollArea = new QScrollArea(this);
|
||||||
scrollArea->setWidgetResizable(true);
|
scrollArea->setWidgetResizable(true);
|
||||||
scrollArea->setMinimumSize(0, 0);
|
scrollArea->setMinimumSize(0, 0);
|
||||||
|
|
@ -136,31 +179,19 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
|
||||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
|
|
||||||
zoneContainer = new QWidget(scrollArea);
|
zoneContainer = new QWidget(scrollArea);
|
||||||
|
zoneContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
zoneContainerLayout = new QVBoxLayout(zoneContainer);
|
zoneContainerLayout = new QVBoxLayout(zoneContainer);
|
||||||
zoneContainer->setLayout(zoneContainerLayout);
|
zoneContainer->setLayout(zoneContainerLayout);
|
||||||
scrollArea->addScrollBarWidget(zoneContainer, Qt::AlignHCenter);
|
scrollArea->addScrollBarWidget(zoneContainer, Qt::AlignHCenter);
|
||||||
scrollArea->setWidget(zoneContainer);
|
scrollArea->setWidget(zoneContainer);
|
||||||
|
}
|
||||||
|
|
||||||
cardSizeWidget = new CardSizeWidget(this, nullptr, SettingsCache::instance().getVisualDeckEditorCardSize());
|
void VisualDeckEditorWidget::connectDeckListModel()
|
||||||
connect(cardSizeWidget, &CardSizeWidget::cardSizeSettingUpdated, &SettingsCache::instance(),
|
{
|
||||||
&SettingsCache::setVisualDeckEditorCardSize);
|
|
||||||
|
|
||||||
mainLayout->addWidget(displayOptionsAndSearch);
|
|
||||||
mainLayout->addWidget(scrollArea);
|
|
||||||
mainLayout->addWidget(cardSizeWidget);
|
|
||||||
|
|
||||||
connect(deckListModel, &DeckListModel::modelReset, this, &VisualDeckEditorWidget::decklistModelReset);
|
connect(deckListModel, &DeckListModel::modelReset, this, &VisualDeckEditorWidget::decklistModelReset);
|
||||||
connect(deckListModel, &DeckListModel::dataChanged, this, &VisualDeckEditorWidget::decklistDataChanged);
|
connect(deckListModel, &DeckListModel::dataChanged, this, &VisualDeckEditorWidget::decklistDataChanged);
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &VisualDeckEditorWidget::onCardAddition);
|
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &VisualDeckEditorWidget::onCardAddition);
|
||||||
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &VisualDeckEditorWidget::onCardRemoval);
|
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &VisualDeckEditorWidget::onCardRemoval);
|
||||||
constructZoneWidgetsFromDeckListModel();
|
|
||||||
|
|
||||||
if (selectionModel) {
|
|
||||||
connect(selectionModel, &QItemSelectionModel::selectionChanged, this,
|
|
||||||
&VisualDeckEditorWidget::onSelectionChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
retranslateUi();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::retranslateUi()
|
void VisualDeckEditorWidget::retranslateUi()
|
||||||
|
|
@ -171,96 +202,9 @@ void VisualDeckEditorWidget::retranslateUi()
|
||||||
"preferred printing to the deck on pressing enter"));
|
"preferred printing to the deck on pressing enter"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::setSelectionModel(QItemSelectionModel *model)
|
// =====================================================================================================================
|
||||||
{
|
// Display Widget Management
|
||||||
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()
|
|
||||||
{
|
|
||||||
for (auto idx : indexToWidgetMap.keys()) {
|
|
||||||
auto displayWidget = indexToWidgetMap.value(idx);
|
|
||||||
zoneContainerLayout->removeWidget(displayWidget);
|
|
||||||
indexToWidgetMap.remove(idx);
|
|
||||||
delete displayWidget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisualDeckEditorWidget::cleanupInvalidZones(DeckCardZoneDisplayWidget *displayWidget)
|
|
||||||
{
|
|
||||||
zoneContainerLayout->removeWidget(displayWidget);
|
|
||||||
for (auto idx : indexToWidgetMap.keys()) {
|
|
||||||
if (!idx.isValid()) {
|
|
||||||
indexToWidgetMap.remove(idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete displayWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisualDeckEditorWidget::onCardAddition(const QModelIndex &parent, int first, int last)
|
|
||||||
{
|
|
||||||
if (parent == deckListModel->getRoot()) {
|
|
||||||
for (int i = first; i <= last; i++) {
|
|
||||||
QPersistentModelIndex index = QPersistentModelIndex(deckListModel->index(i, 0, deckListModel->getRoot()));
|
|
||||||
|
|
||||||
if (indexToWidgetMap.contains(index)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructZoneWidgetForIndex(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisualDeckEditorWidget::onCardRemoval(const QModelIndex &parent, int first, int last)
|
|
||||||
{
|
|
||||||
Q_UNUSED(parent);
|
|
||||||
Q_UNUSED(first);
|
|
||||||
Q_UNUSED(last);
|
|
||||||
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
|
||||||
if (!idx.isValid()) {
|
|
||||||
zoneContainerLayout->removeWidget(indexToWidgetMap.value(idx));
|
|
||||||
indexToWidgetMap.value(idx)->deleteLater();
|
|
||||||
indexToWidgetMap.remove(idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisualDeckEditorWidget::constructZoneWidgetForIndex(QPersistentModelIndex persistent)
|
void VisualDeckEditorWidget::constructZoneWidgetForIndex(QPersistentModelIndex persistent)
|
||||||
{
|
{
|
||||||
|
|
@ -312,10 +256,58 @@ void VisualDeckEditorWidget::updateZoneWidgets()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::resizeEvent(QResizeEvent *event)
|
void VisualDeckEditorWidget::clearAllDisplayWidgets()
|
||||||
{
|
{
|
||||||
QWidget::resizeEvent(event);
|
for (auto idx : indexToWidgetMap.keys()) {
|
||||||
zoneContainer->setMaximumWidth(scrollArea->viewport()->width());
|
auto displayWidget = indexToWidgetMap.value(idx);
|
||||||
|
zoneContainerLayout->removeWidget(displayWidget);
|
||||||
|
indexToWidgetMap.remove(idx);
|
||||||
|
delete displayWidget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::cleanupInvalidZones(DeckCardZoneDisplayWidget *displayWidget)
|
||||||
|
{
|
||||||
|
zoneContainerLayout->removeWidget(displayWidget);
|
||||||
|
for (auto idx : indexToWidgetMap.keys()) {
|
||||||
|
if (!idx.isValid()) {
|
||||||
|
indexToWidgetMap.remove(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete displayWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================================================================
|
||||||
|
// DeckModel Signals Management
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::onCardAddition(const QModelIndex &parent, int first, int last)
|
||||||
|
{
|
||||||
|
if (parent == deckListModel->getRoot()) {
|
||||||
|
for (int i = first; i <= last; i++) {
|
||||||
|
QPersistentModelIndex index = QPersistentModelIndex(deckListModel->index(i, 0, deckListModel->getRoot()));
|
||||||
|
|
||||||
|
if (indexToWidgetMap.contains(index)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructZoneWidgetForIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::onCardRemoval(const QModelIndex &parent, int first, int last)
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent);
|
||||||
|
Q_UNUSED(first);
|
||||||
|
Q_UNUSED(last);
|
||||||
|
for (const QPersistentModelIndex &idx : indexToWidgetMap.keys()) {
|
||||||
|
if (!idx.isValid()) {
|
||||||
|
zoneContainerLayout->removeWidget(indexToWidgetMap.value(idx));
|
||||||
|
indexToWidgetMap.value(idx)->deleteLater();
|
||||||
|
indexToWidgetMap.remove(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::decklistModelReset()
|
void VisualDeckEditorWidget::decklistModelReset()
|
||||||
|
|
@ -334,6 +326,17 @@ void VisualDeckEditorWidget::decklistDataChanged(QModelIndex topLeft, QModelInde
|
||||||
updateZoneWidgets();
|
updateZoneWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =====================================================================================================================
|
||||||
|
// User Interaction
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::onCardClick(QMouseEvent *event,
|
||||||
|
CardInfoPictureWithTextOverlayWidget *instance,
|
||||||
|
QString zoneName)
|
||||||
|
{
|
||||||
|
emit cardClicked(event, instance, zoneName);
|
||||||
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::onHover(const ExactCard &hoveredCard)
|
void VisualDeckEditorWidget::onHover(const ExactCard &hoveredCard)
|
||||||
{
|
{
|
||||||
// If user has any card selected, ignore hover
|
// If user has any card selected, ignore hover
|
||||||
|
|
@ -348,9 +351,43 @@ void VisualDeckEditorWidget::onHover(const ExactCard &hoveredCard)
|
||||||
// highlightHoveredCard(hoveredCard);
|
// highlightHoveredCard(hoveredCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::onCardClick(QMouseEvent *event,
|
void VisualDeckEditorWidget::setSelectionModel(QItemSelectionModel *model)
|
||||||
CardInfoPictureWithTextOverlayWidget *instance,
|
|
||||||
QString zoneName)
|
|
||||||
{
|
{
|
||||||
emit cardClicked(event, instance, zoneName);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ public:
|
||||||
explicit VisualDeckEditorWidget(QWidget *parent, DeckListModel *deckListModel, QItemSelectionModel *selectionModel);
|
explicit VisualDeckEditorWidget(QWidget *parent, DeckListModel *deckListModel, QItemSelectionModel *selectionModel);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void clearAllDisplayWidgets();
|
void clearAllDisplayWidgets();
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
|
||||||
|
|
||||||
void setDeckList(const DeckList &_deckListModel);
|
void setDeckList(const DeckList &_deckListModel);
|
||||||
|
|
||||||
|
|
@ -70,6 +69,13 @@ signals:
|
||||||
void cardAdditionRequested(const ExactCard &card);
|
void cardAdditionRequested(const ExactCard &card);
|
||||||
void displayTypeChanged(DisplayType displayType);
|
void displayTypeChanged(DisplayType displayType);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void initializeSearchBarAndCompleter();
|
||||||
|
void initializeDisplayOptionsWidget();
|
||||||
|
void initializeDisplayOptionsAndSearchWidget();
|
||||||
|
void initializeScrollAreaAndZoneContainer();
|
||||||
|
void connectDeckListModel();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onHover(const ExactCard &hoveredCard);
|
void onHover(const ExactCard &hoveredCard);
|
||||||
void onCardClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *instance, QString zoneName);
|
void onCardClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *instance, QString zoneName);
|
||||||
|
|
@ -91,7 +97,6 @@ private:
|
||||||
QWidget *zoneContainer;
|
QWidget *zoneContainer;
|
||||||
QVBoxLayout *zoneContainerLayout;
|
QVBoxLayout *zoneContainerLayout;
|
||||||
// OverlapControlWidget *overlapControlWidget;
|
// OverlapControlWidget *overlapControlWidget;
|
||||||
QWidget *container;
|
|
||||||
QHash<QPersistentModelIndex, QWidget *> indexToWidgetMap;
|
QHash<QPersistentModelIndex, QWidget *> indexToWidgetMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue