[VDE] Use placeholder image for deck view if deck is empty.

Took 15 minutes

Took 9 seconds

Took 5 seconds
This commit is contained in:
Lukas Brübach 2026-01-14 09:57:25 +01:00
parent 38e73486c1
commit 09ae89d283
4 changed files with 85 additions and 8 deletions

View file

@ -0,0 +1,41 @@
#include "visual_deck_editor_placeholder_widget.h"
VisualDeckEditorPlaceholderWidget::VisualDeckEditorPlaceholderWidget(QWidget *parent) : QWidget(parent)
{
mainLayout = new QVBoxLayout(this);
mainLayout->setAlignment(Qt::AlignCenter);
setLayout(mainLayout);
// Image label with the background image
imageLabel = new QLabel(this);
imageLabel->setAlignment(Qt::AlignCenter);
imageLabel->setStyleSheet(R"(
QLabel {
background-image: url(theme:backgrounds/card_triplet.svg);
background-repeat: no-repeat;
background-position: center;
}
)");
imageLabel->setFixedSize(300, 300);
textLabel = new QLabel(this);
textLabel->setAlignment(Qt::AlignCenter);
textLabel->setWordWrap(true);
textLabel->setStyleSheet(R"(
QLabel {
color: palette(mid);
font-size: 14px;
padding: 10px;
}
)");
mainLayout->addWidget(imageLabel);
mainLayout->addWidget(textLabel);
retranslateUi();
}
void VisualDeckEditorPlaceholderWidget::retranslateUi()
{
textLabel->setText(tr("Add cards using the search bar or database tab to have them appear here"));
}

View file

@ -0,0 +1,22 @@
#ifndef COCKATRICE_VISUAL_DECK_EDITOR_PLACEHOLDER_WIDGET_H
#define COCKATRICE_VISUAL_DECK_EDITOR_PLACEHOLDER_WIDGET_H
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
class VisualDeckEditorPlaceholderWidget : public QWidget
{
Q_OBJECT
public:
explicit VisualDeckEditorPlaceholderWidget(QWidget *parent = nullptr);
void retranslateUi();
private:
QVBoxLayout *mainLayout;
QLabel *imageLabel;
QLabel *textLabel;
};
#endif // COCKATRICE_VISUAL_DECK_EDITOR_PLACEHOLDER_WIDGET_H

View file

@ -59,6 +59,7 @@ VisualDeckEditorWidget::VisualDeckEditorWidget(QWidget *parent,
&VisualDeckEditorWidget::onSelectionChanged);
}
updatePlaceholderVisibility();
retranslateUi();
}
@ -181,15 +182,13 @@ void VisualDeckEditorWidget::initializeScrollAreaAndZoneContainer()
zoneContainer = new QWidget(scrollArea);
zoneContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
zoneContainer->setObjectName("zoneContainer");
zoneContainer->setStyleSheet(R"(
QWidget#zoneContainer {
background-image: url(theme:backgrounds/card_triplet.svg);
background-repeat: no-repeat;
background-position: center;
}
)");
zoneContainerLayout = new QVBoxLayout(zoneContainer);
zoneContainer->setLayout(zoneContainerLayout);
// Create placeholder widget
placeholderWidget = new VisualDeckEditorPlaceholderWidget(zoneContainer);
zoneContainerLayout->addWidget(placeholderWidget);
scrollArea->addScrollBarWidget(zoneContainer, Qt::AlignHCenter);
scrollArea->setWidget(zoneContainer);
}
@ -208,6 +207,17 @@ void VisualDeckEditorWidget::retranslateUi()
searchPushButton->setText(tr("Quick search and add card"));
searchPushButton->setToolTip(tr("Search for closest match in the database (with auto-suggestions) and add "
"preferred printing to the deck on pressing enter"));
if (placeholderWidget) {
placeholderWidget->retranslateUi();
}
}
void VisualDeckEditorWidget::updatePlaceholderVisibility()
{
if (placeholderWidget) {
placeholderWidget->setVisible(indexToWidgetMap.isEmpty());
}
}
// =====================================================================================================================
@ -258,6 +268,7 @@ void VisualDeckEditorWidget::constructZoneWidgetsFromDeckListModel()
constructZoneWidgetForIndex(persistent);
}
updatePlaceholderVisibility();
}
void VisualDeckEditorWidget::updateZoneWidgets()

View file

@ -11,6 +11,7 @@
#include "../cards/card_size_widget.h"
#include "../general/layout_containers/overlap_control_widget.h"
#include "../quick_settings/settings_button_widget.h"
#include "visual_deck_editor_placeholder_widget.h"
#include <QCheckBox>
#include <QListWidget>
@ -44,6 +45,7 @@ public:
void setSelectionModel(QItemSelectionModel *model);
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void updatePlaceholderVisibility();
QItemSelectionModel *getSelectionModel() const
{
return selectionModel;
@ -96,6 +98,7 @@ private:
QScrollArea *scrollArea;
QWidget *zoneContainer;
QVBoxLayout *zoneContainerLayout;
VisualDeckEditorPlaceholderWidget *placeholderWidget;
// OverlapControlWidget *overlapControlWidget;
QHash<QPersistentModelIndex, QWidget *> indexToWidgetMap;
};