diff --git a/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp b/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp index 64b8940dde..ce89cd7b85 100644 --- a/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp +++ b/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp @@ -37,6 +37,7 @@ const QVector icons{ AyuAssets::CHIBI2_ICON, AyuAssets::EXTERA2_ICON, }; +std::unordered_map cachedIcons; const auto rows = static_cast(icons.size()) / 4 + std::min(1, static_cast(icons.size()) % 4); @@ -83,6 +84,9 @@ IconPicker::IconPicker(QWidget *parent) setMinimumSize(st::boxWidth, (st::cpIconSize + st::cpPadding) * rows - st::cpPadding); } +IconPicker::~IconPicker() { + cachedIcons.clear(); +} void IconPicker::paintEvent(QPaintEvent *e) { Painter p(this); PainterHighQualityEnabler hq(p); @@ -98,10 +102,16 @@ void IconPicker::paintEvent(QPaintEvent *e) { if (iconName.isEmpty()) { continue; } - - auto icon = AyuAssets::loadPreview(iconName) - .scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); - + QImage icon; + if (const auto cached = cachedIcons.find(iconName); cached != cachedIcons.end()) { + icon = cached->second; + } else { + icon = cachedIcons[iconName] = AyuAssets::loadPreview(iconName).scaled( + st::cpIconSize, + st::cpIconSize, + Qt::KeepAspectRatio, + Qt::SmoothTransformation); + } auto opacity = 0.0f; if (iconName == wasSelected) { opacity = 1.0f - animation.value(1.0f); diff --git a/Telegram/SourceFiles/ayu/ui/components/icon_picker.h b/Telegram/SourceFiles/ayu/ui/components/icon_picker.h index 29ce7dd39f..65c8b10cd4 100644 --- a/Telegram/SourceFiles/ayu/ui/components/icon_picker.h +++ b/Telegram/SourceFiles/ayu/ui/components/icon_picker.h @@ -13,6 +13,7 @@ class IconPicker : public Ui::RpWidget { public: IconPicker(QWidget *parent); + ~IconPicker(); protected: void paintEvent(QPaintEvent *e) override;