2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Use Data::DocumentMedia to store good thumbnails.

This commit is contained in:
John Preston
2020-03-27 15:40:50 +04:00
parent 61647275e8
commit 7db53599e8
29 changed files with 545 additions and 168 deletions

View File

@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_media_types.h"
#include "data/data_peer.h"
#include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "styles/style_overview.h"
#include "styles/style_history.h"
#include "core/file_utilities.h"
@@ -417,13 +418,10 @@ Video::Video(
, _duration(formatDurationText(_data->getDuration())) {
setDocumentLinks(_data);
_data->loadThumbnail(parent->fullId());
if (_data->hasThumbnail() && !_data->thumbnail()->loaded()) {
if (const auto good = _data->goodThumbnail()) {
good->load({});
}
}
}
Video::~Video() = default;
void Video::initDimensions() {
_maxw = 2 * st::overviewPhotoMinSize;
_minh = _maxw;
@@ -436,12 +434,14 @@ int32 Video::resizeGetHeight(int32 width) {
}
void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
ensureDataMediaCreated();
const auto selected = (selection == FullSelection);
const auto blurred = _data->thumbnailInline();
const auto goodLoaded = _data->goodThumbnail()
&& _data->goodThumbnail()->loaded();
const auto thumbLoaded = _data->hasThumbnail()
&& _data->thumbnail()->loaded();
const auto goodLoaded = _dataMedia->goodThumbnail()
&& _dataMedia->goodThumbnail()->loaded();
bool loaded = _data->loaded(), displayLoading = _data->displayLoading();
if (displayLoading) {
@@ -459,7 +459,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const
|| (_pixBlurred && (thumbLoaded || goodLoaded)))) {
auto size = _width * cIntRetinaFactor();
auto img = goodLoaded
? _data->goodThumbnail()->original()
? _dataMedia->goodThumbnail()->original()
: thumbLoaded
? _data->thumbnail()->original()
: Images::prepareBlur(blurred->original());
@@ -543,6 +543,14 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const
paintCheckbox(p, { checkLeft, checkTop }, selected, context);
}
void Video::ensureDataMediaCreated() const {
if (_dataMedia) {
return;
}
_dataMedia = _data->createMediaView();
_dataMedia->goodThumbnailWanted();
}
float64 Video::dataProgress() const {
return _data->progress();
}

View File

@@ -19,6 +19,7 @@ struct RoundCheckbox;
namespace Data {
class Media;
class DocumentMedia;
} // namespace Data
namespace Overview {
@@ -220,11 +221,12 @@ private:
};
class Video : public RadialProgressItem {
class Video final : public RadialProgressItem {
public:
Video(
not_null<HistoryItem*> parent,
not_null<DocumentData*> video);
~Video();
void initDimensions() override;
int32 resizeGetHeight(int32 width) override;
@@ -240,15 +242,17 @@ protected:
bool iconAnimated() const override;
private:
void ensureDataMediaCreated() const;
void updateStatusText();
not_null<DocumentData*> _data;
mutable std::shared_ptr<Data::DocumentMedia> _dataMedia;
StatusText _status;
QString _duration;
QPixmap _pix;
bool _pixBlurred = true;
void updateStatusText();
};
class Voice : public RadialProgressItem {