From a69bfb8cb88aa4fcea23e624bccfbf31b41d94f4 Mon Sep 17 00:00:00 2001 From: ebbit1q Date: Fri, 3 Oct 2025 04:55:18 +0200 Subject: [PATCH] add scroll bar to properties in cardinfotextwidget (#6201) * add scroll bar to properties in cardinfotextwidget * remove resizeevent trigger --- .../widgets/cards/card_info_text_widget.cpp | 49 +++++++++++++------ .../widgets/cards/card_info_text_widget.h | 5 +- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/cockatrice/src/interface/widgets/cards/card_info_text_widget.cpp b/cockatrice/src/interface/widgets/cards/card_info_text_widget.cpp index 3d99d4fc9..8a4b26eb6 100644 --- a/cockatrice/src/interface/widgets/cards/card_info_text_widget.cpp +++ b/cockatrice/src/interface/widgets/cards/card_info_text_widget.cpp @@ -6,32 +6,55 @@ #include #include +#include +#include +#include #include CardInfoTextWidget::CardInfoTextWidget(QWidget *parent) : QFrame(parent), info(nullptr) { - nameLabel = new QLabel; - nameLabel->setOpenExternalLinks(false); - nameLabel->setWordWrap(true); - connect(nameLabel, SIGNAL(linkActivated(const QString &)), this, SIGNAL(linkActivated(const QString &))); + propsLabel = new QLabel; + propsLabel->setOpenExternalLinks(false); + propsLabel->setWordWrap(true); + connect(propsLabel, SIGNAL(linkActivated(const QString &)), this, SIGNAL(linkActivated(const QString &))); textLabel = new QTextEdit(); textLabel->setReadOnly(true); + textLabel->setMinimumSize(35, 35); + + propsScroll = new QScrollArea(this); + propsScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + propsScroll->setWidgetResizable(true); + propsScroll->setAlignment(Qt::AlignLeft | Qt::AlignTop); + propsScroll->setContentsMargins(0, 0, 0, 0); + propsScroll->setFrameStyle(QFrame::NoFrame); + propsScroll->setWidget(propsLabel); + + // blend into normal background color, note that themes may override this! + propsScroll->viewport()->setStyleSheet("QWidget{background: transparent}"); auto *grid = new QGridLayout(this); - grid->addWidget(nameLabel, 0, 0); - grid->addWidget(textLabel, 1, 0, -1, 2); + grid->addWidget(propsScroll, 0, 0); + grid->addWidget(textLabel, 1, 0); + grid->setRowStretch(0, 2); grid->setRowStretch(1, 1); - grid->setColumnStretch(1, 1); retranslateUi(); } +void CardInfoTextWidget::setTexts(const QString &propsText, const QString &textText) +{ + propsScroll->setMaximumHeight(0); // reset the max height, otherwise the scrollbar will blink in and out sometimes + propsLabel->setText(propsText); + propsScroll->setMinimumWidth(propsLabel->minimumWidth() + propsScroll->verticalScrollBar()->width()); + propsScroll->setMaximumHeight(propsLabel->sizeHint().height()); + textLabel->setText(textText); +} + void CardInfoTextWidget::setCard(CardInfoPtr card) { if (card == nullptr) { - nameLabel->setText(""); - textLabel->setText(""); + setTexts("", ""); return; } @@ -61,14 +84,12 @@ void CardInfoTextWidget::setCard(CardInfoPtr card) } text += ""; - nameLabel->setText(text); - textLabel->setText(card->getText()); + setTexts(text, card->getText()); } void CardInfoTextWidget::setInvalidCardName(const QString &cardName) { - nameLabel->setText(tr("Unknown card:") + " " + cardName); - textLabel->setText(""); + setTexts(tr("Unknown card:") + " " + cardName, ""); } void CardInfoTextWidget::retranslateUi() @@ -77,5 +98,5 @@ void CardInfoTextWidget::retranslateUi() * There's no way we can really translate the text currently being rendered. * The best we can do is invalidate the current text. */ - setInvalidCardName(""); + setTexts("", ""); } diff --git a/cockatrice/src/interface/widgets/cards/card_info_text_widget.h b/cockatrice/src/interface/widgets/cards/card_info_text_widget.h index bd161dc22..d3cba8994 100644 --- a/cockatrice/src/interface/widgets/cards/card_info_text_widget.h +++ b/cockatrice/src/interface/widgets/cards/card_info_text_widget.h @@ -11,6 +11,7 @@ #include class QLabel; +class QScrollArea; class QTextEdit; class CardInfoTextWidget : public QFrame @@ -18,9 +19,11 @@ class CardInfoTextWidget : public QFrame Q_OBJECT private: - QLabel *nameLabel; + QLabel *propsLabel; + QScrollArea *propsScroll; QTextEdit *textLabel; CardInfoPtr info; + void setTexts(const QString &propsText, const QString &textText); public: explicit CardInfoTextWidget(QWidget *parent = nullptr);