From a7e8c1f59bff280ed481fbd06db95e17af6639b6 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Sun, 2 Mar 2025 06:26:03 -0800 Subject: [PATCH] Make BannerWidget's dropdown icon more robust (#5676) * Make BannerWidget's dropdown icon more robust * use isHidden Otherwise, it doesn't work correctly if the BannerWidget is offscreen * don't show icon if there's no buddy --- .../widgets/general/display/banner_widget.cpp | 20 ++++++++++++------- .../widgets/general/display/banner_widget.h | 7 ++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp b/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp index abed4bac5..1d70a72b5 100644 --- a/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp +++ b/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp @@ -28,6 +28,8 @@ BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation // Set minimum height for the widget setMinimumHeight(50); connect(this, &BannerWidget::buddyVisibilityChanged, this, &BannerWidget::toggleBuddyVisibility); + + updateDropdownIconState(); } void BannerWidget::mousePressEvent(QMouseEvent *event) @@ -46,23 +48,27 @@ void BannerWidget::setText(const QString &text) const void BannerWidget::setClickable(bool _clickable) { clickable = _clickable; - setDropdownIconState(true); + updateDropdownIconState(); +} + +void BannerWidget::setBuddy(QWidget *_buddy) +{ + buddy = _buddy; + updateDropdownIconState(); } void BannerWidget::toggleBuddyVisibility() const { if (buddy) { buddy->setVisible(!buddy->isVisible()); - setDropdownIconState(buddy->isVisible()); - } else { - setDropdownIconState(false); + updateDropdownIconState(); } } -void BannerWidget::setDropdownIconState(bool expanded) const +void BannerWidget::updateDropdownIconState() const { - if (clickable) { - iconLabel->setPixmap(DropdownIconPixmapGenerator::generatePixmap(24, expanded)); + if (clickable && buddy) { + iconLabel->setPixmap(DropdownIconPixmapGenerator::generatePixmap(24, !buddy->isHidden())); } else { // we cannot directly hide the iconLabel, since it's needed to center the text; set an empty image instead iconLabel->setPixmap(QPixmap()); diff --git a/cockatrice/src/client/ui/widgets/general/display/banner_widget.h b/cockatrice/src/client/ui/widgets/general/display/banner_widget.h index 552e5ea98..fa842cb44 100644 --- a/cockatrice/src/client/ui/widgets/general/display/banner_widget.h +++ b/cockatrice/src/client/ui/widgets/general/display/banner_widget.h @@ -17,10 +17,7 @@ public: void mousePressEvent(QMouseEvent *event) override; void setText(const QString &text) const; void setClickable(bool _clickable); - void setBuddy(QWidget *_buddy) - { - buddy = _buddy; - } + void setBuddy(QWidget *_buddy); QString getText() const { return bannerLabel->text(); @@ -40,7 +37,7 @@ signals: void buddyVisibilityChanged(); private slots: void toggleBuddyVisibility() const; - void setDropdownIconState(bool expanded) const; + void updateDropdownIconState() const; }; #endif // BANNER_WIDGET_H