Compare commits

...

1 Commits

Author SHA1 Message Date
BruebachL
a0d1359860 [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>
2026-01-13 09:08:03 +01:00
5 changed files with 264 additions and 206 deletions

View File

@@ -39,6 +39,34 @@ CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
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)
{
auto proxyModel = qobject_cast<QAbstractProxyModel *>(selectionModel->model());
@@ -76,15 +104,9 @@ void CardGroupDisplayWidget::onSelectionChanged(const QItemSelection &selected,
}
}
void CardGroupDisplayWidget::clearAllDisplayWidgets()
{
for (auto idx : indexToWidgetMap.keys()) {
auto displayWidget = indexToWidgetMap.value(idx);
removeFromLayout(displayWidget);
indexToWidgetMap.remove(idx);
delete displayWidget;
}
}
// =====================================================================================================================
// Display Widget Management
// =====================================================================================================================
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)
{
if (!trackedIndex.isValid()) {
@@ -178,27 +214,4 @@ void CardGroupDisplayWidget::onActiveSortCriteriaChanged(QStringList _activeSort
clearAllDisplayWidgets();
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);
}

View File

@@ -23,6 +23,7 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
displayType(_displayType), bannerOpacity(bannerOpacity), subBannerOpacity(subBannerOpacity),
cardSizeWidget(_cardSizeWidget)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout = new QVBoxLayout(this);
setLayout(layout);
@@ -46,6 +47,20 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
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)
{
for (auto &range : selected) {
@@ -69,17 +84,9 @@ void DeckCardZoneDisplayWidget::onSelectionChanged(const QItemSelection &selecte
}
}
void DeckCardZoneDisplayWidget::cleanupInvalidCardGroup(CardGroupDisplayWidget *displayWidget)
{
cardGroupLayout->removeWidget(displayWidget);
displayWidget->setParent(nullptr);
for (auto idx : indexToWidgetMap.keys()) {
if (!idx.isValid()) {
indexToWidgetMap.remove(idx);
}
}
delete displayWidget;
}
// =====================================================================================================================
// Display Widget Management
// =====================================================================================================================
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)
{
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)
{
activeGroupCriteria = _activeGroupCriteria;

View File

@@ -40,7 +40,6 @@ public:
QPersistentModelIndex trackedIndex;
QString zoneName;
void addCardsToOverlapWidget();
void resizeEvent(QResizeEvent *event) override;
public slots:
void onClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *card);

View File

@@ -38,6 +38,36 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
mainLayout->setContentsMargins(9, 0, 9, 5);
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);
connect(searchBar, &QLineEdit::returnPressed, this, [=, this]() {
if (!searchBar->hasFocus())
@@ -109,12 +139,10 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
emit cardAdditionRequested(card);
}
});
}
displayOptionsAndSearch = new QWidget(this);
displayOptionsAndSearchLayout = new QHBoxLayout(displayOptionsAndSearch);
displayOptionsAndSearchLayout->setAlignment(Qt::AlignLeft);
displayOptionsAndSearch->setLayout(displayOptionsAndSearchLayout);
void VisualDeckEditorWidget::initializeDisplayOptionsWidget()
{
displayOptionsWidget = new VisualDeckDisplayOptionsWidget(this);
connect(displayOptionsWidget, &VisualDeckDisplayOptionsWidget::displayTypeChanged, this,
&VisualDeckEditorWidget::displayTypeChanged);
@@ -122,11 +150,26 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
&VisualDeckEditorWidget::activeGroupCriteriaChanged);
connect(displayOptionsWidget, &VisualDeckDisplayOptionsWidget::sortCriteriaChanged, this,
&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(searchBar);
displayOptionsAndSearchLayout->addWidget(searchPushButton);
}
void VisualDeckEditorWidget::initializeScrollAreaAndZoneContainer()
{
scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
scrollArea->setMinimumSize(0, 0);
@@ -136,31 +179,19 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
zoneContainer = new QWidget(scrollArea);
zoneContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
zoneContainerLayout = new QVBoxLayout(zoneContainer);
zoneContainer->setLayout(zoneContainerLayout);
scrollArea->addScrollBarWidget(zoneContainer, Qt::AlignHCenter);
scrollArea->setWidget(zoneContainer);
}
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);
void VisualDeckEditorWidget::connectDeckListModel()
{
connect(deckListModel, &DeckListModel::modelReset, this, &VisualDeckEditorWidget::decklistModelReset);
connect(deckListModel, &DeckListModel::dataChanged, this, &VisualDeckEditorWidget::decklistDataChanged);
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &VisualDeckEditorWidget::onCardAddition);
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &VisualDeckEditorWidget::onCardRemoval);
constructZoneWidgetsFromDeckListModel();
if (selectionModel) {
connect(selectionModel, &QItemSelectionModel::selectionChanged, this,
&VisualDeckEditorWidget::onSelectionChanged);
}
retranslateUi();
}
void VisualDeckEditorWidget::retranslateUi()
@@ -171,96 +202,9 @@ void VisualDeckEditorWidget::retranslateUi()
"preferred printing to the deck on pressing enter"));
}
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()
{
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);
}
}
}
// =====================================================================================================================
// Display Widget Management
// =====================================================================================================================
void VisualDeckEditorWidget::constructZoneWidgetForIndex(QPersistentModelIndex persistent)
{
@@ -312,10 +256,58 @@ void VisualDeckEditorWidget::updateZoneWidgets()
{
}
void VisualDeckEditorWidget::resizeEvent(QResizeEvent *event)
void VisualDeckEditorWidget::clearAllDisplayWidgets()
{
QWidget::resizeEvent(event);
zoneContainer->setMaximumWidth(scrollArea->viewport()->width());
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;
}
// =====================================================================================================================
// 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()
@@ -334,6 +326,17 @@ void VisualDeckEditorWidget::decklistDataChanged(QModelIndex topLeft, QModelInde
updateZoneWidgets();
}
// =====================================================================================================================
// User Interaction
// =====================================================================================================================
void VisualDeckEditorWidget::onCardClick(QMouseEvent *event,
CardInfoPictureWithTextOverlayWidget *instance,
QString zoneName)
{
emit cardClicked(event, instance, zoneName);
}
void VisualDeckEditorWidget::onHover(const ExactCard &hoveredCard)
{
// If user has any card selected, ignore hover
@@ -348,9 +351,43 @@ void VisualDeckEditorWidget::onHover(const ExactCard &hoveredCard)
// highlightHoveredCard(hoveredCard);
}
void VisualDeckEditorWidget::onCardClick(QMouseEvent *event,
CardInfoPictureWithTextOverlayWidget *instance,
QString zoneName)
void VisualDeckEditorWidget::setSelectionModel(QItemSelectionModel *model)
{
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);
}
}
}
}

View File

@@ -39,7 +39,6 @@ public:
explicit VisualDeckEditorWidget(QWidget *parent, DeckListModel *deckListModel, QItemSelectionModel *selectionModel);
void retranslateUi();
void clearAllDisplayWidgets();
void resizeEvent(QResizeEvent *event) override;
void setDeckList(const DeckList &_deckListModel);
@@ -70,6 +69,13 @@ signals:
void cardAdditionRequested(const ExactCard &card);
void displayTypeChanged(DisplayType displayType);
protected:
void initializeSearchBarAndCompleter();
void initializeDisplayOptionsWidget();
void initializeDisplayOptionsAndSearchWidget();
void initializeScrollAreaAndZoneContainer();
void connectDeckListModel();
protected slots:
void onHover(const ExactCard &hoveredCard);
void onCardClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *instance, QString zoneName);
@@ -91,7 +97,6 @@ private:
QWidget *zoneContainer;
QVBoxLayout *zoneContainerLayout;
// OverlapControlWidget *overlapControlWidget;
QWidget *container;
QHash<QPersistentModelIndex, QWidget *> indexToWidgetMap;
};