mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Implement correct rounding of shared locations.
This commit is contained in:
parent
5e82433693
commit
b2302d35fe
3 changed files with 41 additions and 14 deletions
|
@ -195,14 +195,10 @@ void Location::draw(Painter &p, const PaintContext &context) const {
|
|||
}
|
||||
|
||||
ensureMediaCreated();
|
||||
//if (const auto thumbnail = _media->image()) {
|
||||
// p.drawPixmap(rthumb.topLeft(), thumbnail->pixSingle(
|
||||
// rthumb.size(),
|
||||
// {
|
||||
// .options = Images::RoundOptions(roundRadius, roundCorners),
|
||||
// .outer = rthumb.size(),
|
||||
// }));
|
||||
//} else if (!bubble) {
|
||||
validateImageCache(rthumb.size(), rounding);
|
||||
if (!_imageCache.isNull()) {
|
||||
p.drawImage(rthumb.topLeft(), _imageCache);
|
||||
} else if (!bubble) {
|
||||
Ui::PaintBubble(
|
||||
p,
|
||||
Ui::SimpleBubble{
|
||||
|
@ -215,7 +211,7 @@ void Location::draw(Painter &p, const PaintContext &context) const {
|
|||
.outbg = context.outbg,
|
||||
.rounding = rounding,
|
||||
});
|
||||
//}
|
||||
}
|
||||
const auto paintMarker = [&](const style::icon &icon) {
|
||||
icon.paint(
|
||||
p,
|
||||
|
@ -247,6 +243,28 @@ void Location::draw(Painter &p, const PaintContext &context) const {
|
|||
}
|
||||
}
|
||||
|
||||
void Location::validateImageCache(
|
||||
QSize outer,
|
||||
Ui::BubbleRounding rounding) const {
|
||||
const auto ratio = style::DevicePixelRatio();
|
||||
if (_imageCache.size() == (outer * ratio)
|
||||
&& _imageCacheRounding == rounding) {
|
||||
return;
|
||||
}
|
||||
const auto thumbnail = _media->image();
|
||||
if (!thumbnail) {
|
||||
return;
|
||||
}
|
||||
_imageCache = Images::Round(
|
||||
thumbnail->original().scaled(
|
||||
outer * ratio,
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::SmoothTransformation),
|
||||
MediaRoundingMask(rounding));
|
||||
_imageCache.setDevicePixelRatio(ratio);
|
||||
_imageCacheRounding = rounding;
|
||||
}
|
||||
|
||||
TextState Location::textState(QPoint point, StateRequest request) const {
|
||||
auto result = TextState(_parent);
|
||||
auto symbolAdd = 0;
|
||||
|
|
|
@ -65,19 +65,28 @@ public:
|
|||
private:
|
||||
void ensureMediaCreated() const;
|
||||
|
||||
void validateImageCache(
|
||||
QSize outer,
|
||||
Ui::BubbleRounding rounding) const;
|
||||
|
||||
QSize countOptimalSize() override;
|
||||
QSize countCurrentSize(int newWidth) override;
|
||||
|
||||
TextSelection toDescriptionSelection(TextSelection selection) const;
|
||||
TextSelection fromDescriptionSelection(TextSelection selection) const;
|
||||
[[nodiscard]] TextSelection toDescriptionSelection(
|
||||
TextSelection selection) const;
|
||||
[[nodiscard]] TextSelection fromDescriptionSelection(
|
||||
TextSelection selection) const;
|
||||
|
||||
[[nodiscard]] int fullWidth() const;
|
||||
[[nodiscard]] int fullHeight() const;
|
||||
|
||||
const not_null<Data::CloudImage*> _data;
|
||||
mutable std::shared_ptr<Data::CloudImageView> _media;
|
||||
Ui::Text::String _title, _description;
|
||||
ClickHandlerPtr _link;
|
||||
|
||||
int fullWidth() const;
|
||||
int fullHeight() const;
|
||||
mutable QImage _imageCache;
|
||||
mutable Ui::BubbleRounding _imageCacheRounding;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -149,8 +149,8 @@ private:
|
|||
mutable std::shared_ptr<Data::PhotoMedia> _dataMedia;
|
||||
mutable std::unique_ptr<Streamed> _streamed;
|
||||
mutable QImage _imageCache;
|
||||
int _serviceWidth = 0;
|
||||
mutable std::optional<Ui::BubbleRounding> _imageCacheRounding;
|
||||
int _serviceWidth = 0;
|
||||
mutable bool _imageCacheBlurred = false;
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue