mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
feat: add fade animation for icon picker
This commit is contained in:
parent
a48534b51a
commit
299833ca3d
3 changed files with 36 additions and 13 deletions
|
@ -33,18 +33,19 @@ const QVector<QString> icons{
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
void drawIcon(QPainter &p, const QImage &icon, int xOffset, int yOffset, bool selected) {
|
void drawIcon(QPainter &p, const QImage &icon, int xOffset, int yOffset, float strokeOpacity) {
|
||||||
xOffset += st::cpPadding;
|
xOffset += st::cpPadding;
|
||||||
|
|
||||||
if (selected) {
|
// stroke
|
||||||
p.save();
|
p.save();
|
||||||
p.setPen(QPen(st::iconPreviewStroke, st::cpPenSize));
|
p.setPen(QPen(st::iconPreviewStroke, st::cpPenSize));
|
||||||
|
p.setOpacity(strokeOpacity);
|
||||||
p.drawEllipse(xOffset + st::cpSelectedPadding,
|
p.drawEllipse(xOffset + st::cpSelectedPadding,
|
||||||
yOffset + st::cpSelectedPadding,
|
yOffset + st::cpSelectedPadding,
|
||||||
st::cpIconSize + st::cpSelectedPadding * 2,
|
st::cpIconSize + st::cpSelectedPadding * 2,
|
||||||
st::cpIconSize + st::cpSelectedPadding * 2);
|
st::cpIconSize + st::cpSelectedPadding * 2);
|
||||||
p.restore();
|
p.restore();
|
||||||
}
|
// /stroke
|
||||||
|
|
||||||
auto rect = QRect(xOffset + st::cpImagePadding, yOffset + st::cpImagePadding, st::cpIconSize, st::cpIconSize);
|
auto rect = QRect(xOffset + st::cpImagePadding, yOffset + st::cpImagePadding, st::cpIconSize, st::cpIconSize);
|
||||||
p.drawImage(rect, icon);
|
p.drawImage(rect, icon);
|
||||||
|
@ -81,11 +82,19 @@ void IconPicker::paintEvent(QPaintEvent *e) {
|
||||||
const auto &iconName = icons[idx];
|
const auto &iconName = icons[idx];
|
||||||
auto icon = AyuAssets::loadPreview(iconName)
|
auto icon = AyuAssets::loadPreview(iconName)
|
||||||
.scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
.scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
|
||||||
|
auto opacity = 0.0f;
|
||||||
|
if (iconName == wasSelected) {
|
||||||
|
opacity = 1.0f - animation.value(1.0f);
|
||||||
|
} else if (iconName == AyuAssets::currentAppLogoName()) {
|
||||||
|
opacity = wasSelected.isEmpty() ? 1.0f : animation.value(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
drawIcon(p,
|
drawIcon(p,
|
||||||
icon,
|
icon,
|
||||||
(st::cpIconSize + st::cpSpacingX) * i + offset,
|
(st::cpIconSize + st::cpSpacingX) * i + offset,
|
||||||
row * (st::cpIconSize + st::cpSpacingY),
|
row * (st::cpIconSize + st::cpSpacingY),
|
||||||
AyuAssets::currentAppLogoName() == iconName);
|
opacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +115,17 @@ void IconPicker::mousePressEvent(QMouseEvent *e) {
|
||||||
&& e->pos().y() <= yOffset + st::cpIconSize) {
|
&& e->pos().y() <= yOffset + st::cpIconSize) {
|
||||||
const auto &iconName = icons[idx];
|
const auto &iconName = icons[idx];
|
||||||
if (settings->appIcon != iconName) {
|
if (settings->appIcon != iconName) {
|
||||||
|
wasSelected = settings->appIcon;
|
||||||
|
animation.start(
|
||||||
|
[=]
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
},
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
200,
|
||||||
|
anim::easeOutCubic);
|
||||||
|
|
||||||
settings->set_appIcon(iconName);
|
settings->set_appIcon(iconName);
|
||||||
changed = true;
|
changed = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
|
#include "ui/effects/animations.h"
|
||||||
|
|
||||||
class IconPicker : public Ui::RpWidget
|
class IconPicker : public Ui::RpWidget
|
||||||
{
|
{
|
||||||
|
@ -16,4 +17,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void mousePressEvent(QMouseEvent *e) override;
|
void mousePressEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
|
Ui::Animations::Simple animation;
|
||||||
|
QString wasSelected;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1008,7 +1008,7 @@ void SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout*> container) {
|
||||||
st::autoDownloadLimitSlider,
|
st::autoDownloadLimitSlider,
|
||||||
st::settingsScaleLabel,
|
st::settingsScaleLabel,
|
||||||
0,
|
0,
|
||||||
st::settingsScaleLabel.style.font->width("30%"));
|
st::settingsScaleLabel.style.font->width("8%%"));
|
||||||
container->add(std::move(recentStickersLimitSlider.widget), st::recentStickersLimitPadding);
|
container->add(std::move(recentStickersLimitSlider.widget), st::recentStickersLimitPadding);
|
||||||
const auto slider = recentStickersLimitSlider.slider;
|
const auto slider = recentStickersLimitSlider.slider;
|
||||||
const auto label = recentStickersLimitSlider.label;
|
const auto label = recentStickersLimitSlider.label;
|
||||||
|
@ -1331,7 +1331,6 @@ void SetupAyuGramSettings(not_null<Ui::VerticalLayout*> container,
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
SetupSendConfirmations(container);
|
SetupSendConfirmations(container);
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
AddDivider(container);
|
|
||||||
|
|
||||||
AddDividerText(container, tr::ayu_SettingsWatermark());
|
AddDividerText(container, tr::ayu_SettingsWatermark());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue