From 6f5d36941698a6adbca14b86e751ea63b2da0e57 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Tue, 25 Feb 2025 15:36:48 -0800 Subject: [PATCH] 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 --- cockatrice/cockatrice.qrc | 4 ++- .../resources/icons/dropdown_collapsed.svg | 10 +++++++ .../resources/icons/dropdown_expanded.svg | 10 +++++++ .../src/client/ui/pixel_map_generator.cpp | 15 ++++++++++ .../src/client/ui/pixel_map_generator.h | 13 ++++++++ .../widgets/general/display/banner_widget.cpp | 30 +++++++++++++++++-- .../widgets/general/display/banner_widget.h | 8 ++--- 7 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 cockatrice/resources/icons/dropdown_collapsed.svg create mode 100644 cockatrice/resources/icons/dropdown_expanded.svg diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index 970c25fc9..1ee8aea25 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -1,5 +1,5 @@ - + resources/cardback.svg resources/cockatrice.svg resources/hand.svg @@ -17,6 +17,8 @@ resources/icons/conceded.svg resources/icons/decrement.svg resources/icons/delete.svg + resources/icons/dropdown_collapsed.svg + resources/icons/dropdown_expanded.svg resources/icons/forgot_password.svg resources/icons/increment.svg resources/icons/info.svg diff --git a/cockatrice/resources/icons/dropdown_collapsed.svg b/cockatrice/resources/icons/dropdown_collapsed.svg new file mode 100644 index 000000000..52e833e65 --- /dev/null +++ b/cockatrice/resources/icons/dropdown_collapsed.svg @@ -0,0 +1,10 @@ + + + + + ]> + + + diff --git a/cockatrice/resources/icons/dropdown_expanded.svg b/cockatrice/resources/icons/dropdown_expanded.svg new file mode 100644 index 000000000..fa3ee205c --- /dev/null +++ b/cockatrice/resources/icons/dropdown_expanded.svg @@ -0,0 +1,10 @@ + + + + + ]> + + + diff --git a/cockatrice/src/client/ui/pixel_map_generator.cpp b/cockatrice/src/client/ui/pixel_map_generator.cpp index 9f1c9bb68..c695e1093 100644 --- a/cockatrice/src/client/ui/pixel_map_generator.cpp +++ b/cockatrice/src/client/ui/pixel_map_generator.cpp @@ -357,6 +357,21 @@ QPixmap LockPixmapGenerator::generatePixmap(int height) QMap 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 DropdownIconPixmapGenerator::pmCache; + QPixmap loadColorAdjustedPixmap(const QString &name) { if (qApp->palette().windowText().color().lightness() > 200) { diff --git a/cockatrice/src/client/ui/pixel_map_generator.h b/cockatrice/src/client/ui/pixel_map_generator.h index f35596bc8..0380de5ee 100644 --- a/cockatrice/src/client/ui/pixel_map_generator.h +++ b/cockatrice/src/client/ui/pixel_map_generator.h @@ -106,6 +106,19 @@ public: } }; +class DropdownIconPixmapGenerator +{ +private: + static QMap pmCache; + +public: + static QPixmap generatePixmap(int height, bool expanded); + static void clear() + { + pmCache.clear(); + } +}; + QPixmap loadColorAdjustedPixmap(const QString &name); #endif 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 64a64ba7c..abed4bac5 100644 --- a/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp +++ b/cockatrice/src/client/ui/widgets/general/display/banner_widget.cpp @@ -1,5 +1,7 @@ #include "banner_widget.h" +#include "../../../../../client/ui/pixel_map_generator.h" + #include #include #include @@ -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()); } } 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 545cb5ed6..552e5ea98 100644 --- a/cockatrice/src/client/ui/widgets/general/display/banner_widget.h +++ b/cockatrice/src/client/ui/widgets/general/display/banner_widget.h @@ -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