mirror of https://github.com/procxx/kepka.git
				
				
				
			Fix photo edit caption box, remove 's' size.
This commit is contained in:
		
							parent
							
								
									af0eebb6f1
								
							
						
					
					
						commit
						74ef8104a7
					
				| 
						 | 
					@ -80,7 +80,17 @@ EditCaptionBox::EditCaptionBox(
 | 
				
			||||||
		_photoMedia = photo->createMediaView();
 | 
							_photoMedia = photo->createMediaView();
 | 
				
			||||||
		_photoMedia->wanted(PhotoSize::Large, _msgId);
 | 
							_photoMedia->wanted(PhotoSize::Large, _msgId);
 | 
				
			||||||
		image = _photoMedia->image(PhotoSize::Large);
 | 
							image = _photoMedia->image(PhotoSize::Large);
 | 
				
			||||||
 | 
							if (!image) {
 | 
				
			||||||
 | 
								image = _photoMedia->image(PhotoSize::Thumbnail);
 | 
				
			||||||
 | 
								if (!image) {
 | 
				
			||||||
 | 
									image = _photoMedia->image(PhotoSize::Small);
 | 
				
			||||||
 | 
									if (!image) {
 | 
				
			||||||
 | 
										image = _photoMedia->thumbnailInline();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		dimensions = _photoMedia->size(PhotoSize::Large);
 | 
							dimensions = _photoMedia->size(PhotoSize::Large);
 | 
				
			||||||
 | 
							_photo = true;
 | 
				
			||||||
	} else if (const auto document = media->document()) {
 | 
						} else if (const auto document = media->document()) {
 | 
				
			||||||
		_documentMedia = document->createMediaView();
 | 
							_documentMedia = document->createMediaView();
 | 
				
			||||||
		_documentMedia->thumbnailWanted(_msgId);
 | 
							_documentMedia->thumbnailWanted(_msgId);
 | 
				
			||||||
| 
						 | 
					@ -183,14 +193,23 @@ EditCaptionBox::EditCaptionBox(
 | 
				
			||||||
			maxH = dimensions.height();
 | 
								maxH = dimensions.height();
 | 
				
			||||||
			_thumbnailImage = image;
 | 
								_thumbnailImage = image;
 | 
				
			||||||
			_refreshThumbnail = [=] {
 | 
								_refreshThumbnail = [=] {
 | 
				
			||||||
				if (!_thumbnailImage) {
 | 
									const auto photo = _photoMedia
 | 
				
			||||||
					return;
 | 
										? _photoMedia->image(Data::PhotoSize::Large)
 | 
				
			||||||
				}
 | 
										: nullptr;
 | 
				
			||||||
				_thumb = _thumbnailImage->pixNoCache(
 | 
									const auto use = photo
 | 
				
			||||||
 | 
										? photo
 | 
				
			||||||
 | 
										:  _thumbnailImage
 | 
				
			||||||
 | 
										? _thumbnailImage
 | 
				
			||||||
 | 
										: Image::BlankMedia().get();
 | 
				
			||||||
 | 
									const auto options = Images::Option::Smooth
 | 
				
			||||||
 | 
										| ((_photoMedia && !photo)
 | 
				
			||||||
 | 
											? Images::Option::Blurred
 | 
				
			||||||
 | 
											: Images::Option(0));
 | 
				
			||||||
 | 
									_thumb = use->pixNoCache(
 | 
				
			||||||
					_msgId,
 | 
										_msgId,
 | 
				
			||||||
					maxW * cIntRetinaFactor(),
 | 
										maxW * cIntRetinaFactor(),
 | 
				
			||||||
					maxH * cIntRetinaFactor(),
 | 
										maxH * cIntRetinaFactor(),
 | 
				
			||||||
					Images::Option::Smooth,
 | 
										options,
 | 
				
			||||||
					maxW,
 | 
										maxW,
 | 
				
			||||||
					maxH);
 | 
										maxH);
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
| 
						 | 
					@ -260,10 +279,10 @@ EditCaptionBox::EditCaptionBox(
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	Assert(_animated || _photo || _doc);
 | 
						Assert(_animated || _photo || _doc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_thumbnailImageLoaded = _thumbnailImage
 | 
						_thumbnailImageLoaded = _photoMedia
 | 
				
			||||||
 | 
							? _photoMedia->image(Data::PhotoSize::Large)
 | 
				
			||||||
 | 
							: _thumbnailImage
 | 
				
			||||||
		? _thumbnailImage->loaded()
 | 
							? _thumbnailImage->loaded()
 | 
				
			||||||
		: _photoMedia
 | 
					 | 
				
			||||||
		? false
 | 
					 | 
				
			||||||
		: _documentMedia
 | 
							: _documentMedia
 | 
				
			||||||
		? !_documentMedia->owner()->hasThumbnail()
 | 
							? !_documentMedia->owner()->hasThumbnail()
 | 
				
			||||||
		: true;
 | 
							: true;
 | 
				
			||||||
| 
						 | 
					@ -271,7 +290,9 @@ EditCaptionBox::EditCaptionBox(
 | 
				
			||||||
		subscribe(_controller->session().downloaderTaskFinished(), [=] {
 | 
							subscribe(_controller->session().downloaderTaskFinished(), [=] {
 | 
				
			||||||
			if (_thumbnailImageLoaded) {
 | 
								if (_thumbnailImageLoaded) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			} else if (!_thumbnailImage && _photoMedia) {
 | 
								} else if (!_thumbnailImage
 | 
				
			||||||
 | 
									&& _photoMedia
 | 
				
			||||||
 | 
									&& _photoMedia->image(PhotoSize::Large)) {
 | 
				
			||||||
				_thumbnailImage = _photoMedia->image(PhotoSize::Large);
 | 
									_thumbnailImage = _photoMedia->image(PhotoSize::Large);
 | 
				
			||||||
			} else if (!_thumbnailImage
 | 
								} else if (!_thumbnailImage
 | 
				
			||||||
				&& _documentMedia
 | 
									&& _documentMedia
 | 
				
			||||||
| 
						 | 
					@ -279,9 +300,12 @@ EditCaptionBox::EditCaptionBox(
 | 
				
			||||||
				_thumbnailImage = _documentMedia->thumbnail();
 | 
									_thumbnailImage = _documentMedia->thumbnail();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_thumbnailImage && _thumbnailImage->loaded()) {
 | 
								if (_thumbnailImage && _thumbnailImage->loaded()) {
 | 
				
			||||||
				_thumbnailImageLoaded = true;
 | 
									_thumbnailImageLoaded = !_photoMedia
 | 
				
			||||||
				_refreshThumbnail();
 | 
										|| _photoMedia->image(PhotoSize::Large);
 | 
				
			||||||
				update();
 | 
									if (_thumbnailImageLoaded) {
 | 
				
			||||||
 | 
										_refreshThumbnail();
 | 
				
			||||||
 | 
										update();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1125,7 +1125,6 @@ TextState Contact::getState(
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Contact::prepareThumbnail(int width, int height) const {
 | 
					void Contact::prepareThumbnail(int width, int height) const {
 | 
				
			||||||
	// #TODO optimize use photo / document thumbnail as well
 | 
					 | 
				
			||||||
	const auto thumb = getResultThumb();
 | 
						const auto thumb = getResultThumb();
 | 
				
			||||||
	if (!thumb) {
 | 
						if (!thumb) {
 | 
				
			||||||
		if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
 | 
							if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
 | 
				
			||||||
| 
						 | 
					@ -1215,7 +1214,6 @@ void Article::paint(Painter &p, const QRect &clip, const PaintContext *context)
 | 
				
			||||||
		prepareThumbnail(st::inlineThumbSize, st::inlineThumbSize);
 | 
							prepareThumbnail(st::inlineThumbSize, st::inlineThumbSize);
 | 
				
			||||||
		QRect rthumb(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width));
 | 
							QRect rthumb(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width));
 | 
				
			||||||
		if (_thumb.isNull()) {
 | 
							if (_thumb.isNull()) {
 | 
				
			||||||
			// #TODO optimize use photo / document thumbnail as well
 | 
					 | 
				
			||||||
			const auto thumb = getResultThumb();
 | 
								const auto thumb = getResultThumb();
 | 
				
			||||||
			if (!thumb && !_thumbLetter.isEmpty()) {
 | 
								if (!thumb && !_thumbLetter.isEmpty()) {
 | 
				
			||||||
				int32 index = (_thumbLetter.at(0).unicode() % 4);
 | 
									int32 index = (_thumbLetter.at(0).unicode() % 4);
 | 
				
			||||||
| 
						 | 
					@ -1281,7 +1279,6 @@ TextState Article::getState(
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Article::prepareThumbnail(int width, int height) const {
 | 
					void Article::prepareThumbnail(int width, int height) const {
 | 
				
			||||||
	// #TODO optimize use photo / document thumbnail as well
 | 
					 | 
				
			||||||
	const auto thumb = getResultThumb();
 | 
						const auto thumb = getResultThumb();
 | 
				
			||||||
	if (!thumb) {
 | 
						if (!thumb) {
 | 
				
			||||||
		if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
 | 
							if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -853,10 +853,6 @@ void FileLoadTask::process() {
 | 
				
			||||||
			} else if (isAnimation) {
 | 
								} else if (isAnimation) {
 | 
				
			||||||
				attributes.push_back(MTP_documentAttributeAnimated());
 | 
									attributes.push_back(MTP_documentAttributeAnimated());
 | 
				
			||||||
			} else if (_type != SendMediaType::File) {
 | 
								} else if (_type != SendMediaType::File) {
 | 
				
			||||||
				auto thumb = (w > 100 || h > 100) ? fullimage.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
 | 
					 | 
				
			||||||
				photoThumbs.emplace('s', thumb);
 | 
					 | 
				
			||||||
				photoSizes.push_back(MTP_photoSize(MTP_string("s"), MTP_fileLocationToBeDeprecated(MTP_long(0), MTP_int(0)), MTP_int(thumb.width()), MTP_int(thumb.height()), MTP_int(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				auto medium = (w > 320 || h > 320) ? fullimage.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
 | 
									auto medium = (w > 320 || h > 320) ? fullimage.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation) : fullimage;
 | 
				
			||||||
				photoThumbs.emplace('m', medium);
 | 
									photoThumbs.emplace('m', medium);
 | 
				
			||||||
				photoSizes.push_back(MTP_photoSize(MTP_string("m"), MTP_fileLocationToBeDeprecated(MTP_long(0), MTP_int(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0)));
 | 
									photoSizes.push_back(MTP_photoSize(MTP_string("m"), MTP_fileLocationToBeDeprecated(MTP_long(0), MTP_int(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0)));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -378,6 +378,8 @@ struct PlainUrlLocation {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct InMemoryLocation {
 | 
					struct InMemoryLocation {
 | 
				
			||||||
 | 
						~InMemoryLocation() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QByteArray bytes;
 | 
						QByteArray bytes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	friend inline bool operator==(
 | 
						friend inline bool operator==(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue