Make BannerWidget's dropdown icon more robust

This commit is contained in:
RickyRister 2025-03-02 01:55:33 -08:00
parent ec452aabe2
commit fbbfe4f794
2 changed files with 14 additions and 10 deletions

View file

@ -28,6 +28,8 @@ BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation
// Set minimum height for the widget // Set minimum height for the widget
setMinimumHeight(50); setMinimumHeight(50);
connect(this, &BannerWidget::buddyVisibilityChanged, this, &BannerWidget::toggleBuddyVisibility); connect(this, &BannerWidget::buddyVisibilityChanged, this, &BannerWidget::toggleBuddyVisibility);
updateDropdownIconState();
} }
void BannerWidget::mousePressEvent(QMouseEvent *event) void BannerWidget::mousePressEvent(QMouseEvent *event)
@ -46,22 +48,27 @@ void BannerWidget::setText(const QString &text) const
void BannerWidget::setClickable(bool _clickable) void BannerWidget::setClickable(bool _clickable)
{ {
clickable = _clickable; clickable = _clickable;
setDropdownIconState(true); updateDropdownIconState();
}
void BannerWidget::setBuddy(QWidget *_buddy)
{
buddy = _buddy;
updateDropdownIconState();
} }
void BannerWidget::toggleBuddyVisibility() const void BannerWidget::toggleBuddyVisibility() const
{ {
if (buddy) { if (buddy) {
buddy->setVisible(!buddy->isVisible()); buddy->setVisible(!buddy->isVisible());
setDropdownIconState(buddy->isVisible()); updateDropdownIconState();
} else {
setDropdownIconState(false);
} }
} }
void BannerWidget::setDropdownIconState(bool expanded) const void BannerWidget::updateDropdownIconState() const
{ {
if (clickable) { if (clickable) {
bool expanded = buddy && buddy->isVisible();
iconLabel->setPixmap(DropdownIconPixmapGenerator::generatePixmap(24, expanded)); iconLabel->setPixmap(DropdownIconPixmapGenerator::generatePixmap(24, expanded));
} else { } else {
// we cannot directly hide the iconLabel, since it's needed to center the text; set an empty image instead // we cannot directly hide the iconLabel, since it's needed to center the text; set an empty image instead

View file

@ -17,10 +17,7 @@ public:
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
void setText(const QString &text) const; void setText(const QString &text) const;
void setClickable(bool _clickable); void setClickable(bool _clickable);
void setBuddy(QWidget *_buddy) void setBuddy(QWidget *_buddy);
{
buddy = _buddy;
}
QString getText() const QString getText() const
{ {
return bannerLabel->text(); return bannerLabel->text();
@ -40,7 +37,7 @@ signals:
void buddyVisibilityChanged(); void buddyVisibilityChanged();
private slots: private slots:
void toggleBuddyVisibility() const; void toggleBuddyVisibility() const;
void setDropdownIconState(bool expanded) const; void updateDropdownIconState() const;
}; };
#endif // BANNER_WIDGET_H #endif // BANNER_WIDGET_H