mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -07:00
move pic and button into a single widget
This commit is contained in:
parent
d03be7eba5
commit
ed9744c7aa
2 changed files with 100 additions and 23 deletions
|
|
@ -11,23 +11,84 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
CardPictureAndButtonWidget::CardPictureAndButtonWidget(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
auto *mainLayout = new QVBoxLayout();
|
||||||
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
mainLayout->setSpacing(0);
|
||||||
|
setLayout(mainLayout);
|
||||||
|
|
||||||
|
pic = new CardInfoPictureWidget();
|
||||||
|
pic->setObjectName("pic");
|
||||||
|
connect(pic, &CardInfoPictureWidget::cardChanged, this, [this](auto card) { emit cardChanged(card); });
|
||||||
|
|
||||||
|
setMinimumHeight(pic->minimumHeight());
|
||||||
|
|
||||||
|
layout()->addWidget(pic);
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardPictureAndButtonWidget::retranslateUi()
|
||||||
|
{
|
||||||
|
if (viewTransformationButton) {
|
||||||
|
viewTransformationButton->setText(tr("View transformation"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton *CardPictureAndButtonWidget::createViewTransformationButton()
|
||||||
|
{
|
||||||
|
auto *pushButton = new QPushButton();
|
||||||
|
pushButton->setObjectName("viewTransformationButton");
|
||||||
|
pushButton->setContentsMargins(0, 0, 0, 0);
|
||||||
|
connect(pushButton, &QPushButton::clicked, this, [this] { emit transformationButtonClicked(); });
|
||||||
|
return pushButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardPictureAndButtonWidget::setTransformButtonVisibility(bool visible)
|
||||||
|
{
|
||||||
|
if (visible && !viewTransformationButton) {
|
||||||
|
viewTransformationButton = createViewTransformationButton();
|
||||||
|
layout()->addWidget(viewTransformationButton);
|
||||||
|
retranslateUi();
|
||||||
|
} else if (!visible && viewTransformationButton) {
|
||||||
|
layout()->removeWidget(viewTransformationButton);
|
||||||
|
viewTransformationButton->deleteLater();
|
||||||
|
viewTransformationButton = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool hasTransformation(const CardInfoPtr &info)
|
||||||
|
{
|
||||||
|
if (!info) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &relatedCards = info->getAllRelatedCards();
|
||||||
|
return std::any_of(relatedCards.cbegin(), relatedCards.cend(),
|
||||||
|
[](const auto &cardRelation) { return cardRelation->getDoesTransform(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardPictureAndButtonWidget::setCard(const CardInfoPtr &card)
|
||||||
|
{
|
||||||
|
pic->setCard(card);
|
||||||
|
setTransformButtonVisibility(hasTransformation(card));
|
||||||
|
}
|
||||||
|
|
||||||
CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *parent)
|
CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *parent)
|
||||||
: QTabWidget(parent), info(nullptr), cardTextOnly(false)
|
: QTabWidget(parent), info(nullptr), cardTextOnly(false)
|
||||||
{
|
{
|
||||||
setContentsMargins(3, 3, 3, 3);
|
setContentsMargins(3, 3, 3, 3);
|
||||||
pic = new CardInfoPictureWidget();
|
pic = new CardPictureAndButtonWidget();
|
||||||
pic->setObjectName("pic");
|
pic->setObjectName("pic");
|
||||||
connect(pic, &CardInfoPictureWidget::cardChanged, this, qOverload<CardInfoPtr>(&CardInfoFrameWidget::setCard));
|
connect(pic, &CardPictureAndButtonWidget::cardChanged, this, qOverload<CardInfoPtr>(&CardInfoFrameWidget::setCard));
|
||||||
|
connect(pic, &CardPictureAndButtonWidget::transformationButtonClicked, this,
|
||||||
|
&CardInfoFrameWidget::viewTransformation);
|
||||||
|
|
||||||
text = new CardInfoTextWidget();
|
text = new CardInfoTextWidget();
|
||||||
text->setObjectName("text");
|
text->setObjectName("text");
|
||||||
connect(text, SIGNAL(linkActivated(const QString &)), this, SLOT(setCard(const QString &)));
|
connect(text, SIGNAL(linkActivated(const QString &)), this, SLOT(setCard(const QString &)));
|
||||||
|
|
||||||
viewTransformationButton = new QPushButton();
|
|
||||||
viewTransformationButton->setObjectName("viewTransformationButton");
|
|
||||||
connect(viewTransformationButton, &QPushButton::clicked, this, &CardInfoFrameWidget::viewTransformation);
|
|
||||||
viewTransformationButton->setHidden(true);
|
|
||||||
|
|
||||||
tab1 = new QWidget(this);
|
tab1 = new QWidget(this);
|
||||||
tab2 = new QWidget(this);
|
tab2 = new QWidget(this);
|
||||||
tab3 = new QWidget(this);
|
tab3 = new QWidget(this);
|
||||||
|
|
@ -74,7 +135,6 @@ void CardInfoFrameWidget::retranslateUi()
|
||||||
setTabText(ImageOnlyView, tr("Image"));
|
setTabText(ImageOnlyView, tr("Image"));
|
||||||
setTabText(TextOnlyView, tr("Description"));
|
setTabText(TextOnlyView, tr("Description"));
|
||||||
setTabText(ImageAndTextView, tr("Both"));
|
setTabText(ImageAndTextView, tr("Both"));
|
||||||
viewTransformationButton->setText(tr("View transformation"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoFrameWidget::setViewMode(int mode)
|
void CardInfoFrameWidget::setViewMode(int mode)
|
||||||
|
|
@ -91,12 +151,10 @@ void CardInfoFrameWidget::setViewMode(int mode)
|
||||||
case ImageOnlyView:
|
case ImageOnlyView:
|
||||||
case TextOnlyView:
|
case TextOnlyView:
|
||||||
tab1Layout->addWidget(pic);
|
tab1Layout->addWidget(pic);
|
||||||
tab1Layout->addWidget(viewTransformationButton);
|
|
||||||
tab2Layout->addWidget(text);
|
tab2Layout->addWidget(text);
|
||||||
break;
|
break;
|
||||||
case ImageAndTextView:
|
case ImageAndTextView:
|
||||||
splitter->addWidget(pic);
|
splitter->addWidget(pic);
|
||||||
splitter->addWidget(viewTransformationButton);
|
|
||||||
splitter->addWidget(text);
|
splitter->addWidget(text);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -108,7 +166,6 @@ void CardInfoFrameWidget::setViewMode(int mode)
|
||||||
|
|
||||||
void CardInfoFrameWidget::setCard(CardInfoPtr card)
|
void CardInfoFrameWidget::setCard(CardInfoPtr card)
|
||||||
{
|
{
|
||||||
viewTransformationButton->setHidden(true);
|
|
||||||
if (info) {
|
if (info) {
|
||||||
disconnect(info.data(), nullptr, this, nullptr);
|
disconnect(info.data(), nullptr, this, nullptr);
|
||||||
}
|
}
|
||||||
|
|
@ -119,16 +176,6 @@ void CardInfoFrameWidget::setCard(CardInfoPtr card)
|
||||||
connect(info.data(), SIGNAL(destroyed()), this, SLOT(clearCard()));
|
connect(info.data(), SIGNAL(destroyed()), this, SLOT(clearCard()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info) {
|
|
||||||
const auto &cardRelations = info->getAllRelatedCards();
|
|
||||||
for (const auto &cardRelation : cardRelations) {
|
|
||||||
if (cardRelation->getDoesTransform()) {
|
|
||||||
viewTransformationButton->setHidden(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
text->setCard(info);
|
text->setCard(info);
|
||||||
pic->setCard(info);
|
pic->setCard(info);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,44 @@ class CardInfoTextWidget;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This widget contains the CardInfoPictureWidget and the "view transformation" button.
|
||||||
|
*
|
||||||
|
* Simply hiding the button will still leave a small gap at the bottom of the CardInfoPictureWidget.
|
||||||
|
* This widget deletes the button when it's not relevant in order to not leave any spaces.
|
||||||
|
*/
|
||||||
|
class CardPictureAndButtonWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
CardInfoPictureWidget *pic;
|
||||||
|
QPushButton *viewTransformationButton;
|
||||||
|
|
||||||
|
QPushButton *createViewTransformationButton();
|
||||||
|
void setTransformButtonVisibility(bool visible);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CardPictureAndButtonWidget(QWidget *parent = nullptr);
|
||||||
|
void retranslateUi();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setCard(const CardInfoPtr &card);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
* Forwarded from CardInfoPictureWidget::cardChanged
|
||||||
|
*/
|
||||||
|
void cardChanged(CardInfoPtr card);
|
||||||
|
void transformationButtonClicked();
|
||||||
|
};
|
||||||
|
|
||||||
class CardInfoFrameWidget : public QTabWidget
|
class CardInfoFrameWidget : public QTabWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
CardInfoPtr info;
|
CardInfoPtr info;
|
||||||
CardInfoPictureWidget *pic;
|
CardPictureAndButtonWidget *pic;
|
||||||
CardInfoTextWidget *text;
|
CardInfoTextWidget *text;
|
||||||
QPushButton *viewTransformationButton;
|
|
||||||
bool cardTextOnly;
|
bool cardTextOnly;
|
||||||
QWidget *tab1, *tab2, *tab3;
|
QWidget *tab1, *tab2, *tab3;
|
||||||
QVBoxLayout *tab1Layout, *tab2Layout, *tab3Layout;
|
QVBoxLayout *tab1Layout, *tab2Layout, *tab3Layout;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue