mirror of https://github.com/procxx/kepka.git
				
				
				
			Use sticker set thumbnails in StickersBox.
This commit is contained in:
		
							parent
							
								
									72d9ac508a
								
							
						
					
					
						commit
						4ba959e6e1
					
				| 
						 | 
					@ -619,6 +619,7 @@ StickersBox::~StickersBox() = default;
 | 
				
			||||||
StickersBox::Inner::Row::Row(
 | 
					StickersBox::Inner::Row::Row(
 | 
				
			||||||
	uint64 id,
 | 
						uint64 id,
 | 
				
			||||||
	uint64 accessHash,
 | 
						uint64 accessHash,
 | 
				
			||||||
 | 
						ImagePtr thumbnail,
 | 
				
			||||||
	DocumentData *sticker,
 | 
						DocumentData *sticker,
 | 
				
			||||||
	int32 count,
 | 
						int32 count,
 | 
				
			||||||
	const QString &title,
 | 
						const QString &title,
 | 
				
			||||||
| 
						 | 
					@ -632,6 +633,7 @@ StickersBox::Inner::Row::Row(
 | 
				
			||||||
	int32 pixh)
 | 
						int32 pixh)
 | 
				
			||||||
: id(id)
 | 
					: id(id)
 | 
				
			||||||
, accessHash(accessHash)
 | 
					, accessHash(accessHash)
 | 
				
			||||||
 | 
					, thumbnail(thumbnail)
 | 
				
			||||||
, sticker(sticker)
 | 
					, sticker(sticker)
 | 
				
			||||||
, count(count)
 | 
					, count(count)
 | 
				
			||||||
, title(title)
 | 
					, title(title)
 | 
				
			||||||
| 
						 | 
					@ -850,7 +852,10 @@ void StickersBox::Inner::paintRow(Painter &p, Row *set, int index, crl::time ms)
 | 
				
			||||||
		const auto origin = Data::FileOriginStickerSet(
 | 
							const auto origin = Data::FileOriginStickerSet(
 | 
				
			||||||
			set->id,
 | 
								set->id,
 | 
				
			||||||
			set->accessHash);
 | 
								set->accessHash);
 | 
				
			||||||
		if (const auto thumb = set->sticker->thumbnail()) {
 | 
							const auto thumb = set->thumbnail
 | 
				
			||||||
 | 
								? set->thumbnail.get()
 | 
				
			||||||
 | 
								: set->sticker->thumbnail();
 | 
				
			||||||
 | 
							if (thumb) {
 | 
				
			||||||
			thumb->load(origin);
 | 
								thumb->load(origin);
 | 
				
			||||||
			auto pix = thumb->pix(origin, set->pixw, set->pixh);
 | 
								auto pix = thumb->pix(origin, set->pixw, set->pixh);
 | 
				
			||||||
			p.drawPixmapLeft(stickerx + (st::contactsPhotoSize - set->pixw) / 2, st::contactsPadding.top() + (st::contactsPhotoSize - set->pixh) / 2, width(), pix);
 | 
								p.drawPixmapLeft(stickerx + (st::contactsPhotoSize - set->pixw) / 2, st::contactsPadding.top() + (st::contactsPhotoSize - set->pixh) / 2, width(), pix);
 | 
				
			||||||
| 
						 | 
					@ -1227,6 +1232,7 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void StickersBox::Inner::saveGroupSet() {
 | 
					void StickersBox::Inner::saveGroupSet() {
 | 
				
			||||||
	Expects(_megagroupSet != nullptr);
 | 
						Expects(_megagroupSet != nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto oldId = (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) ? _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid.v : 0;
 | 
						auto oldId = (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) ? _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid.v : 0;
 | 
				
			||||||
	auto newId = (_megagroupSetInput.type() == mtpc_inputStickerSetID) ? _megagroupSetInput.c_inputStickerSetID().vid.v : 0;
 | 
						auto newId = (_megagroupSetInput.type() == mtpc_inputStickerSetID) ? _megagroupSetInput.c_inputStickerSetID().vid.v : 0;
 | 
				
			||||||
	if (newId != oldId) {
 | 
						if (newId != oldId) {
 | 
				
			||||||
| 
						 | 
					@ -1407,9 +1413,10 @@ void StickersBox::Inner::rebuildMegagroupSet() {
 | 
				
			||||||
	auto titleWidth = 0;
 | 
						auto titleWidth = 0;
 | 
				
			||||||
	auto title = fillSetTitle(*it, maxNameWidth, &titleWidth);
 | 
						auto title = fillSetTitle(*it, maxNameWidth, &titleWidth);
 | 
				
			||||||
	auto count = fillSetCount(*it);
 | 
						auto count = fillSetCount(*it);
 | 
				
			||||||
 | 
						auto thumbnail = ImagePtr();
 | 
				
			||||||
	auto sticker = (DocumentData*)nullptr;
 | 
						auto sticker = (DocumentData*)nullptr;
 | 
				
			||||||
	auto pixw = 0, pixh = 0;
 | 
						auto pixw = 0, pixh = 0;
 | 
				
			||||||
	fillSetCover(*it, &sticker, &pixw, &pixh);
 | 
						fillSetCover(*it, &thumbnail, &sticker, &pixw, &pixh);
 | 
				
			||||||
	auto installed = true, official = false, unread = false, archived = false, removed = false;
 | 
						auto installed = true, official = false, unread = false, archived = false, removed = false;
 | 
				
			||||||
	if (!_megagroupSelectedSet || _megagroupSelectedSet->id != it->id) {
 | 
						if (!_megagroupSelectedSet || _megagroupSelectedSet->id != it->id) {
 | 
				
			||||||
		_megagroupSetField->setText(it->shortName);
 | 
							_megagroupSetField->setText(it->shortName);
 | 
				
			||||||
| 
						 | 
					@ -1418,6 +1425,7 @@ void StickersBox::Inner::rebuildMegagroupSet() {
 | 
				
			||||||
	_megagroupSelectedSet = std::make_unique<Row>(
 | 
						_megagroupSelectedSet = std::make_unique<Row>(
 | 
				
			||||||
		it->id,
 | 
							it->id,
 | 
				
			||||||
		it->access,
 | 
							it->access,
 | 
				
			||||||
 | 
							thumbnail,
 | 
				
			||||||
		sticker,
 | 
							sticker,
 | 
				
			||||||
		count,
 | 
							count,
 | 
				
			||||||
		title,
 | 
							title,
 | 
				
			||||||
| 
						 | 
					@ -1525,10 +1533,12 @@ void StickersBox::Inner::updateRows() {
 | 
				
			||||||
		if (it != sets.cend()) {
 | 
							if (it != sets.cend()) {
 | 
				
			||||||
			auto &set = it.value();
 | 
								auto &set = it.value();
 | 
				
			||||||
			if (!row->sticker) {
 | 
								if (!row->sticker) {
 | 
				
			||||||
 | 
									auto thumbnail = ImagePtr();
 | 
				
			||||||
				auto sticker = (DocumentData*)nullptr;
 | 
									auto sticker = (DocumentData*)nullptr;
 | 
				
			||||||
				auto pixw = 0, pixh = 0;
 | 
									auto pixw = 0, pixh = 0;
 | 
				
			||||||
				fillSetCover(set, &sticker, &pixw, &pixh);
 | 
									fillSetCover(set, &thumbnail, &sticker, &pixw, &pixh);
 | 
				
			||||||
				if (sticker) {
 | 
									if (sticker) {
 | 
				
			||||||
 | 
										row->thumbnail = thumbnail;
 | 
				
			||||||
					row->sticker = sticker;
 | 
										row->sticker = sticker;
 | 
				
			||||||
					row->pixw = pixw;
 | 
										row->pixw = pixw;
 | 
				
			||||||
					row->pixh = pixh;
 | 
										row->pixh = pixh;
 | 
				
			||||||
| 
						 | 
					@ -1590,9 +1600,10 @@ void StickersBox::Inner::rebuildAppendSet(const Stickers::Set &set, int maxNameW
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ImagePtr thumbnail;
 | 
				
			||||||
	DocumentData *sticker = nullptr;
 | 
						DocumentData *sticker = nullptr;
 | 
				
			||||||
	int pixw = 0, pixh = 0;
 | 
						int pixw = 0, pixh = 0;
 | 
				
			||||||
	fillSetCover(set, &sticker, &pixw, &pixh);
 | 
						fillSetCover(set, &thumbnail, &sticker, &pixw, &pixh);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int titleWidth = 0;
 | 
						int titleWidth = 0;
 | 
				
			||||||
	QString title = fillSetTitle(set, maxNameWidth, &titleWidth);
 | 
						QString title = fillSetTitle(set, maxNameWidth, &titleWidth);
 | 
				
			||||||
| 
						 | 
					@ -1601,6 +1612,7 @@ void StickersBox::Inner::rebuildAppendSet(const Stickers::Set &set, int maxNameW
 | 
				
			||||||
	_rows.push_back(std::make_unique<Row>(
 | 
						_rows.push_back(std::make_unique<Row>(
 | 
				
			||||||
		set.id,
 | 
							set.id,
 | 
				
			||||||
		set.access,
 | 
							set.access,
 | 
				
			||||||
 | 
							thumbnail,
 | 
				
			||||||
		sticker,
 | 
							sticker,
 | 
				
			||||||
		count,
 | 
							count,
 | 
				
			||||||
		title,
 | 
							title,
 | 
				
			||||||
| 
						 | 
					@ -1615,7 +1627,8 @@ void StickersBox::Inner::rebuildAppendSet(const Stickers::Set &set, int maxNameW
 | 
				
			||||||
	_animStartTimes.push_back(0);
 | 
						_animStartTimes.push_back(0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void StickersBox::Inner::fillSetCover(const Stickers::Set &set, DocumentData **outSticker, int *outWidth, int *outHeight) const {
 | 
					void StickersBox::Inner::fillSetCover(const Stickers::Set &set, ImagePtr *thumbnail, DocumentData **outSticker, int *outWidth, int *outHeight) const {
 | 
				
			||||||
 | 
						*thumbnail = set.thumbnail;
 | 
				
			||||||
	if (set.stickers.isEmpty()) {
 | 
						if (set.stickers.isEmpty()) {
 | 
				
			||||||
		*outSticker = nullptr;
 | 
							*outSticker = nullptr;
 | 
				
			||||||
		*outWidth = *outHeight = 0;
 | 
							*outWidth = *outHeight = 0;
 | 
				
			||||||
| 
						 | 
					@ -1623,7 +1636,9 @@ void StickersBox::Inner::fillSetCover(const Stickers::Set &set, DocumentData **o
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	auto sticker = *outSticker = set.stickers.front();
 | 
						auto sticker = *outSticker = set.stickers.front();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto size = sticker->thumbnail()
 | 
						const auto size = set.thumbnail
 | 
				
			||||||
 | 
							? set.thumbnail->size()
 | 
				
			||||||
 | 
							: sticker->thumbnail()
 | 
				
			||||||
		? sticker->thumbnail()->size()
 | 
							? sticker->thumbnail()->size()
 | 
				
			||||||
		: QSize(1, 1);
 | 
							: QSize(1, 1);
 | 
				
			||||||
	auto pixw = size.width();
 | 
						auto pixw = size.width();
 | 
				
			||||||
| 
						 | 
					@ -1785,9 +1800,13 @@ void StickersBox::Inner::readVisibleSets() {
 | 
				
			||||||
		if (i * _rowHeight < itemsVisibleTop || (i + 1) * _rowHeight > itemsVisibleBottom) {
 | 
							if (i * _rowHeight < itemsVisibleTop || (i + 1) * _rowHeight > itemsVisibleBottom) {
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!_rows[i]->sticker
 | 
							const auto thumbnail = !_rows[i]->sticker
 | 
				
			||||||
			|| !_rows[i]->sticker->hasThumbnail()
 | 
								? nullptr
 | 
				
			||||||
			|| _rows[i]->sticker->thumbnail()->loaded()
 | 
								: _rows[i]->thumbnail
 | 
				
			||||||
 | 
								? _rows[i]->thumbnail.get()
 | 
				
			||||||
 | 
								: _rows[i]->sticker->thumbnail();
 | 
				
			||||||
 | 
							if (!thumbnail
 | 
				
			||||||
 | 
								|| thumbnail->loaded()
 | 
				
			||||||
			|| _rows[i]->sticker->loaded()) {
 | 
								|| _rows[i]->sticker->loaded()) {
 | 
				
			||||||
			Auth().api().readFeaturedSetDelayed(_rows[i]->id);
 | 
								Auth().api().readFeaturedSetDelayed(_rows[i]->id);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -199,6 +199,7 @@ private:
 | 
				
			||||||
		Row(
 | 
							Row(
 | 
				
			||||||
			uint64 id,
 | 
								uint64 id,
 | 
				
			||||||
			uint64 accessHash,
 | 
								uint64 accessHash,
 | 
				
			||||||
 | 
								ImagePtr thumbnail,
 | 
				
			||||||
			DocumentData *sticker,
 | 
								DocumentData *sticker,
 | 
				
			||||||
			int32 count,
 | 
								int32 count,
 | 
				
			||||||
			const QString &title,
 | 
								const QString &title,
 | 
				
			||||||
| 
						 | 
					@ -217,6 +218,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		uint64 id = 0;
 | 
							uint64 id = 0;
 | 
				
			||||||
		uint64 accessHash = 0;
 | 
							uint64 accessHash = 0;
 | 
				
			||||||
 | 
							ImagePtr thumbnail;
 | 
				
			||||||
		DocumentData *sticker = nullptr;
 | 
							DocumentData *sticker = nullptr;
 | 
				
			||||||
		int32 count = 0;
 | 
							int32 count = 0;
 | 
				
			||||||
		QString title;
 | 
							QString title;
 | 
				
			||||||
| 
						 | 
					@ -279,7 +281,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void updateControlsGeometry();
 | 
						void updateControlsGeometry();
 | 
				
			||||||
	void rebuildAppendSet(const Stickers::Set &set, int maxNameWidth);
 | 
						void rebuildAppendSet(const Stickers::Set &set, int maxNameWidth);
 | 
				
			||||||
	void fillSetCover(const Stickers::Set &set, DocumentData **outSticker, int *outWidth, int *outHeight) const;
 | 
						void fillSetCover(const Stickers::Set &set, ImagePtr *thumbnail, DocumentData **outSticker, int *outWidth, int *outHeight) const;
 | 
				
			||||||
	int fillSetCount(const Stickers::Set &set) const;
 | 
						int fillSetCount(const Stickers::Set &set) const;
 | 
				
			||||||
	QString fillSetTitle(const Stickers::Set &set, int maxNameWidth, int *outTitleWidth) const;
 | 
						QString fillSetTitle(const Stickers::Set &set, int maxNameWidth, int *outTitleWidth) const;
 | 
				
			||||||
	void fillSetFlags(const Stickers::Set &set, bool *outInstalled, bool *outOfficial, bool *outUnread, bool *outArchived);
 | 
						void fillSetFlags(const Stickers::Set &set, bool *outInstalled, bool *outOfficial, bool *outUnread, bool *outArchived);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue