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

View file

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