mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +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 setRemovedSets(const StickersSetsOrder &removed);
|
||||
|
||||
void setRowRemovedBySetId(uint64 setId, bool removed);
|
||||
|
||||
void setInstallSetCallback(Fn<void(uint64 setId)> callback) {
|
||||
_installSetCallback = std::move(callback);
|
||||
}
|
||||
void setRemoveSetCallback(Fn<void(uint64 setId)> callback) {
|
||||
_removeSetCallback = std::move(callback);
|
||||
}
|
||||
void setLoadMoreCallback(Fn<void()> callback) {
|
||||
_loadMoreCallback = std::move(callback);
|
||||
}
|
||||
|
@ -212,7 +217,11 @@ private:
|
|||
void setPressed(SelectedRow pressed);
|
||||
void setup();
|
||||
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);
|
||||
void paintRow(Painter &p, not_null<Row*> row, int index);
|
||||
|
@ -270,6 +279,7 @@ private:
|
|||
Ui::Animations::Basic _shiftingAnimation;
|
||||
|
||||
Fn<void(uint64 setId)> _installSetCallback;
|
||||
Fn<void(uint64 setId)> _removeSetCallback;
|
||||
Fn<void()> _loadMoreCallback;
|
||||
|
||||
int _visibleTop = 0;
|
||||
|
@ -598,17 +608,43 @@ void StickersBox::prepare() {
|
|||
_attached.widget()->hide();
|
||||
}
|
||||
|
||||
const auto installCallback = [=](uint64 setId) { installSet(setId); };
|
||||
if (_featured.widget()) {
|
||||
_featured.widget()->setInstallSetCallback(installCallback);
|
||||
}
|
||||
if (_archived.widget()) {
|
||||
_archived.widget()->setInstallSetCallback(installCallback);
|
||||
_archived.widget()->setLoadMoreCallback([=] { loadMoreArchived(); });
|
||||
}
|
||||
if (_attached.widget()) {
|
||||
_attached.widget()->setInstallSetCallback(installCallback);
|
||||
_attached.widget()->setLoadMoreCallback([=] { showAttachedStickers(); });
|
||||
{
|
||||
const auto installCallback = [=](uint64 setId) { installSet(setId); };
|
||||
const auto markAsInstalledCallback = [=](uint64 setId) {
|
||||
if (_installed.widget()) {
|
||||
_installed.widget()->setRowRemovedBySetId(setId, false);
|
||||
}
|
||||
if (_featured.widget()) {
|
||||
_featured.widget()->setRowRemovedBySetId(setId, false);
|
||||
}
|
||||
};
|
||||
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) {
|
||||
|
@ -998,12 +1034,12 @@ void StickersBox::rebuildList(Tab *tab) {
|
|||
tab = _tab;
|
||||
}
|
||||
|
||||
if ((tab == &_installed) || (tab == &_masks)) {
|
||||
if ((tab == &_installed) || (tab == &_masks) || (_tab == &_featured)) {
|
||||
_localOrder = tab->widget()->getFullOrder();
|
||||
_localRemoved = tab->widget()->getRemovedSets();
|
||||
}
|
||||
tab->widget()->rebuild(_isMasks);
|
||||
if ((tab == &_installed) || (tab == &_masks)) {
|
||||
if ((tab == &_installed) || (tab == &_masks) || (_tab == &_featured)) {
|
||||
tab->widget()->setFullOrder(_localOrder);
|
||||
}
|
||||
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 &text = _installedText;
|
||||
_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.setPen(st.textFg);
|
||||
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) {
|
||||
auto rippleSize = QSize(_undoWidth - st::stickersUndoRemove.width, st::stickersUndoRemove.height);
|
||||
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 {
|
||||
auto rippleSize = st::stickersRemove.rippleAreaSize;
|
||||
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) {
|
||||
auto rippleSize = QSize(_addWidth - st::stickersTrendingAdd.width, st::stickersTrendingAdd.height);
|
||||
auto rippleMask = Ui::RippleAnimation::RoundRectMask(rippleSize, st::roundRadiusLarge);
|
||||
ensureRipple(st::stickersTrendingAdd.ripple, std::move(rippleMask), removeButton);
|
||||
} else {
|
||||
const auto installedSet = row->isInstalled()
|
||||
&& !row->isArchived()
|
||||
&& !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) {
|
||||
|
@ -1747,9 +1800,14 @@ void StickersBox::Inner::setPressed(SelectedRow pressed) {
|
|||
}
|
||||
}
|
||||
|
||||
void StickersBox::Inner::ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton) {
|
||||
_rows[_actionDown]->ripple = std::make_unique<Ui::RippleAnimation>(st, std::move(mask), [this, index = _actionDown, removeButton] {
|
||||
update(myrtlrect(relativeButtonRect(removeButton, false).translated(0, _itemsTop + index * _rowHeight)));
|
||||
void StickersBox::Inner::ensureRipple(
|
||||
const style::RippleAnimation &st,
|
||||
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;
|
||||
local.setY(local.y() - _itemsTop - selectedIndex * _rowHeight);
|
||||
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 rect = myrtlrect(relativeButtonRect(removeButton, false));
|
||||
actionSel = rect.contains(local) ? selectedIndex : -1;
|
||||
|
@ -1857,7 +1915,7 @@ float64 StickersBox::Inner::aboveShadowOpacity() const {
|
|||
|
||||
auto dx = 0;
|
||||
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) {
|
||||
|
@ -1868,10 +1926,11 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
|||
_mouse = e->globalPos();
|
||||
updateSelected();
|
||||
if (_actionDown == _actionSel && _actionSel >= 0) {
|
||||
if (_isInstalledTab) {
|
||||
setRowRemoved(_actionDown, !_rows[_actionDown]->removed);
|
||||
} else if (_installSetCallback) {
|
||||
_installSetCallback(_rows[_actionDown]->set->id);
|
||||
const auto callback = _rows[_actionDown]->removed
|
||||
? _installSetCallback
|
||||
: _removeSetCallback;
|
||||
if (callback) {
|
||||
callback(_rows[_actionDown]->set->id);
|
||||
}
|
||||
} else if (_dragging >= 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) {
|
||||
auto &row = _rows[index];
|
||||
if (row->removed != removed) {
|
||||
|
|
|
@ -294,8 +294,11 @@ stickersTrendingAdd: RoundButton(defaultActiveButton) {
|
|||
stickersTrendingInstalled: RoundButton(stickersTrendingAdd) {
|
||||
textFg: activeButtonBg;
|
||||
textFgOver: activeButtonBgOver;
|
||||
textBg: activeButtonSecondaryFg;
|
||||
textBgOver: activeButtonSecondaryFgOver;
|
||||
textBg: lightButtonBgOver;
|
||||
textBgOver: lightButtonBgOver;
|
||||
ripple: RippleAnimation(defaultRippleAnimation) {
|
||||
color: activeButtonSecondaryFg;
|
||||
}
|
||||
}
|
||||
stickersRemove: IconButton(defaultIconButton) {
|
||||
width: 40px;
|
||||
|
|
Loading…
Add table
Reference in a new issue