mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
sticker packs management done, conversations list context menu added
This commit is contained in:
@@ -38,7 +38,6 @@ _input(set), _installRequest(0) {
|
||||
case mtpc_inputStickerSetShortName: _setShortName = qs(set.c_inputStickerSetShortName().vshort_name); break;
|
||||
}
|
||||
MTP::send(MTPmessages_GetStickerSet(_input), rpcDone(&StickerSetInner::gotSet), rpcFail(&StickerSetInner::failedSet));
|
||||
cSetLastStickersUpdate(0);
|
||||
App::main()->updateStickers();
|
||||
}
|
||||
|
||||
@@ -56,7 +55,7 @@ void StickerSetInner::gotSet(const MTPmessages_StickerSet &set) {
|
||||
}
|
||||
if (d.vset.type() == mtpc_stickerSet) {
|
||||
const MTPDstickerSet &s(d.vset.c_stickerSet());
|
||||
_setTitle = qs(s.vtitle);
|
||||
_setTitle = stickerSetTitle(s);
|
||||
_title = st::boxTitleFont->elided(_setTitle, width() - st::boxTitlePosition.x() - st::boxTitleHeight);
|
||||
_setShortName = qs(s.vshort_name);
|
||||
_setId = s.vid.v;
|
||||
@@ -91,23 +90,14 @@ bool StickerSetInner::failedSet(const RPCError &error) {
|
||||
void StickerSetInner::installDone(const MTPBool &result) {
|
||||
StickerSets &sets(cRefStickerSets());
|
||||
|
||||
_setFlags &= ~MTPDstickerSet::flag_disabled;
|
||||
sets.insert(_setId, StickerSet(_setId, _setAccess, _setTitle, _setShortName, _setCount, _setHash, _setFlags)).value().stickers = _pack;
|
||||
|
||||
int32 insertAtIndex = 0;
|
||||
StickerSetsOrder &order(cRefStickerSetsOrder());
|
||||
for (int32 s = order.size(); insertAtIndex < s; ++insertAtIndex) {
|
||||
StickerSets::const_iterator i = sets.constFind(order.at(insertAtIndex));
|
||||
if (i == sets.cend() || !(i->flags & MTPDstickerSet::flag_official)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int32 currentIndex = cStickerSetsOrder().indexOf(_setId);
|
||||
int32 insertAtIndex = 0, currentIndex = order.indexOf(_setId);
|
||||
if (currentIndex != insertAtIndex) {
|
||||
if (currentIndex > 0) {
|
||||
order.removeAt(currentIndex);
|
||||
if (currentIndex < insertAtIndex) {
|
||||
--insertAtIndex;
|
||||
}
|
||||
}
|
||||
order.insert(insertAtIndex, _setId);
|
||||
}
|
||||
@@ -121,7 +111,7 @@ void StickerSetInner::installDone(const MTPBool &result) {
|
||||
sets.erase(custom);
|
||||
}
|
||||
}
|
||||
cSetStickersHash(QByteArray());
|
||||
cSetStickersHash(stickersCountHash());
|
||||
Local::writeStickers();
|
||||
emit installed(_setId);
|
||||
App::wnd()->hideLayer();
|
||||
@@ -195,7 +185,10 @@ bool StickerSetInner::loaded() const {
|
||||
}
|
||||
|
||||
int32 StickerSetInner::notInstalled() const {
|
||||
return (_loaded && (cStickerSets().constFind(_setId) == cStickerSets().cend())) ? _pack.size() : 0;
|
||||
if (!_loaded) return 0;
|
||||
StickerSets::const_iterator it = cStickerSets().constFind(_setId);
|
||||
if (it == cStickerSets().cend() || (it->flags & MTPDstickerSet::flag_disabled)) return _pack.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool StickerSetInner::official() const {
|
||||
@@ -285,16 +278,16 @@ void StickerSetBox::showAll() {
|
||||
int32 cnt = _inner.notInstalled();
|
||||
if (_inner.loaded()) {
|
||||
_shadow.show();
|
||||
if (_inner.official()) {
|
||||
_add.hide();
|
||||
_share.hide();
|
||||
_cancel.hide();
|
||||
_done.show();
|
||||
} else if (_inner.notInstalled()) {
|
||||
if (_inner.notInstalled()) {
|
||||
_add.show();
|
||||
_cancel.show();
|
||||
_share.hide();
|
||||
_done.hide();
|
||||
} else if (_inner.official()) {
|
||||
_add.hide();
|
||||
_share.hide();
|
||||
_cancel.hide();
|
||||
_done.show();
|
||||
} else {
|
||||
_share.show();
|
||||
_cancel.show();
|
||||
@@ -334,3 +327,589 @@ void StickerSetBox::resizeEvent(QResizeEvent *e) {
|
||||
_cancel.moveToRight(st::boxButtonPadding.right() + _add.width() + st::boxButtonPadding.left(), _add.y());
|
||||
}
|
||||
}
|
||||
|
||||
StickersInner::StickersInner() : TWidget()
|
||||
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
||||
, _aboveShadowFadeStart(0)
|
||||
, _aboveShadowFadeOpacity(0, 0)
|
||||
, _a_shifting(animFunc(this, &StickersInner::animStep_shifting))
|
||||
, _saving(false)
|
||||
, _removeSel(-1)
|
||||
, _removeDown(-1)
|
||||
, _removeWidth(st::normalFont->width(lang(lng_stickers_remove)))
|
||||
, _returnWidth(st::normalFont->width(lang(lng_stickers_return)))
|
||||
, _selected(-1)
|
||||
, _started(-1)
|
||||
, _dragging(-1)
|
||||
, _above(-1)
|
||||
, _aboveShadow(st::boxShadow)
|
||||
, _scrollbar(0) {
|
||||
connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update()));
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
void StickersInner::paintEvent(QPaintEvent *e) {
|
||||
QRect r(e->rect());
|
||||
Painter p(this);
|
||||
|
||||
p.fillRect(r, st::white);
|
||||
p.setClipRect(r);
|
||||
|
||||
int32 yFrom = r.y() - st::membersPadding.top(), yTo = r.y() + r.height() - st::membersPadding.top();
|
||||
p.translate(0, st::membersPadding.top());
|
||||
if (_rows.isEmpty()) {
|
||||
p.setFont(st::noContactsFont->f);
|
||||
p.setPen(st::noContactsColor->p);
|
||||
p.drawText(QRect(0, 0, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
|
||||
} else {
|
||||
int32 from = floorclamp(yFrom - _rowHeight, _rowHeight, 0, _rows.size());
|
||||
int32 to = ceilclamp(yTo + _rowHeight, _rowHeight, 0, _rows.size());
|
||||
p.translate(0, from * _rowHeight);
|
||||
for (int32 i = from; i < to; ++i) {
|
||||
if (i != _above) {
|
||||
paintRow(p, i);
|
||||
}
|
||||
p.translate(0, _rowHeight);
|
||||
}
|
||||
if (from <= _above && _above < to) {
|
||||
p.translate(0, (_above - to) * _rowHeight);
|
||||
paintRow(p, _above);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StickersInner::paintRow(Painter &p, int32 index) {
|
||||
const StickerSetRow *s(_rows.at(index));
|
||||
|
||||
int32 xadd = s->xadd.current(), yadd = s->yadd.current();
|
||||
if (xadd || yadd) p.translate(xadd, yadd);
|
||||
|
||||
bool removeSel = (index == _removeSel && (_removeDown < 0 || index == _removeDown));
|
||||
bool removeDown = removeSel && (index == _removeDown);
|
||||
|
||||
p.setFont((removeSel ? st::linkOverFont : st::linkFont)->f);
|
||||
if (removeDown) {
|
||||
p.setPen(st::btnDefLink.downColor->p);
|
||||
} else {
|
||||
p.setPen(st::btnDefLink.color->p);
|
||||
}
|
||||
p.drawTextRight(st::contactsPadding.right() + st::contactsCheckPosition.x(), st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, width(), lang(s->disabled ? lng_stickers_return : lng_stickers_remove), s->disabled ? _returnWidth : _removeWidth);
|
||||
|
||||
if (index == _above) {
|
||||
float64 current = _aboveShadowFadeOpacity.current();
|
||||
if (_started >= 0) {
|
||||
float64 o = aboveShadowOpacity();
|
||||
if (o > current) {
|
||||
_aboveShadowFadeOpacity = anim::fvalue(o, o);
|
||||
current = o;
|
||||
}
|
||||
}
|
||||
p.setOpacity(current);
|
||||
QRect row(myrtlrect(_aboveShadow.getDimensions(st::boxShadowShift).left(), st::contactsPadding.top() / 2, width() - (st::contactsPadding.left() / 2) - _scrollbar - _aboveShadow.getDimensions(st::boxShadowShift).right(), _rowHeight - ((st::contactsPadding.top() + st::contactsPadding.bottom()) / 2)));
|
||||
_aboveShadow.paint(p, row, st::boxShadowShift);
|
||||
p.fillRect(row, st::white);
|
||||
p.setOpacity(1);
|
||||
}
|
||||
|
||||
if (s->disabled) p.setOpacity(st::stickersRowDisabledOpacity);
|
||||
if (s->sticker) {
|
||||
s->sticker->thumb->load();
|
||||
QPixmap pix(s->sticker->thumb->pix(s->pixw, s->pixh));
|
||||
p.drawPixmapLeft(st::contactsPadding.left() + (st::contactsPhotoSize - s->pixw) / 2, st::contactsPadding.top() + (st::contactsPhotoSize - s->pixh) / 2, width(), pix);
|
||||
}
|
||||
p.setFont(st::contactsNameFont);
|
||||
p.setPen(st::black);
|
||||
|
||||
int32 namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
||||
p.drawTextLeft(namex, st::contactsPadding.top() + st::contactsNameTop, width(), s->title);
|
||||
|
||||
p.setFont(st::contactsStatusFont);
|
||||
p.setPen(st::contactsStatusFg);
|
||||
p.drawTextLeft(namex, st::contactsPadding.top() + st::contactsStatusTop, width(), lng_stickers_count(lt_count, s->count));
|
||||
|
||||
p.setOpacity(1);
|
||||
if (xadd || yadd) p.translate(-xadd, -yadd);
|
||||
}
|
||||
|
||||
void StickersInner::mousePressEvent(QMouseEvent *e) {
|
||||
if (_saving) return;
|
||||
if (_dragging >= 0) mouseReleaseEvent(e);
|
||||
_mouse = e->globalPos();
|
||||
onUpdateSelected();
|
||||
if (_removeSel >= 0) {
|
||||
_removeDown = _removeSel;
|
||||
update(0, st::membersPadding.top() + _removeSel * _rowHeight, width(), _rowHeight);
|
||||
} else if (_selected >= 0) {
|
||||
_above = _dragging = _started = _selected;
|
||||
_dragStart = mapFromGlobal(_mouse);
|
||||
}
|
||||
}
|
||||
|
||||
void StickersInner::mouseMoveEvent(QMouseEvent *e) {
|
||||
if (_saving) return;
|
||||
_mouse = e->globalPos();
|
||||
onUpdateSelected();
|
||||
}
|
||||
|
||||
void StickersInner::onUpdateSelected() {
|
||||
if (_saving) return;
|
||||
QPoint local(mapFromGlobal(_mouse));
|
||||
if (_dragging >= 0) {
|
||||
int32 shift = 0;
|
||||
uint64 ms = getms();
|
||||
if (_dragStart.y() > local.y() && _dragging > 0) {
|
||||
shift = -floorclamp(_dragStart.y() - local.y() + (_rowHeight / 2), _rowHeight, 0, _dragging);
|
||||
for (int32 from = _dragging, to = _dragging + shift; from > to; --from) {
|
||||
qSwap(_rows[from], _rows[from - 1]);
|
||||
_rows.at(from)->yadd = anim::ivalue(_rows.at(from)->yadd.current() - _rowHeight, 0);
|
||||
_animStartTimes[from] = ms;
|
||||
}
|
||||
} else if (_dragStart.y() < local.y() && _dragging + 1 < _rows.size()) {
|
||||
shift = floorclamp(local.y() - _dragStart.y() + (_rowHeight / 2), _rowHeight, 0, _rows.size() - _dragging - 1);
|
||||
for (int32 from = _dragging, to = _dragging + shift; from < to; ++from) {
|
||||
qSwap(_rows[from], _rows[from + 1]);
|
||||
_rows.at(from)->yadd = anim::ivalue(_rows.at(from)->yadd.current() + _rowHeight, 0);
|
||||
_animStartTimes[from] = ms;
|
||||
}
|
||||
}
|
||||
if (shift) {
|
||||
_dragging += shift;
|
||||
_above = _dragging;
|
||||
_dragStart.setY(_dragStart.y() + shift * _rowHeight);
|
||||
if (!_a_shifting.animating()) {
|
||||
_a_shifting.start();
|
||||
}
|
||||
}
|
||||
// _rows.at(_dragging)->xadd = anim::ivalue(local.x() - _dragStart.x(), local.x() - _dragStart.x());
|
||||
_rows.at(_dragging)->yadd = anim::ivalue(local.y() - _dragStart.y(), local.y() - _dragStart.y());
|
||||
_animStartTimes[_dragging] = 0;
|
||||
update(0, st::membersPadding.top() + _rowHeight * (_dragging + qMin(shift, 0) - 1), width(), _rowHeight * (qMax(shift, 0) - qMin(shift, 0) + 3));
|
||||
|
||||
emit checkDraggingScroll(local.y());
|
||||
} else {
|
||||
bool in = rect().marginsRemoved(QMargins(0, st::membersPadding.top(), 0, st::membersPadding.bottom())).contains(local);
|
||||
_selected = in ? floorclamp(local.y() - st::membersPadding.top(), _rowHeight, 0, _rows.size() - 1) : -1;
|
||||
int32 removeSel = -1;
|
||||
|
||||
if (_selected >= 0) {
|
||||
int32 remw = _rows.at(_selected)->disabled ? _returnWidth : _removeWidth;
|
||||
QRect rem(myrtlrect(width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - remw, st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, remw, st::normalFont->height));
|
||||
removeSel = rem.contains(local.x(), local.y() - st::membersPadding.top() - _selected * _rowHeight) ? _selected : -1;
|
||||
}
|
||||
setRemoveSel(removeSel);
|
||||
emit noDraggingScroll();
|
||||
}
|
||||
}
|
||||
|
||||
float64 StickersInner::aboveShadowOpacity() const {
|
||||
if (_above < 0) return 0;
|
||||
|
||||
int32 dx = qAbs(_above * _rowHeight + _rows.at(_above)->yadd.current() - _started * _rowHeight);
|
||||
int32 dy = qAbs(_rows.at(_above)->xadd.current());
|
||||
return qMin((dx + dy) * 2. / _rowHeight, 1.);
|
||||
}
|
||||
|
||||
void StickersInner::mouseReleaseEvent(QMouseEvent *e) {
|
||||
if (_saving) return;
|
||||
_mouse = e->globalPos();
|
||||
onUpdateSelected();
|
||||
if (_removeDown == _removeSel && _removeSel >= 0) {
|
||||
_rows[_removeDown]->disabled = !_rows[_removeDown]->disabled;
|
||||
} else if (_dragging >= 0) {
|
||||
QPoint local(mapFromGlobal(_mouse));
|
||||
_rows[_dragging]->xadd.start(0);
|
||||
_rows[_dragging]->yadd.start(0);
|
||||
_aboveShadowFadeStart = _animStartTimes[_dragging] = getms();
|
||||
_aboveShadowFadeOpacity = anim::fvalue(aboveShadowOpacity(), 0);
|
||||
if (!_a_shifting.animating()) {
|
||||
_a_shifting.start();
|
||||
}
|
||||
|
||||
_dragging = _started = -1;
|
||||
}
|
||||
if (_removeDown >= 0) {
|
||||
update(0, st::membersPadding.top() + _removeDown * _rowHeight, width(), _rowHeight);
|
||||
_removeDown = -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool StickersInner::animStep_shifting(float64) {
|
||||
uint64 ms = getms();
|
||||
bool animating = false;
|
||||
int32 updateMin = -1, updateMax = 0;
|
||||
for (int32 i = 0, l = _animStartTimes.size(); i < l; ++i) {
|
||||
uint64 start = _animStartTimes.at(i);
|
||||
if (start) {
|
||||
if (updateMin < 0) updateMin = i;
|
||||
updateMax = i;
|
||||
if (start + st::stickersRowDuration > ms && ms > start) {
|
||||
_rows.at(i)->xadd.update((ms - start) / st::stickersRowDuration, anim::sineInOut);
|
||||
_rows.at(i)->yadd.update((ms - start) / st::stickersRowDuration, anim::sineInOut);
|
||||
animating = true;
|
||||
} else {
|
||||
_rows.at(i)->xadd.finish();
|
||||
_rows.at(i)->yadd.finish();
|
||||
_animStartTimes[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_aboveShadowFadeStart) {
|
||||
if (updateMin < 0 || updateMin > _above) updateMin = _above;
|
||||
if (updateMax < _above) updateMin = _above;
|
||||
if (_aboveShadowFadeStart + st::stickersRowDuration > ms && ms > _aboveShadowFadeStart) {
|
||||
_aboveShadowFadeOpacity.update((ms - _aboveShadowFadeStart) / st::stickersRowDuration, anim::sineInOut);
|
||||
animating = true;
|
||||
} else {
|
||||
_aboveShadowFadeOpacity.finish();
|
||||
_aboveShadowFadeStart = 0;
|
||||
}
|
||||
}
|
||||
if (updateMin >= 0) {
|
||||
update(0, st::membersPadding.top() + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3));
|
||||
}
|
||||
if (!animating) {
|
||||
_above = _dragging;
|
||||
}
|
||||
return animating;
|
||||
}
|
||||
|
||||
void StickersInner::clear() {
|
||||
for (int32 i = 0, l = _rows.size(); i < l; ++i) {
|
||||
delete _rows.at(i);
|
||||
}
|
||||
_rows.clear();
|
||||
_animStartTimes.clear();
|
||||
_aboveShadowFadeStart = 0;
|
||||
_aboveShadowFadeOpacity = anim::fvalue(0, 0);
|
||||
_a_shifting.stop();
|
||||
_above = _dragging = _started = -1;
|
||||
_selected = -1;
|
||||
_removeDown = -1;
|
||||
setRemoveSel(-1);
|
||||
update();
|
||||
}
|
||||
|
||||
void StickersInner::setRemoveSel(int32 removeSel) {
|
||||
if (removeSel != _removeSel) {
|
||||
if (_removeSel >= 0) update(0, st::membersPadding.top() + _removeSel * _rowHeight, width(), _rowHeight);
|
||||
_removeSel = removeSel;
|
||||
if (_removeSel >= 0) update(0, st::membersPadding.top() + _removeSel * _rowHeight, width(), _rowHeight);
|
||||
setCursor((_removeSel >= 0 && (_removeDown < 0 || _removeDown == _removeSel)) ? style::cur_pointer : style::cur_default);
|
||||
}
|
||||
}
|
||||
|
||||
void StickersInner::rebuild() {
|
||||
QList<StickerSetRow*> rows, rowsDisabled;
|
||||
|
||||
int32 namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
||||
int32 namew = st::boxWideWidth - namex - st::contactsPadding.right() - st::contactsCheckPosition.x() - qMax(_returnWidth, _removeWidth);
|
||||
|
||||
clear();
|
||||
const StickerSetsOrder &order(cStickerSetsOrder());
|
||||
_animStartTimes.reserve(order.size());
|
||||
|
||||
const StickerSets &sets(cStickerSets());
|
||||
for (int32 i = 0, l = order.size(); i < l; ++i) {
|
||||
StickerSets::const_iterator it = sets.constFind(order.at(i));
|
||||
if (it != sets.cend()) {
|
||||
bool disabled = (it->flags & MTPDstickerSet::flag_disabled);
|
||||
|
||||
DocumentData *sticker = it->stickers.isEmpty() ? 0 : it->stickers.at(0);
|
||||
int32 pixw = 0, pixh = 0;
|
||||
if (sticker) {
|
||||
pixw = sticker->thumb->width();
|
||||
pixh = sticker->thumb->height();
|
||||
if (pixw > st::contactsPhotoSize) {
|
||||
if (pixw > pixh) {
|
||||
pixh = (pixh * st::contactsPhotoSize) / pixw;
|
||||
pixw = st::contactsPhotoSize;
|
||||
} else {
|
||||
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
||||
pixh = st::contactsPhotoSize;
|
||||
}
|
||||
} else if (pixh > st::contactsPhotoSize) {
|
||||
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
||||
pixh = st::contactsPhotoSize;
|
||||
}
|
||||
}
|
||||
QString title = it->title;
|
||||
int32 titleWidth = st::contactsNameFont->width(title);
|
||||
if (titleWidth > namew) {
|
||||
title = st::contactsNameFont->elided(title, namew);
|
||||
}
|
||||
(disabled ? rowsDisabled : rows).push_back(new StickerSetRow(it->id, sticker, it->stickers.size(), title, disabled, pixw, pixh));
|
||||
_animStartTimes.push_back(0);
|
||||
if (it->stickers.isEmpty() || (it->flags & MTPDstickerSet_flag_NOT_LOADED)) {
|
||||
App::api()->scheduleStickerSetRequest(it->id, it->access);
|
||||
}
|
||||
}
|
||||
}
|
||||
App::api()->requestStickerSets();
|
||||
_rows = rows + rowsDisabled;
|
||||
resize(width(), st::membersPadding.top() + _rows.size() * _rowHeight + st::membersPadding.bottom());
|
||||
}
|
||||
|
||||
QVector<uint64> StickersInner::getOrder() const {
|
||||
QVector<uint64> result;
|
||||
result.reserve(_rows.size());
|
||||
for (int32 i = 0, l = _rows.size(); i < l; ++i) {
|
||||
if (_rows.at(i)->disabled) {
|
||||
StickerSets::const_iterator it = cStickerSets().constFind(_rows.at(i)->id);
|
||||
if (it == cStickerSets().cend() || !(it->flags & MTPDstickerSet::flag_official)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result.push_back(_rows.at(i)->id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QVector<uint64> StickersInner::getDisabledSets() const {
|
||||
QVector<uint64> result;
|
||||
result.reserve(_rows.size());
|
||||
for (int32 i = 0, l = _rows.size(); i < l; ++i) {
|
||||
if (_rows.at(i)->disabled) {
|
||||
result.push_back(_rows.at(i)->id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void StickersInner::setVisibleScrollbar(int32 width) {
|
||||
_scrollbar = width;
|
||||
}
|
||||
|
||||
StickersInner::~StickersInner() {
|
||||
clear();
|
||||
}
|
||||
|
||||
StickersBox::StickersBox() : ItemListBox(st::boxScroll)
|
||||
, _save(this, lang(lng_settings_save), st::defaultBoxButton)
|
||||
, _cancel(this, lang(lng_cancel), st::cancelBoxButton)
|
||||
, _reorderRequest(0)
|
||||
, _bottomShadow(this) {
|
||||
ItemListBox::init(&_inner, st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom());
|
||||
setMaxHeight(snap(countHeight(), int32(st::sessionsHeight), int32(st::boxMaxListHeight)));
|
||||
|
||||
connect(App::main(), SIGNAL(stickersUpdated()), this, SLOT(onStickersUpdated()));
|
||||
|
||||
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
||||
connect(&_save, SIGNAL(clicked()), this, SLOT(onSave()));
|
||||
|
||||
connect(&_inner, SIGNAL(checkDraggingScroll(int)), this, SLOT(onCheckDraggingScroll(int)));
|
||||
connect(&_inner, SIGNAL(noDraggingScroll()), this, SLOT(onNoDraggingScroll()));
|
||||
connect(&_scroll, SIGNAL(scrolled()), &_inner, SLOT(onUpdateSelected()));
|
||||
connect(&_scrollTimer, SIGNAL(timeout()), this, SLOT(onScrollTimer()));
|
||||
_scrollTimer.setSingleShot(false);
|
||||
|
||||
onStickersUpdated();
|
||||
|
||||
prepare();
|
||||
}
|
||||
|
||||
int32 StickersBox::countHeight() const {
|
||||
return st::boxTitleHeight + _inner.height() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom();
|
||||
}
|
||||
|
||||
void StickersBox::disenableDone(const MTPBool & result, mtpRequestId req) {
|
||||
_disenableRequests.remove(req);
|
||||
if (_disenableRequests.isEmpty()) {
|
||||
saveOrder();
|
||||
}
|
||||
}
|
||||
|
||||
bool StickersBox::disenableFail(const RPCError &error, mtpRequestId req) {
|
||||
if (mtpIsFlood(error)) return false;
|
||||
_disenableRequests.remove(req);
|
||||
if (_disenableRequests.isEmpty()) {
|
||||
saveOrder();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void StickersBox::saveOrder() {
|
||||
QVector<uint64> order = _inner.getOrder();
|
||||
if (order.size() > 1) {
|
||||
QVector<MTPlong> mtpOrder;
|
||||
mtpOrder.reserve(order.size());
|
||||
for (int32 i = 0, l = order.size(); i < l; ++i) {
|
||||
mtpOrder.push_back(MTP_long(order.at(i)));
|
||||
}
|
||||
_reorderRequest = MTP::send(MTPmessages_ReorderStickerSets(MTP_vector<MTPlong>(mtpOrder)), rpcDone(&StickersBox::reorderDone), rpcFail(&StickersBox::reorderFail));
|
||||
} else {
|
||||
reorderDone(MTP_boolTrue());
|
||||
}
|
||||
}
|
||||
|
||||
void StickersBox::reorderDone(const MTPBool &result) {
|
||||
_reorderRequest = 0;
|
||||
onClose();
|
||||
}
|
||||
|
||||
bool StickersBox::reorderFail(const RPCError &result) {
|
||||
if (mtpIsFlood(result)) return false;
|
||||
_reorderRequest = 0;
|
||||
cSetLastStickersUpdate(0);
|
||||
App::main()->updateStickers();
|
||||
onClose();
|
||||
return true;
|
||||
}
|
||||
|
||||
void StickersBox::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
if (paint(p)) return;
|
||||
|
||||
paintTitle(p, lang(lng_stickers_packs));
|
||||
p.translate(0, st::boxTitleHeight);
|
||||
}
|
||||
|
||||
void StickersBox::closePressed() {
|
||||
if (!_disenableRequests.isEmpty()) {
|
||||
for (QMap<mtpRequestId, NullType>::const_iterator i = _disenableRequests.cbegin(), e = _disenableRequests.cend(); i != e; ++i) {
|
||||
MTP::cancel(i.key());
|
||||
}
|
||||
_disenableRequests.clear();
|
||||
cSetLastStickersUpdate(0);
|
||||
App::main()->updateStickers();
|
||||
} else if (_reorderRequest) {
|
||||
MTP::cancel(_reorderRequest);
|
||||
_reorderRequest = 0;
|
||||
cSetLastStickersUpdate(0);
|
||||
App::main()->updateStickers();
|
||||
}
|
||||
}
|
||||
|
||||
void StickersBox::resizeEvent(QResizeEvent *e) {
|
||||
ItemListBox::resizeEvent(e);
|
||||
_save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height());
|
||||
_cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y());
|
||||
_inner.resize(width(), _inner.height());
|
||||
_bottomShadow.setGeometry(0, height() - st::boxButtonPadding.bottom() - _save.height() - st::boxButtonPadding.top() - st::lineWidth, width(), st::lineWidth);
|
||||
_inner.setVisibleScrollbar((_scroll.scrollTopMax() > 0) ? (st::boxScroll.width - st::boxScroll.deltax) : 0);
|
||||
}
|
||||
|
||||
void StickersBox::onStickersUpdated() {
|
||||
_inner.rebuild();
|
||||
setMaxHeight(snap(countHeight(), int32(st::sessionsHeight), int32(st::boxMaxListHeight)));
|
||||
_inner.setVisibleScrollbar((_scroll.scrollTopMax() > 0) ? (st::boxScroll.width - st::boxScroll.deltax) : 0);
|
||||
}
|
||||
|
||||
void StickersBox::onCheckDraggingScroll(int localY) {
|
||||
if (localY < _scroll.scrollTop()) {
|
||||
_scrollDelta = localY - _scroll.scrollTop();
|
||||
} else if (localY >= _scroll.scrollTop() + _scroll.height()) {
|
||||
_scrollDelta = localY - _scroll.scrollTop() - _scroll.height() + 1;
|
||||
} else {
|
||||
_scrollDelta = 0;
|
||||
}
|
||||
if (_scrollDelta) {
|
||||
_scrollTimer.start(15);
|
||||
} else {
|
||||
_scrollTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void StickersBox::onNoDraggingScroll() {
|
||||
_scrollTimer.stop();
|
||||
}
|
||||
|
||||
void StickersBox::onScrollTimer() {
|
||||
int32 d = (_scrollDelta > 0) ? qMin(_scrollDelta * 3 / 20 + 1, int32(MaxScrollSpeed)) : qMax(_scrollDelta * 3 / 20 - 1, -int32(MaxScrollSpeed));
|
||||
_scroll.scrollToY(_scroll.scrollTop() + d);
|
||||
}
|
||||
|
||||
void StickersBox::onSave() {
|
||||
if (!_inner.savingStart()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool writeRecent = false;
|
||||
RecentStickerPack &recent(cGetRecentStickers());
|
||||
StickerSets &sets(cRefStickerSets());
|
||||
|
||||
QVector<uint64> reorder = _inner.getOrder(), disabled = _inner.getDisabledSets();
|
||||
for (int32 i = 0, l = disabled.size(); i < l; ++i) {
|
||||
StickerSets::iterator it = sets.find(disabled.at(i));
|
||||
if (it != sets.cend()) {
|
||||
for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) {
|
||||
if (it->stickers.indexOf(i->first) >= 0) {
|
||||
i = recent.erase(i);
|
||||
writeRecent = true;
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (!(it->flags & MTPDstickerSet::flag_disabled)) {
|
||||
MTPInputStickerSet setId = (it->id && it->access) ? MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)) : MTP_inputStickerSetShortName(MTP_string(it->shortName));
|
||||
if (it->flags & MTPDstickerSet::flag_official) {
|
||||
_disenableRequests.insert(MTP::send(MTPmessages_InstallStickerSet(setId, MTP_boolTrue()), rpcDone(&StickersBox::disenableDone), rpcFail(&StickersBox::disenableFail), 0, 5), NullType());
|
||||
it->flags |= MTPDstickerSet::flag_disabled;
|
||||
} else {
|
||||
_disenableRequests.insert(MTP::send(MTPmessages_UninstallStickerSet(setId), rpcDone(&StickersBox::disenableDone), rpcFail(&StickersBox::disenableFail), 0, 5), NullType());
|
||||
cRefStickerSetsOrder().removeOne(it->id);
|
||||
sets.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StickerSetsOrder &order(cRefStickerSetsOrder());
|
||||
order.clear();
|
||||
for (int32 i = 0, l = reorder.size(); i < l; ++i) {
|
||||
StickerSets::iterator it = sets.find(reorder.at(i));
|
||||
if (it != sets.cend()) {
|
||||
if ((it->flags & MTPDstickerSet::flag_disabled) && !disabled.contains(it->id)) {
|
||||
MTPInputStickerSet setId = (it->id && it->access) ? MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)) : MTP_inputStickerSetShortName(MTP_string(it->shortName));
|
||||
_disenableRequests.insert(MTP::send(MTPmessages_InstallStickerSet(setId, MTP_boolFalse()), rpcDone(&StickersBox::disenableDone), rpcFail(&StickersBox::disenableFail), 0, 5), NullType());
|
||||
it->flags &= ~MTPDstickerSet::flag_disabled;
|
||||
}
|
||||
order.push_back(reorder.at(i));
|
||||
}
|
||||
}
|
||||
for (StickerSets::iterator it = sets.begin(); it != sets.cend();) {
|
||||
if (it->id == CustomStickerSetId || it->id == RecentStickerSetId || order.contains(it->id)) {
|
||||
++it;
|
||||
} else {
|
||||
it = sets.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
cSetStickersHash(stickersCountHash());
|
||||
Local::writeStickers();
|
||||
if (writeRecent) Local::writeUserSettings();
|
||||
emit App::main()->stickersUpdated();
|
||||
|
||||
if (_disenableRequests.isEmpty()) {
|
||||
saveOrder();
|
||||
} else {
|
||||
MTP::sendAnything();
|
||||
}
|
||||
}
|
||||
|
||||
void StickersBox::hideAll() {
|
||||
_save.hide();
|
||||
_cancel.hide();
|
||||
_bottomShadow.hide();
|
||||
ItemListBox::hideAll();
|
||||
}
|
||||
|
||||
void StickersBox::showAll() {
|
||||
_save.show();
|
||||
_cancel.show();
|
||||
_bottomShadow.show();
|
||||
ItemListBox::showAll();
|
||||
}
|
||||
|
||||
int32 stickerPacksCount(bool includeDisabledOfficial) {
|
||||
int32 result = 0;
|
||||
const StickerSetsOrder &order(cStickerSetsOrder());
|
||||
const StickerSets &sets(cStickerSets());
|
||||
for (int32 i = 0, l = order.size(); i < l; ++i) {
|
||||
StickerSets::const_iterator it = sets.constFind(order.at(i));
|
||||
if (it != sets.cend()) {
|
||||
if (!(it->flags & MTPDstickerSet::flag_disabled) || ((it->flags & MTPDstickerSet::flag_official) && includeDisabledOfficial)) {
|
||||
++result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@@ -106,3 +106,136 @@ private:
|
||||
BoxButton _add, _share, _cancel, _done;
|
||||
QString _title;
|
||||
};
|
||||
|
||||
class StickersInner : public TWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
StickersInner();
|
||||
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
|
||||
void rebuild();
|
||||
bool savingStart() {
|
||||
if (_saving) return false;
|
||||
_saving = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<uint64> getOrder() const;
|
||||
QVector<uint64> getDisabledSets() const;
|
||||
|
||||
void setVisibleScrollbar(int32 width);
|
||||
|
||||
~StickersInner();
|
||||
|
||||
signals:
|
||||
|
||||
void checkDraggingScroll(int localY);
|
||||
void noDraggingScroll();
|
||||
|
||||
public slots:
|
||||
|
||||
void onUpdateSelected();
|
||||
|
||||
private:
|
||||
|
||||
bool animStep_shifting(float64 ms);
|
||||
void paintRow(Painter &p, int32 index);
|
||||
void clear();
|
||||
void setRemoveSel(int32 removeSel);
|
||||
float64 aboveShadowOpacity() const;
|
||||
|
||||
int32 _rowHeight;
|
||||
struct StickerSetRow {
|
||||
StickerSetRow(uint64 id, DocumentData *sticker, int32 count, const QString &title, bool disabled, int32 pixw, int32 pixh) : id(id)
|
||||
, sticker(sticker)
|
||||
, count(count)
|
||||
, title(title)
|
||||
, disabled(disabled)
|
||||
, pixw(pixw)
|
||||
, pixh(pixh)
|
||||
, xadd(0, 0)
|
||||
, yadd(0, 0) {
|
||||
}
|
||||
uint64 id;
|
||||
DocumentData *sticker;
|
||||
int32 count;
|
||||
QString title;
|
||||
bool disabled;
|
||||
int32 pixw, pixh;
|
||||
anim::ivalue xadd, yadd;
|
||||
};
|
||||
typedef QList<StickerSetRow*> StickerSetRows;
|
||||
StickerSetRows _rows;
|
||||
QList<uint64> _animStartTimes;
|
||||
uint64 _aboveShadowFadeStart;
|
||||
anim::fvalue _aboveShadowFadeOpacity;
|
||||
Animation _a_shifting;
|
||||
|
||||
bool _saving;
|
||||
|
||||
int32 _removeSel, _removeDown, _removeWidth, _returnWidth;
|
||||
|
||||
QPoint _mouse;
|
||||
int32 _selected;
|
||||
QPoint _dragStart;
|
||||
int32 _started, _dragging, _above;
|
||||
|
||||
BoxShadow _aboveShadow;
|
||||
|
||||
int32 _scrollbar;
|
||||
};
|
||||
|
||||
class StickersBox : public ItemListBox, public RPCSender {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
StickersBox();
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
void closePressed();
|
||||
|
||||
public slots:
|
||||
|
||||
void onStickersUpdated();
|
||||
|
||||
void onCheckDraggingScroll(int localY);
|
||||
void onNoDraggingScroll();
|
||||
void onScrollTimer();
|
||||
|
||||
void onSave();
|
||||
|
||||
protected:
|
||||
|
||||
void hideAll();
|
||||
void showAll();
|
||||
|
||||
private:
|
||||
|
||||
int32 countHeight() const;
|
||||
|
||||
void disenableDone(const MTPBool &result, mtpRequestId req);
|
||||
bool disenableFail(const RPCError &error, mtpRequestId req);
|
||||
void reorderDone(const MTPBool &result);
|
||||
bool reorderFail(const RPCError &result);
|
||||
void saveOrder();
|
||||
|
||||
StickersInner _inner;
|
||||
BoxButton _save, _cancel;
|
||||
QMap<mtpRequestId, NullType> _disenableRequests;
|
||||
mtpRequestId _reorderRequest;
|
||||
ScrollableBoxShadow _bottomShadow;
|
||||
|
||||
QTimer _scrollTimer;
|
||||
int32 _scrollDelta;
|
||||
|
||||
};
|
||||
|
||||
int32 stickerPacksCount(bool includeDisabledOfficial = false);
|
||||
|
Reference in New Issue
Block a user