mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-08-02 10:53:02 +02:00
fix: cache icons in settings
This commit is contained in:
parent
64b824671a
commit
1dfe68e9f3
2 changed files with 15 additions and 4 deletions
|
@ -37,6 +37,7 @@ const QVector<QString> icons{
|
||||||
AyuAssets::CHIBI2_ICON,
|
AyuAssets::CHIBI2_ICON,
|
||||||
AyuAssets::EXTERA2_ICON,
|
AyuAssets::EXTERA2_ICON,
|
||||||
};
|
};
|
||||||
|
std::unordered_map<QString, QImage> cachedIcons;
|
||||||
|
|
||||||
const auto rows = static_cast<int>(icons.size()) / 4 + std::min(1, static_cast<int>(icons.size()) % 4);
|
const auto rows = static_cast<int>(icons.size()) / 4 + std::min(1, static_cast<int>(icons.size()) % 4);
|
||||||
|
|
||||||
|
@ -83,6 +84,9 @@ IconPicker::IconPicker(QWidget *parent)
|
||||||
setMinimumSize(st::boxWidth, (st::cpIconSize + st::cpPadding) * rows - st::cpPadding);
|
setMinimumSize(st::boxWidth, (st::cpIconSize + st::cpPadding) * rows - st::cpPadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IconPicker::~IconPicker() {
|
||||||
|
cachedIcons.clear();
|
||||||
|
}
|
||||||
void IconPicker::paintEvent(QPaintEvent *e) {
|
void IconPicker::paintEvent(QPaintEvent *e) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
PainterHighQualityEnabler hq(p);
|
PainterHighQualityEnabler hq(p);
|
||||||
|
@ -98,10 +102,16 @@ void IconPicker::paintEvent(QPaintEvent *e) {
|
||||||
if (iconName.isEmpty()) {
|
if (iconName.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
QImage icon;
|
||||||
auto icon = AyuAssets::loadPreview(iconName)
|
if (const auto cached = cachedIcons.find(iconName); cached != cachedIcons.end()) {
|
||||||
.scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
icon = cached->second;
|
||||||
|
} else {
|
||||||
|
icon = cachedIcons[iconName] = AyuAssets::loadPreview(iconName).scaled(
|
||||||
|
st::cpIconSize,
|
||||||
|
st::cpIconSize,
|
||||||
|
Qt::KeepAspectRatio,
|
||||||
|
Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
auto opacity = 0.0f;
|
auto opacity = 0.0f;
|
||||||
if (iconName == wasSelected) {
|
if (iconName == wasSelected) {
|
||||||
opacity = 1.0f - animation.value(1.0f);
|
opacity = 1.0f - animation.value(1.0f);
|
||||||
|
|
|
@ -13,6 +13,7 @@ class IconPicker : public Ui::RpWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IconPicker(QWidget *parent);
|
IconPicker(QWidget *parent);
|
||||||
|
~IconPicker();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue