mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-09 01:23:57 -07:00
[ColorIdentityWidget] Refactor and add setter
This commit is contained in:
parent
ed1115f4c0
commit
3e9d1e18a6
2 changed files with 17 additions and 27 deletions
|
|
@ -9,29 +9,8 @@
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
|
||||||
ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, CardInfoPtr _card) : QWidget(parent), card(_card)
|
ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, const QString &_manaCost)
|
||||||
{
|
: QWidget(parent), manaCost(_manaCost)
|
||||||
layout = new QHBoxLayout(this);
|
|
||||||
layout->setSpacing(5); // Small spacing between icons
|
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
layout->setAlignment(Qt::AlignCenter); // Ensure icons are centered
|
|
||||||
setLayout(layout);
|
|
||||||
|
|
||||||
// Define the full WUBRG set (White, Blue, Black, Red, Green)
|
|
||||||
QString fullColorIdentity = "WUBRG";
|
|
||||||
|
|
||||||
if (card) {
|
|
||||||
manaCost = card->getColors(); // Get mana cost string
|
|
||||||
QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string
|
|
||||||
|
|
||||||
populateManaSymbolWidgets();
|
|
||||||
}
|
|
||||||
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageDrawUnusedColorIdentitiesChanged, this,
|
|
||||||
&ColorIdentityWidget::toggleUnusedVisibility);
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, QString _manaCost)
|
|
||||||
: QWidget(parent), card(nullptr), manaCost(_manaCost)
|
|
||||||
{
|
{
|
||||||
layout = new QHBoxLayout(this);
|
layout = new QHBoxLayout(this);
|
||||||
layout->setSpacing(5); // Small spacing between icons
|
layout->setSpacing(5); // Small spacing between icons
|
||||||
|
|
@ -51,6 +30,12 @@ void ColorIdentityWidget::populateManaSymbolWidgets()
|
||||||
QString fullColorIdentity = "WUBRG";
|
QString fullColorIdentity = "WUBRG";
|
||||||
QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string
|
QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string
|
||||||
|
|
||||||
|
// clear old layout
|
||||||
|
for (auto widgets : layout->findChildren<ManaSymbolWidget *>()) {
|
||||||
|
widgets->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
// populate mana symbols
|
||||||
if (SettingsCache::instance().getVisualDeckStorageDrawUnusedColorIdentities()) {
|
if (SettingsCache::instance().getVisualDeckStorageDrawUnusedColorIdentities()) {
|
||||||
for (const QString symbol : fullColorIdentity) {
|
for (const QString symbol : fullColorIdentity) {
|
||||||
auto *manaSymbol = new ManaSymbolWidget(this, symbol, symbols.contains(symbol));
|
auto *manaSymbol = new ManaSymbolWidget(this, symbol, symbols.contains(symbol));
|
||||||
|
|
@ -64,6 +49,12 @@ void ColorIdentityWidget::populateManaSymbolWidgets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ColorIdentityWidget::setColorIdentity(const QString &manaString)
|
||||||
|
{
|
||||||
|
manaCost = manaString;
|
||||||
|
populateManaSymbolWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
void ColorIdentityWidget::toggleUnusedVisibility()
|
void ColorIdentityWidget::toggleUnusedVisibility()
|
||||||
{
|
{
|
||||||
if (layout != nullptr) {
|
if (layout != nullptr) {
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,17 @@ class ColorIdentityWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ColorIdentityWidget(QWidget *parent, CardInfoPtr card);
|
explicit ColorIdentityWidget(QWidget *parent, const QString &manaCost = "");
|
||||||
explicit ColorIdentityWidget(QWidget *parent, QString manaCost);
|
|
||||||
void populateManaSymbolWidgets();
|
void populateManaSymbolWidgets();
|
||||||
|
|
||||||
QStringList parseColorIdentity(const QString &manaString);
|
static QStringList parseColorIdentity(const QString &manaString);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void setColorIdentity(const QString &manaString);
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
void toggleUnusedVisibility();
|
void toggleUnusedVisibility();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CardInfoPtr card;
|
|
||||||
QString manaCost;
|
QString manaCost;
|
||||||
QHBoxLayout *layout;
|
QHBoxLayout *layout;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue