mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-23 15:13:55 -07:00
Remove spacing in CardInfoWidget caused by invisible view transformation button (#5510)
This commit is contained in:
parent
420cca2402
commit
af161f00b7
2 changed files with 61 additions and 23 deletions
|
|
@ -12,7 +12,7 @@
|
|||
#include <utility>
|
||||
|
||||
CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *parent)
|
||||
: QTabWidget(parent), info(nullptr), cardTextOnly(false)
|
||||
: QTabWidget(parent), info(nullptr), viewTransformationButton(nullptr), cardTextOnly(false)
|
||||
{
|
||||
setContentsMargins(3, 3, 3, 3);
|
||||
pic = new CardInfoPictureWidget();
|
||||
|
|
@ -23,11 +23,6 @@ CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *paren
|
|||
text->setObjectName("text");
|
||||
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->setVisible(false);
|
||||
|
||||
tab1 = new QWidget(this);
|
||||
tab2 = new QWidget(this);
|
||||
tab3 = new QWidget(this);
|
||||
|
|
@ -74,36 +69,84 @@ void CardInfoFrameWidget::retranslateUi()
|
|||
setTabText(ImageOnlyView, tr("Image"));
|
||||
setTabText(TextOnlyView, tr("Description"));
|
||||
setTabText(ImageAndTextView, tr("Both"));
|
||||
viewTransformationButton->setText(tr("View transformation"));
|
||||
|
||||
if (viewTransformationButton) {
|
||||
viewTransformationButton->setText(tr("View transformation"));
|
||||
}
|
||||
}
|
||||
|
||||
void CardInfoFrameWidget::setViewMode(int mode)
|
||||
void CardInfoFrameWidget::setViewTransformationButtonVisibility(bool visible)
|
||||
{
|
||||
if (currentIndex() != mode)
|
||||
setCurrentIndex(mode);
|
||||
if (!viewTransformationButton && visible) {
|
||||
viewTransformationButton = new QPushButton();
|
||||
viewTransformationButton->setObjectName("viewTransformationButton");
|
||||
connect(viewTransformationButton, &QPushButton::clicked, this, &CardInfoFrameWidget::viewTransformation);
|
||||
refreshLayout();
|
||||
} else if (viewTransformationButton && !visible) {
|
||||
// Deleting a widget automatically removes it from its parent
|
||||
viewTransformationButton->deleteLater();
|
||||
viewTransformationButton = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
/**
|
||||
* Adds the widgets to the layouts that are relevant to the currently active tab.
|
||||
*
|
||||
* QWidgets can only have one parent, so we need to re-parent the shared widgets whenever we switch tabs.
|
||||
*/
|
||||
void CardInfoFrameWidget::refreshLayout()
|
||||
{
|
||||
switch (currentIndex()) {
|
||||
case ImageOnlyView:
|
||||
case TextOnlyView:
|
||||
// We need to always parent all widgets, even the ones that aren't visible,
|
||||
// since an unparented widget becomes free-floating.
|
||||
tab1Layout->addWidget(pic);
|
||||
tab1Layout->addWidget(viewTransformationButton);
|
||||
if (viewTransformationButton) {
|
||||
tab1Layout->addWidget(viewTransformationButton);
|
||||
}
|
||||
tab2Layout->addWidget(text);
|
||||
break;
|
||||
case ImageAndTextView:
|
||||
splitter->addWidget(pic);
|
||||
splitter->addWidget(viewTransformationButton);
|
||||
if (viewTransformationButton) {
|
||||
splitter->addWidget(viewTransformationButton);
|
||||
}
|
||||
splitter->addWidget(text);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void CardInfoFrameWidget::setViewMode(int mode)
|
||||
{
|
||||
if (currentIndex() != mode) {
|
||||
setCurrentIndex(mode);
|
||||
}
|
||||
|
||||
refreshLayout();
|
||||
|
||||
SettingsCache::instance().setCardInfoViewMode(mode);
|
||||
}
|
||||
|
||||
static bool hasTransformation(const CardInfoPtr &info)
|
||||
{
|
||||
if (!info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto &cardRelation : info->getAllRelatedCards()) {
|
||||
if (cardRelation->getDoesTransform()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CardInfoFrameWidget::setCard(CardInfoPtr card)
|
||||
{
|
||||
viewTransformationButton->setVisible(false);
|
||||
if (info) {
|
||||
disconnect(info.data(), nullptr, this, nullptr);
|
||||
}
|
||||
|
|
@ -114,15 +157,7 @@ void CardInfoFrameWidget::setCard(CardInfoPtr card)
|
|||
connect(info.data(), SIGNAL(destroyed()), this, SLOT(clearCard()));
|
||||
}
|
||||
|
||||
if (info) {
|
||||
const auto &cardRelations = info->getAllRelatedCards();
|
||||
for (const auto &cardRelation : cardRelations) {
|
||||
if (cardRelation->getDoesTransform()) {
|
||||
viewTransformationButton->setVisible(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
setViewTransformationButtonVisibility(hasTransformation(info));
|
||||
|
||||
text->setCard(info);
|
||||
pic->setCard(info);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ private:
|
|||
QVBoxLayout *tab1Layout, *tab2Layout, *tab3Layout;
|
||||
QSplitter *splitter;
|
||||
|
||||
void setViewTransformationButtonVisibility(bool visible);
|
||||
void refreshLayout();
|
||||
|
||||
public:
|
||||
enum ViewMode
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue