New utility display widgets.

This commit is contained in:
Brübach, Lukas 2025-11-25 09:37:37 +01:00
parent 2867fbabe6
commit 45c599cae9
9 changed files with 364 additions and 0 deletions

View file

@ -0,0 +1,65 @@
#include "archidekt_deck_preview_image_display_widget.h"
#include <QFontMetrics>
#include <QPainter>
ArchidektDeckPreviewImageDisplayWidget::ArchidektDeckPreviewImageDisplayWidget(QWidget *parent) : QWidget(parent)
{
imageLabel = new QLabel(this);
imageLabel->setAlignment(Qt::AlignCenter);
topLeftLabel = new OverlayLabel(this);
topRightLabel = new OverlayLabel(this);
bottomLeftLabel = new OverlayLabel(this);
bottomRightLabel = new OverlayLabel(this);
QFont f;
f.setBold(true);
topLeftLabel->setFont(f);
topRightLabel->setFont(f);
bottomLeftLabel->setFont(f);
bottomRightLabel->setFont(f);
// Raise so labels appear above image
topLeftLabel->raise();
topRightLabel->raise();
bottomLeftLabel->raise();
bottomRightLabel->raise();
}
void ArchidektDeckPreviewImageDisplayWidget::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
// Full size for the image
imageLabel->setGeometry(rect());
topLeftLabel->adjustSize();
topRightLabel->adjustSize();
bottomLeftLabel->adjustSize();
bottomRightLabel->adjustSize();
// Padding settings
const int horizontalPadding = 8;
const int topPadding = 6;
const int bottomPadding = 6;
// Left-aligned, top-aligned (Deck Name)
topLeftLabel->move(horizontalPadding, topPadding);
// Right-aligned, top-aligned (Card Count)
topRightLabel->move(width() - topRightLabel->width() - horizontalPadding, topPadding);
// Bottom-left, bottom-aligned (EDH bracket)
bottomLeftLabel->move(horizontalPadding, height() - bottomLeftLabel->height() - bottomPadding);
// Bottom-right, bottom-aligned (views)
bottomRightLabel->move(width() - bottomRightLabel->width() - horizontalPadding,
height() - bottomRightLabel->height() - bottomPadding);
// Ensure labels stay above image
topLeftLabel->raise();
topRightLabel->raise();
bottomLeftLabel->raise();
bottomRightLabel->raise();
}

View file

@ -0,0 +1,29 @@
//
// Created by Ascor on 25-Nov-25.
//
#ifndef COCKATRICE_ARCHIDEKT_DECK_PREVIEW_IMAGE_DISPLAY_WIDGET_H
#define COCKATRICE_ARCHIDEKT_DECK_PREVIEW_IMAGE_DISPLAY_WIDGET_H
#include "../../../../general/display/overlay_label.h"
#include <QLabel>
#include <QWidget>
class ArchidektDeckPreviewImageDisplayWidget : public QWidget
{
Q_OBJECT
public:
explicit ArchidektDeckPreviewImageDisplayWidget(QWidget *parent = nullptr);
QLabel *imageLabel;
OverlayLabel *topLeftLabel;
OverlayLabel *topRightLabel;
OverlayLabel *bottomLeftLabel;
OverlayLabel *bottomRightLabel;
protected:
void resizeEvent(QResizeEvent *event) override;
};
#endif // COCKATRICE_ARCHIDEKT_DECK_PREVIEW_IMAGE_DISPLAY_WIDGET_H