Add folder dropdown icons to VDS (#5632)

* add svg

* update pixmap cache

* get icon to work

* hide icon when not clickable

* use consistent naming

* use expandOnly because apparently that leads to higher image quality
This commit is contained in:
RickyRister 2025-02-25 15:36:48 -08:00 committed by GitHub
parent 4543038fd8
commit 6f5d369416
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 82 additions and 8 deletions

View file

@ -357,6 +357,21 @@ QPixmap LockPixmapGenerator::generatePixmap(int height)
QMap<int, QPixmap> LockPixmapGenerator::pmCache;
QPixmap DropdownIconPixmapGenerator::generatePixmap(int height, bool expanded)
{
QString key = QString::number(expanded) + ":" + QString::number(height);
if (pmCache.contains(key))
return pmCache.value(key);
QString name = expanded ? "dropdown_expanded" : "dropdown_collapsed";
QPixmap pixmap = tryLoadImage("theme:icons/" + name, QSize(height, height), true);
pmCache.insert(key, pixmap);
return pixmap;
}
QMap<QString, QPixmap> DropdownIconPixmapGenerator::pmCache;
QPixmap loadColorAdjustedPixmap(const QString &name)
{
if (qApp->palette().windowText().color().lightness() > 200) {

View file

@ -106,6 +106,19 @@ public:
}
};
class DropdownIconPixmapGenerator
{
private:
static QMap<QString, QPixmap> pmCache;
public:
static QPixmap generatePixmap(int height, bool expanded);
static void clear()
{
pmCache.clear();
}
};
QPixmap loadColorAdjustedPixmap(const QString &name);
#endif

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,19 @@
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);
// 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
@ -36,10 +43,29 @@ void BannerWidget::setText(const QString &text) const
bannerLabel->setText(text);
}
void BannerWidget::setClickable(bool _clickable)
{
clickable = _clickable;
setDropdownIconState(true);
}
void BannerWidget::toggleBuddyVisibility() const
{
if (buddy) {
buddy->setVisible(!buddy->isVisible());
setDropdownIconState(buddy->isVisible());
} else {
setDropdownIconState(false);
}
}
void BannerWidget::setDropdownIconState(bool expanded) const
{
if (clickable) {
iconLabel->setPixmap(DropdownIconPixmapGenerator::generatePixmap(24, expanded));
} else {
// we cannot directly hide the iconLabel, since it's needed to center the text; set an empty image instead
iconLabel->setPixmap(QPixmap());
}
}

View file

@ -16,6 +16,7 @@ public:
int transparency = 80);
void mousePressEvent(QMouseEvent *event) override;
void setText(const QString &text) const;
void setClickable(bool _clickable);
void setBuddy(QWidget *_buddy)
{
buddy = _buddy;
@ -24,16 +25,12 @@ public:
{
return bannerLabel->text();
}
void setClickable(bool _clickable)
{
clickable = _clickable;
}
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 +40,7 @@ signals:
void buddyVisibilityChanged();
private slots:
void toggleBuddyVisibility() const;
void setDropdownIconState(bool expanded) const;
};
#endif // BANNER_WIDGET_H