get icon to work

This commit is contained in:
RickyRister 2025-02-08 21:40:30 -08:00
parent 00fc59f572
commit 68482935f5
2 changed files with 20 additions and 3 deletions

View file

@ -1,5 +1,7 @@
#include "banner_widget.h"
#include "../../../../../client/ui/pixel_map_generator.h"
#include <QLinearGradient>
#include <QMouseEvent>
#include <QPainter>
@ -8,14 +10,20 @@
BannerWidget::BannerWidget(QWidget *parent, const QString &text, Qt::Orientation orientation, int transparency)
: QWidget(parent), gradientOrientation(orientation), transparency(qBound(0, transparency, 100))
{
auto layout = new QHBoxLayout(this);
iconLabel = new QLabel(this);
iconLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
setExpandIconState(true);
// Create the banner label and set properties
bannerLabel = new QLabel(text, this);
bannerLabel->setAlignment(Qt::AlignCenter);
bannerLabel->setStyleSheet("font-size: 24px; font-weight: bold; color: white;");
// Layout to center the banner label
layout = new QVBoxLayout(this);
layout->addWidget(iconLabel);
layout->addWidget(bannerLabel);
layout->addWidget(new QLabel(this)); // add dummy label to force text label to be centered
setLayout(layout);
// Set minimum height for the widget
@ -40,9 +48,17 @@ void BannerWidget::toggleBuddyVisibility() const
{
if (buddy) {
buddy->setVisible(!buddy->isVisible());
setExpandIconState(buddy->isVisible());
} else {
setExpandIconState(false);
}
}
void BannerWidget::setExpandIconState(bool expanded) const
{
iconLabel->setPixmap(ExpandIconPixmapGenerator::generatePixmap(24, expanded));
}
void BannerWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);

View file

@ -33,7 +33,7 @@ protected:
void paintEvent(QPaintEvent *event) override;
private:
QVBoxLayout *layout;
QLabel *iconLabel;
QLabel *bannerLabel;
Qt::Orientation gradientOrientation;
int transparency; // Transparency percentage for the gradient
@ -43,6 +43,7 @@ signals:
void buddyVisibilityChanged();
private slots:
void toggleBuddyVisibility() const;
void setExpandIconState(bool expanded) const;
};
#endif // BANNER_WIDGET_H