mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to remove sticker set from tab of featured sticker sets.
This commit is contained in:
parent
95b26911e0
commit
0d4a83ea47
2 changed files with 100 additions and 31 deletions
|
@ -105,9 +105,14 @@ public:
|
||||||
void setFullOrder(const StickersSetsOrder &order);
|
void setFullOrder(const StickersSetsOrder &order);
|
||||||
void setRemovedSets(const StickersSetsOrder &removed);
|
void setRemovedSets(const StickersSetsOrder &removed);
|
||||||
|
|
||||||
|
void setRowRemovedBySetId(uint64 setId, bool removed);
|
||||||
|
|
||||||
void setInstallSetCallback(Fn<void(uint64 setId)> callback) {
|
void setInstallSetCallback(Fn<void(uint64 setId)> callback) {
|
||||||
_installSetCallback = std::move(callback);
|
_installSetCallback = std::move(callback);
|
||||||
}
|
}
|
||||||
|
void setRemoveSetCallback(Fn<void(uint64 setId)> callback) {
|
||||||
|
_removeSetCallback = std::move(callback);
|
||||||
|
}
|
||||||
void setLoadMoreCallback(Fn<void()> callback) {
|
void setLoadMoreCallback(Fn<void()> callback) {
|
||||||
_loadMoreCallback = std::move(callback);
|
_loadMoreCallback = std::move(callback);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +217,11 @@ private:
|
||||||
void setPressed(SelectedRow pressed);
|
void setPressed(SelectedRow pressed);
|
||||||
void setup();
|
void setup();
|
||||||
QRect relativeButtonRect(bool removeButton, bool installedSet) const;
|
QRect relativeButtonRect(bool removeButton, bool installedSet) const;
|
||||||
void ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton);
|
void ensureRipple(
|
||||||
|
const style::RippleAnimation &st,
|
||||||
|
QImage mask,
|
||||||
|
bool removeButton,
|
||||||
|
bool installedSet);
|
||||||
|
|
||||||
bool shiftingAnimationCallback(crl::time now);
|
bool shiftingAnimationCallback(crl::time now);
|
||||||
void paintRow(Painter &p, not_null<Row*> row, int index);
|
void paintRow(Painter &p, not_null<Row*> row, int index);
|
||||||
|
@ -270,6 +279,7 @@ private:
|
||||||
Ui::Animations::Basic _shiftingAnimation;
|
Ui::Animations::Basic _shiftingAnimation;
|
||||||
|
|
||||||
Fn<void(uint64 setId)> _installSetCallback;
|
Fn<void(uint64 setId)> _installSetCallback;
|
||||||
|
Fn<void(uint64 setId)> _removeSetCallback;
|
||||||
Fn<void()> _loadMoreCallback;
|
Fn<void()> _loadMoreCallback;
|
||||||
|
|
||||||
int _visibleTop = 0;
|
int _visibleTop = 0;
|
||||||
|
@ -598,17 +608,43 @@ void StickersBox::prepare() {
|
||||||
_attached.widget()->hide();
|
_attached.widget()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto installCallback = [=](uint64 setId) { installSet(setId); };
|
{
|
||||||
if (_featured.widget()) {
|
const auto installCallback = [=](uint64 setId) { installSet(setId); };
|
||||||
_featured.widget()->setInstallSetCallback(installCallback);
|
const auto markAsInstalledCallback = [=](uint64 setId) {
|
||||||
}
|
if (_installed.widget()) {
|
||||||
if (_archived.widget()) {
|
_installed.widget()->setRowRemovedBySetId(setId, false);
|
||||||
_archived.widget()->setInstallSetCallback(installCallback);
|
}
|
||||||
_archived.widget()->setLoadMoreCallback([=] { loadMoreArchived(); });
|
if (_featured.widget()) {
|
||||||
}
|
_featured.widget()->setRowRemovedBySetId(setId, false);
|
||||||
if (_attached.widget()) {
|
}
|
||||||
_attached.widget()->setInstallSetCallback(installCallback);
|
};
|
||||||
_attached.widget()->setLoadMoreCallback([=] { showAttachedStickers(); });
|
const auto markAsRemovedCallback = [=](uint64 setId) {
|
||||||
|
if (_installed.widget()) {
|
||||||
|
_installed.widget()->setRowRemovedBySetId(setId, true);
|
||||||
|
}
|
||||||
|
if (_featured.widget()) {
|
||||||
|
_featured.widget()->setRowRemovedBySetId(setId, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (const auto installed = _installed.widget()) {
|
||||||
|
installed->setInstallSetCallback(markAsInstalledCallback);
|
||||||
|
installed->setRemoveSetCallback(markAsRemovedCallback);
|
||||||
|
}
|
||||||
|
if (const auto featured = _featured.widget()) {
|
||||||
|
featured->setInstallSetCallback([=](uint64 setId) {
|
||||||
|
markAsInstalledCallback(setId);
|
||||||
|
installCallback(setId);
|
||||||
|
});
|
||||||
|
featured->setRemoveSetCallback(markAsRemovedCallback);
|
||||||
|
}
|
||||||
|
if (const auto archived = _archived.widget()) {
|
||||||
|
archived->setInstallSetCallback(installCallback);
|
||||||
|
archived->setLoadMoreCallback([=] { loadMoreArchived(); });
|
||||||
|
}
|
||||||
|
if (const auto attached = _attached.widget()) {
|
||||||
|
attached->setInstallSetCallback(installCallback);
|
||||||
|
attached->setLoadMoreCallback([=] { showAttachedStickers(); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_megagroupSet) {
|
if (_megagroupSet) {
|
||||||
|
@ -998,12 +1034,12 @@ void StickersBox::rebuildList(Tab *tab) {
|
||||||
tab = _tab;
|
tab = _tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tab == &_installed) || (tab == &_masks)) {
|
if ((tab == &_installed) || (tab == &_masks) || (_tab == &_featured)) {
|
||||||
_localOrder = tab->widget()->getFullOrder();
|
_localOrder = tab->widget()->getFullOrder();
|
||||||
_localRemoved = tab->widget()->getRemovedSets();
|
_localRemoved = tab->widget()->getRemovedSets();
|
||||||
}
|
}
|
||||||
tab->widget()->rebuild(_isMasks);
|
tab->widget()->rebuild(_isMasks);
|
||||||
if ((tab == &_installed) || (tab == &_masks)) {
|
if ((tab == &_installed) || (tab == &_masks) || (_tab == &_featured)) {
|
||||||
tab->widget()->setFullOrder(_localOrder);
|
tab->widget()->setFullOrder(_localOrder);
|
||||||
}
|
}
|
||||||
tab->widget()->setRemovedSets(_localRemoved);
|
tab->widget()->setRemovedSets(_localRemoved);
|
||||||
|
@ -1594,6 +1630,12 @@ void StickersBox::Inner::paintFakeButton(Painter &p, not_null<Row*> row, int ind
|
||||||
const auto textWidth = _installedWidth;
|
const auto textWidth = _installedWidth;
|
||||||
const auto &text = _installedText;
|
const auto &text = _installedText;
|
||||||
_inactiveButtonBg.paint(p, myrtlrect(rect));
|
_inactiveButtonBg.paint(p, myrtlrect(rect));
|
||||||
|
if (row->ripple) {
|
||||||
|
row->ripple->paint(p, rect.x(), rect.y(), width());
|
||||||
|
if (row->ripple->empty()) {
|
||||||
|
row->ripple.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
p.setFont(st.font);
|
p.setFont(st.font);
|
||||||
p.setPen(st.textFg);
|
p.setPen(st.textFg);
|
||||||
p.drawTextLeft(rect.x() - (st.width / 2), rect.y() + st.textTop, width(), text, textWidth);
|
p.drawTextLeft(rect.x() - (st.width / 2), rect.y() + st.textTop, width(), text, textWidth);
|
||||||
|
@ -1673,16 +1715,27 @@ void StickersBox::Inner::setActionDown(int newActionDown) {
|
||||||
if (row->removed) {
|
if (row->removed) {
|
||||||
auto rippleSize = QSize(_undoWidth - st::stickersUndoRemove.width, st::stickersUndoRemove.height);
|
auto rippleSize = QSize(_undoWidth - st::stickersUndoRemove.width, st::stickersUndoRemove.height);
|
||||||
auto rippleMask = Ui::RippleAnimation::RoundRectMask(rippleSize, st::roundRadiusLarge);
|
auto rippleMask = Ui::RippleAnimation::RoundRectMask(rippleSize, st::roundRadiusLarge);
|
||||||
ensureRipple(st::stickersUndoRemove.ripple, std::move(rippleMask), removeButton);
|
ensureRipple(st::stickersUndoRemove.ripple, std::move(rippleMask), removeButton, false);
|
||||||
} else {
|
} else {
|
||||||
auto rippleSize = st::stickersRemove.rippleAreaSize;
|
auto rippleSize = st::stickersRemove.rippleAreaSize;
|
||||||
auto rippleMask = Ui::RippleAnimation::EllipseMask(QSize(rippleSize, rippleSize));
|
auto rippleMask = Ui::RippleAnimation::EllipseMask(QSize(rippleSize, rippleSize));
|
||||||
ensureRipple(st::stickersRemove.ripple, std::move(rippleMask), removeButton);
|
ensureRipple(st::stickersRemove.ripple, std::move(rippleMask), removeButton, false);
|
||||||
}
|
}
|
||||||
} else if (!row->isInstalled() || row->isArchived() || row->removed) {
|
} else {
|
||||||
auto rippleSize = QSize(_addWidth - st::stickersTrendingAdd.width, st::stickersTrendingAdd.height);
|
const auto installedSet = row->isInstalled()
|
||||||
auto rippleMask = Ui::RippleAnimation::RoundRectMask(rippleSize, st::roundRadiusLarge);
|
&& !row->isArchived()
|
||||||
ensureRipple(st::stickersTrendingAdd.ripple, std::move(rippleMask), removeButton);
|
&& !row->removed;
|
||||||
|
const auto &st = installedSet
|
||||||
|
? st::stickersTrendingInstalled
|
||||||
|
: st::stickersTrendingAdd;
|
||||||
|
auto rippleMask = Ui::RippleAnimation::RoundRectMask(
|
||||||
|
QSize(_addWidth - st.width, st.height),
|
||||||
|
st::roundRadiusLarge);
|
||||||
|
ensureRipple(
|
||||||
|
st.ripple,
|
||||||
|
std::move(rippleMask),
|
||||||
|
removeButton,
|
||||||
|
installedSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (row->ripple) {
|
if (row->ripple) {
|
||||||
|
@ -1747,9 +1800,14 @@ void StickersBox::Inner::setPressed(SelectedRow pressed) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StickersBox::Inner::ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton) {
|
void StickersBox::Inner::ensureRipple(
|
||||||
_rows[_actionDown]->ripple = std::make_unique<Ui::RippleAnimation>(st, std::move(mask), [this, index = _actionDown, removeButton] {
|
const style::RippleAnimation &st,
|
||||||
update(myrtlrect(relativeButtonRect(removeButton, false).translated(0, _itemsTop + index * _rowHeight)));
|
QImage mask,
|
||||||
|
bool removeButton,
|
||||||
|
bool installedSet) {
|
||||||
|
const auto dy = _itemsTop + _actionDown * _rowHeight;
|
||||||
|
_rows[_actionDown]->ripple = std::make_unique<Ui::RippleAnimation>(st, std::move(mask), [=] {
|
||||||
|
update(myrtlrect(relativeButtonRect(removeButton, installedSet).translated(0, dy)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1812,7 +1870,7 @@ void StickersBox::Inner::updateSelected() {
|
||||||
selected = selectedIndex;
|
selected = selectedIndex;
|
||||||
local.setY(local.y() - _itemsTop - selectedIndex * _rowHeight);
|
local.setY(local.y() - _itemsTop - selectedIndex * _rowHeight);
|
||||||
const auto row = _rows[selectedIndex].get();
|
const auto row = _rows[selectedIndex].get();
|
||||||
if (!_megagroupSet && (_isInstalledTab || !row->isInstalled() || row->isArchived() || row->removed)) {
|
if (!_megagroupSet && (_isInstalledTab || (_section == Section::Featured) || !row->isInstalled() || row->isArchived() || row->removed)) {
|
||||||
auto removeButton = (_isInstalledTab && !row->removed);
|
auto removeButton = (_isInstalledTab && !row->removed);
|
||||||
auto rect = myrtlrect(relativeButtonRect(removeButton, false));
|
auto rect = myrtlrect(relativeButtonRect(removeButton, false));
|
||||||
actionSel = rect.contains(local) ? selectedIndex : -1;
|
actionSel = rect.contains(local) ? selectedIndex : -1;
|
||||||
|
@ -1857,7 +1915,7 @@ float64 StickersBox::Inner::aboveShadowOpacity() const {
|
||||||
|
|
||||||
auto dx = 0;
|
auto dx = 0;
|
||||||
auto dy = qAbs(_above * _rowHeight + qRound(_rows[_above]->yadd.current()) - _started * _rowHeight);
|
auto dy = qAbs(_above * _rowHeight + qRound(_rows[_above]->yadd.current()) - _started * _rowHeight);
|
||||||
return qMin((dx + dy) * 2. / _rowHeight, 1.);
|
return qMin((dx + dy) * 2. / _rowHeight, 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
|
@ -1868,10 +1926,11 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
_mouse = e->globalPos();
|
_mouse = e->globalPos();
|
||||||
updateSelected();
|
updateSelected();
|
||||||
if (_actionDown == _actionSel && _actionSel >= 0) {
|
if (_actionDown == _actionSel && _actionSel >= 0) {
|
||||||
if (_isInstalledTab) {
|
const auto callback = _rows[_actionDown]->removed
|
||||||
setRowRemoved(_actionDown, !_rows[_actionDown]->removed);
|
? _installSetCallback
|
||||||
} else if (_installSetCallback) {
|
: _removeSetCallback;
|
||||||
_installSetCallback(_rows[_actionDown]->set->id);
|
if (callback) {
|
||||||
|
callback(_rows[_actionDown]->set->id);
|
||||||
}
|
}
|
||||||
} else if (_dragging >= 0) {
|
} else if (_dragging >= 0) {
|
||||||
_rows[_dragging]->yadd.start(0.);
|
_rows[_dragging]->yadd.start(0.);
|
||||||
|
@ -1921,6 +1980,13 @@ void StickersBox::Inner::saveGroupSet() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StickersBox::Inner::setRowRemovedBySetId(uint64 setId, bool removed) {
|
||||||
|
const auto index = getRowIndex(setId);
|
||||||
|
if (index >= 0) {
|
||||||
|
setRowRemoved(index, removed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void StickersBox::Inner::setRowRemoved(int index, bool removed) {
|
void StickersBox::Inner::setRowRemoved(int index, bool removed) {
|
||||||
auto &row = _rows[index];
|
auto &row = _rows[index];
|
||||||
if (row->removed != removed) {
|
if (row->removed != removed) {
|
||||||
|
|
|
@ -294,8 +294,11 @@ stickersTrendingAdd: RoundButton(defaultActiveButton) {
|
||||||
stickersTrendingInstalled: RoundButton(stickersTrendingAdd) {
|
stickersTrendingInstalled: RoundButton(stickersTrendingAdd) {
|
||||||
textFg: activeButtonBg;
|
textFg: activeButtonBg;
|
||||||
textFgOver: activeButtonBgOver;
|
textFgOver: activeButtonBgOver;
|
||||||
textBg: activeButtonSecondaryFg;
|
textBg: lightButtonBgOver;
|
||||||
textBgOver: activeButtonSecondaryFgOver;
|
textBgOver: lightButtonBgOver;
|
||||||
|
ripple: RippleAnimation(defaultRippleAnimation) {
|
||||||
|
color: activeButtonSecondaryFg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stickersRemove: IconButton(defaultIconButton) {
|
stickersRemove: IconButton(defaultIconButton) {
|
||||||
width: 40px;
|
width: 40px;
|
||||||
|
|
Loading…
Add table
Reference in a new issue