void StickerSetInner::paintEvent(QPaintEvent *e) { QRect r(e->rect()); Painter p(this); if (_pack.isEmpty()) return; int32 rows = _pack.size() / StickerPanPerRow + ((_pack.size() % StickerPanPerRow) ? 1 : 0); int32 from = qFloor(e->rect().top() / st::stickersSize.height()), to = qFloor(e->rect().bottom() / st::stickersSize.height()) + 1; for (int32 i = from; i < to; ++i) { for (int32 j = 0; j < StickerPanPerRow; ++j) { int32 index = i * StickerPanPerRow + j; if (index >= _pack.size()) break; DocumentData *doc = _pack.at(index); QPoint pos(st::stickerPanPadding + j * st::stickersSize.width(), i * st::stickersSize.height()); bool goodThumb = !doc->thumb->isNull() && ((doc->thumb->width() >= 128) || (doc->thumb->height() >= 128)); if (goodThumb) { doc->thumb->load(); } else { bool already = !doc->already().isEmpty(), hasdata = !doc->data.isEmpty(); if (!doc->loader && doc->status != FileFailed && !already && !hasdata) { doc->save(QString()); } if (doc->sticker()->img->isNull() && (already || hasdata)) { if (already) { doc->sticker()->img = ImagePtr(doc->already()); } else { doc->sticker()->img = ImagePtr(doc->data); } } } float64 coef = qMin((st::stickersSize.width() - st::msgRadius * 2) / float64(doc->dimensions.width()), (st::stickersSize.height() - st::msgRadius * 2) / float64(doc->dimensions.height())); if (coef > 1) coef = 1; int32 w = qRound(coef * doc->dimensions.width()), h = qRound(coef * doc->dimensions.height()); if (w < 1) w = 1; if (h < 1) h = 1; QPoint ppos = pos + QPoint((st::stickersSize.width() - w) / 2, (st::stickersSize.height() - h) / 2); if (goodThumb) { p.drawPixmapLeft(ppos, width(), doc->thumb->pix(w, h)); } else if (!doc->sticker()->img->isNull()) { p.drawPixmapLeft(ppos, width(), doc->sticker()->img->pix(w, h)); } } } p.fillRect(0, _bottom - st::stickersAddOrShare, width(), st::stickersAddOrShare, st::emojiPanHeaderBg->b); }
void StickerSetInner::gotSet(const MTPmessages_StickerSet &set) { _pack.clear(); if (set.type() == mtpc_messages_stickerSet) { const MTPDmessages_stickerSet &d(set.c_messages_stickerSet()); const QVector<MTPDocument> &v(d.vdocuments.c_vector().v); _pack.reserve(v.size()); for (int32 i = 0, l = v.size(); i < l; ++i) { DocumentData *doc = App::feedDocument(v.at(i)); if (!doc || !doc->sticker()) continue; _pack.push_back(doc); } if (d.vset.type() == mtpc_stickerSet) { const MTPDstickerSet &s(d.vset.c_stickerSet()); _setTitle = qs(s.vtitle); _title = st::boxTitleFont->m.elidedText(_setTitle, Qt::ElideRight, width() - st::btnStickersClose.width - st::boxTitlePos.x()); _setShortName = qs(s.vshort_name); _setId = s.vid.v; _setAccess = s.vaccess_hash.v; _setCount = s.vcount.v; _setHash = s.vhash.v; _setFlags = s.vflags.v; } } if (_pack.isEmpty()) { App::wnd()->showLayer(new ConfirmBox(lang(lng_stickers_not_found), true), true); } else { int32 rows = _pack.size() / StickerPanPerRow + ((_pack.size() % StickerPanPerRow) ? 1 : 0); resize(st::stickersPadding + StickerPanPerRow * st::stickersSize.width(), rows * st::stickersSize.height() + st::stickersAddOrShare); } _loaded = true; emit updateButtons(); }
void ApiWrap::gotStickerSet(uint64 setId, const MTPmessages_StickerSet &result) { _stickerSetRequests.remove(setId); if (result.type() != mtpc_messages_stickerSet) return; const MTPDmessages_stickerSet &d(result.c_messages_stickerSet()); if (d.vset.type() != mtpc_stickerSet) return; const MTPDstickerSet &s(d.vset.c_stickerSet()); StickerSets &sets(cRefStickerSets()); StickerSets::iterator it = sets.find(setId); if (it == sets.cend()) return; it->access = s.vaccess_hash.v; it->hash = s.vhash.v; it->shortName = qs(s.vshort_name); it->title = stickerSetTitle(s); it->flags = s.vflags.v; const QVector<MTPDocument> &d_docs(d.vdocuments.c_vector().v); StickerSets::iterator custom = sets.find(CustomStickerSetId); StickerPack pack; pack.reserve(d_docs.size()); for (int32 i = 0, l = d_docs.size(); i != l; ++i) { DocumentData *doc = App::feedDocument(d_docs.at(i)); if (!doc || !doc->sticker()) continue; pack.push_back(doc); if (custom != sets.cend()) { int32 index = custom->stickers.indexOf(doc); if (index >= 0) { custom->stickers.removeAt(index); } } } if (custom != sets.cend() && custom->stickers.isEmpty()) { sets.erase(custom); custom = sets.end(); } bool writeRecent = false; RecentStickerPack &recent(cGetRecentStickers()); for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) { if (it->stickers.indexOf(i->first) >= 0 && pack.indexOf(i->first) < 0) { i = recent.erase(i); writeRecent = true; } else { ++i; } } if (pack.isEmpty()) { int32 removeIndex = cStickerSetsOrder().indexOf(setId); if (removeIndex >= 0) cRefStickerSetsOrder().removeAt(removeIndex); sets.erase(it); } else { it->stickers = pack; } if (writeRecent) { Local::writeUserSettings(); } Local::writeStickers(); if (App::main()) emit App::main()->stickersUpdated(); }
void ApiWrap::gotStickerSet(uint64 setId, const MTPmessages_StickerSet &result) { _stickerSetRequests.remove(setId); if (result.type() != mtpc_messages_stickerSet) return; const MTPDmessages_stickerSet &d(result.c_messages_stickerSet()); if (d.vset.type() != mtpc_stickerSet) return; const MTPDstickerSet &s(d.vset.c_stickerSet()); StickerSets &sets(cRefStickerSets()); StickerSets::iterator it = sets.find(setId); if (it == sets.cend()) return; it->access = s.vaccess_hash.v; it->hash = s.vhash.v; it->shortName = qs(s.vshort_name); QString title = qs(s.vtitle); if ((it->flags & MTPDstickerSet_flag_official) && !title.compare(qstr("Great Minds"), Qt::CaseInsensitive)) { title = lang(lng_stickers_default_set); } it->title = title; it->flags = s.vflags.v; const QVector<MTPDocument> &d_docs(d.vdocuments.c_vector().v); StickerSets::iterator custom = sets.find(CustomStickerSetId); QSet<DocumentData*> found; int32 wasCount = -1; for (int32 i = 0, l = d_docs.size(); i != l; ++i) { DocumentData *doc = App::feedDocument(d_docs.at(i)); if (!doc || !doc->sticker()) continue; if (wasCount < 0) wasCount = it->stickers.size(); if (it->stickers.indexOf(doc) < 0) { it->stickers.push_back(doc); } else { found.insert(doc); } if (custom != sets.cend()) { int32 index = custom->stickers.indexOf(doc); if (index >= 0) { custom->stickers.removeAt(index); } } } if (custom != sets.cend() && custom->stickers.isEmpty()) { sets.erase(custom); custom = sets.end(); } bool writeRecent = false; RecentStickerPack &recent(cGetRecentStickers()); if (wasCount < 0) { // no stickers received for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) { if (it->stickers.indexOf(i->first) >= 0) { i = recent.erase(i); writeRecent = true; } else { ++i; } } cRefStickerSetsOrder().removeOne(setId); sets.erase(it); } else { for (int32 j = 0, l = wasCount; j < l;) { if (found.contains(it->stickers.at(j))) { ++j; } else { for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) { if (it->stickers.at(j) == i->first) { i = recent.erase(i); writeRecent = true; } else { ++i; } } it->stickers.removeAt(j); --l; } } if (it->stickers.isEmpty()) { cRefStickerSetsOrder().removeOne(setId); sets.erase(it); } } if (writeRecent) { Local::writeUserSettings(); } Local::writeStickers(); if (App::main()) emit App::main()->stickersUpdated(); }