mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Use large image previews more.
This commit is contained in:
parent
2d6008f6ca
commit
2a4d269eca
3 changed files with 47 additions and 0 deletions
|
@ -382,6 +382,11 @@ std::unique_ptr<Ui::Text::CustomEmoji> CustomEmojiManager::create(
|
|||
factory(),
|
||||
prepareNonExactPreview(documentId, tag)
|
||||
}, std::move(repaint))).first;
|
||||
} else if (!i->second->hasImagePreview()) {
|
||||
auto preview = prepareNonExactPreview(documentId, tag);
|
||||
if (preview.isImage()) {
|
||||
i->second->updatePreview(std::move(preview));
|
||||
}
|
||||
}
|
||||
return std::make_unique<Ui::CustomEmoji::Object>(
|
||||
i->second.get(),
|
||||
|
|
|
@ -536,10 +536,26 @@ void Loading::paint(QPainter &p, int x, int y, const QColor &preview) {
|
|||
_preview.paint(p, x, y, preview);
|
||||
}
|
||||
|
||||
bool Loading::hasImagePreview() const {
|
||||
return _preview.isImage();
|
||||
}
|
||||
|
||||
Preview Loading::imagePreview() const {
|
||||
return _preview.isImage() ? _preview : Preview();
|
||||
}
|
||||
|
||||
void Loading::updatePreview(Preview preview) {
|
||||
if (!_preview.isImage() && preview.isImage()) {
|
||||
_preview = std::move(preview);
|
||||
} else if (!_preview) {
|
||||
if (auto loaderPreview = _loader->preview()) {
|
||||
_preview = std::move(loaderPreview);
|
||||
} else if (preview) {
|
||||
_preview = std::move(preview);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Loading::cancel() {
|
||||
_loader->cancel();
|
||||
invalidate_weak_ptrs(this);
|
||||
|
@ -606,6 +622,17 @@ void Instance::paint(
|
|||
}
|
||||
}
|
||||
|
||||
bool Instance::hasImagePreview() const {
|
||||
if (const auto loading = std::get_if<Loading>(&_state)) {
|
||||
return loading->hasImagePreview();
|
||||
} else if (const auto caching = std::get_if<Caching>(&_state)) {
|
||||
return caching->preview.isImage();
|
||||
} else if (const auto cached = std::get_if<Cached>(&_state)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Preview Instance::imagePreview() const {
|
||||
if (const auto loading = std::get_if<Loading>(&_state)) {
|
||||
return loading->imagePreview();
|
||||
|
@ -617,6 +644,17 @@ Preview Instance::imagePreview() const {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Instance::updatePreview(Preview preview) {
|
||||
if (const auto loading = std::get_if<Loading>(&_state)) {
|
||||
loading->updatePreview(std::move(preview));
|
||||
} else if (const auto caching = std::get_if<Caching>(&_state)) {
|
||||
if ((!caching->preview.isImage() && preview.isImage())
|
||||
|| (!caching->preview && preview)) {
|
||||
caching->preview = std::move(preview);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Instance::repaint() {
|
||||
for (const auto &object : _usage) {
|
||||
object->repaint();
|
||||
|
|
|
@ -200,7 +200,9 @@ public:
|
|||
void load(Fn<void(Loader::LoadResult)> done);
|
||||
[[nodiscard]] bool loading() const;
|
||||
void paint(QPainter &p, int x, int y, const QColor &preview);
|
||||
[[nodiscard]] bool hasImagePreview() const;
|
||||
[[nodiscard]] Preview imagePreview() const;
|
||||
void updatePreview(Preview preview);
|
||||
void cancel();
|
||||
|
||||
private:
|
||||
|
@ -231,7 +233,9 @@ public:
|
|||
crl::time now,
|
||||
const QColor &preview,
|
||||
bool paused);
|
||||
[[nodiscard]] bool hasImagePreview() const;
|
||||
[[nodiscard]] Preview imagePreview() const;
|
||||
void updatePreview(Preview preview);
|
||||
|
||||
void incrementUsage(not_null<Object*> object);
|
||||
void decrementUsage(not_null<Object*> object);
|
||||
|
|
Loading…
Add table
Reference in a new issue