Example #1
0
QPixmap StickerPreviewWidget::currentImage() const {
	if (_doc) {
		if (_doc->sticker()) {
			if (_cacheStatus != CacheLoaded) {
				_doc->checkSticker();
				if (_doc->sticker()->img->isNull()) {
					if (_cacheStatus != CacheThumbLoaded && _doc->thumb->loaded()) {
						QSize s = currentDimensions();
						_cache = _doc->thumb->pixBlurred(s.width(), s.height());
						_cacheStatus = CacheThumbLoaded;
					}
				} else {
					QSize s = currentDimensions();
					_cache = _doc->sticker()->img->pix(s.width(), s.height());
					_cacheStatus = CacheLoaded;
				}
			}
		} else {
			_doc->automaticLoad(0);
			if (_doc->loaded()) {
				if (!_gif && _gif != BadClipReader) {
					StickerPreviewWidget *that = const_cast<StickerPreviewWidget*>(this);
					that->_gif = new ClipReader(_doc->location(), _doc->data(), func(that, &StickerPreviewWidget::clipCallback));
					if (gif()) _gif->setAutoplay();
				}
			}
			if (gif() && _gif->started()) {
				QSize s = currentDimensions();
				return _gif->current(s.width(), s.height(), s.width(), s.height(), getms());
			}
			if (_cacheStatus != CacheThumbLoaded && _doc->thumb->loaded()) {
				QSize s = currentDimensions();
				_cache = _doc->thumb->pixBlurred(s.width(), s.height());
				_cacheStatus = CacheThumbLoaded;
			}
		}
	}
	return _cache;
}
Example #2
0
QPixmap MediaPreviewWidget::currentImage() const {
	if (_document) {
		if (_document->sticker()) {
			if (_cacheStatus != CacheLoaded) {
				_document->checkSticker();
				if (_document->sticker()->img->isNull()) {
					if (_cacheStatus != CacheThumbLoaded && _document->thumb->loaded()) {
						QSize s = currentDimensions();
						_cache = _document->thumb->pixBlurred(s.width(), s.height());
						_cacheStatus = CacheThumbLoaded;
					}
				} else {
					QSize s = currentDimensions();
					_cache = _document->sticker()->img->pix(s.width(), s.height());
					_cacheStatus = CacheLoaded;
				}
			}
		} else {
			_document->automaticLoad(nullptr);
			if (_document->loaded()) {
				if (!_gif && _gif != BadClipReader) {
					MediaPreviewWidget *that = const_cast<MediaPreviewWidget*>(this);
					that->_gif = new ClipReader(_document->location(), _document->data(), func(that, &MediaPreviewWidget::clipCallback));
					if (gif()) _gif->setAutoplay();
				}
			}
			if (gif() && _gif->started()) {
				QSize s = currentDimensions();
				return _gif->current(s.width(), s.height(), s.width(), s.height(), getms());
			}
			if (_cacheStatus != CacheThumbLoaded && _document->thumb->loaded()) {
				QSize s = currentDimensions();
				_cache = _document->thumb->pixBlurred(s.width(), s.height());
				_cacheStatus = CacheThumbLoaded;
			}
		}
	} else if (_photo) {
		if (_cacheStatus != CacheLoaded) {
			if (_photo->full->loaded()) {
				QSize s = currentDimensions();
				LOG(("DIMENSIONS: %1 %2").arg(s.width()).arg(s.height()));
				_cache = _photo->full->pix(s.width(), s.height());
				_cacheStatus = CacheLoaded;
			} else {
				if (_cacheStatus != CacheThumbLoaded && _photo->thumb->loaded()) {
					QSize s = currentDimensions();
					LOG(("DIMENSIONS: %1 %2").arg(s.width()).arg(s.height()));
					_cache = _photo->thumb->pixBlurred(s.width(), s.height());
					_cacheStatus = CacheThumbLoaded;
				}
				_photo->thumb->load();
				_photo->full->load();
			}
		}

	}
	return _cache;
}
Example #3
0
void StickerPreviewWidget::clipCallback(ClipReaderNotification notification) {
	switch (notification) {
	case ClipReaderReinit: {
		if (gif() && _gif->state() == ClipError) {
			delete _gif;
			_gif = BadClipReader;
		}

		if (gif() && _gif->ready() && !_gif->started()) {
			QSize s = currentDimensions();
			_gif->start(s.width(), s.height(), s.width(), s.height(), false);
		}

		update();
	} break;

	case ClipReaderRepaint: {
		if (gif() && !_gif->currentDisplayed()) {
			update();
		}
	} break;
	}
}