mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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();
|
ensureMediaCreated();
|
||||||
//if (const auto thumbnail = _media->image()) {
|
validateImageCache(rthumb.size(), rounding);
|
||||||
// p.drawPixmap(rthumb.topLeft(), thumbnail->pixSingle(
|
if (!_imageCache.isNull()) {
|
||||||
// rthumb.size(),
|
p.drawImage(rthumb.topLeft(), _imageCache);
|
||||||
// {
|
} else if (!bubble) {
|
||||||
// .options = Images::RoundOptions(roundRadius, roundCorners),
|
|
||||||
// .outer = rthumb.size(),
|
|
||||||
// }));
|
|
||||||
//} else if (!bubble) {
|
|
||||||
Ui::PaintBubble(
|
Ui::PaintBubble(
|
||||||
p,
|
p,
|
||||||
Ui::SimpleBubble{
|
Ui::SimpleBubble{
|
||||||
|
@ -215,7 +211,7 @@ void Location::draw(Painter &p, const PaintContext &context) const {
|
||||||
.outbg = context.outbg,
|
.outbg = context.outbg,
|
||||||
.rounding = rounding,
|
.rounding = rounding,
|
||||||
});
|
});
|
||||||
//}
|
}
|
||||||
const auto paintMarker = [&](const style::icon &icon) {
|
const auto paintMarker = [&](const style::icon &icon) {
|
||||||
icon.paint(
|
icon.paint(
|
||||||
p,
|
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 {
|
TextState Location::textState(QPoint point, StateRequest request) const {
|
||||||
auto result = TextState(_parent);
|
auto result = TextState(_parent);
|
||||||
auto symbolAdd = 0;
|
auto symbolAdd = 0;
|
||||||
|
|
|
@ -65,19 +65,28 @@ public:
|
||||||
private:
|
private:
|
||||||
void ensureMediaCreated() const;
|
void ensureMediaCreated() const;
|
||||||
|
|
||||||
|
void validateImageCache(
|
||||||
|
QSize outer,
|
||||||
|
Ui::BubbleRounding rounding) const;
|
||||||
|
|
||||||
QSize countOptimalSize() override;
|
QSize countOptimalSize() override;
|
||||||
QSize countCurrentSize(int newWidth) override;
|
QSize countCurrentSize(int newWidth) override;
|
||||||
|
|
||||||
TextSelection toDescriptionSelection(TextSelection selection) const;
|
[[nodiscard]] TextSelection toDescriptionSelection(
|
||||||
TextSelection fromDescriptionSelection(TextSelection selection) const;
|
TextSelection selection) const;
|
||||||
|
[[nodiscard]] TextSelection fromDescriptionSelection(
|
||||||
|
TextSelection selection) const;
|
||||||
|
|
||||||
|
[[nodiscard]] int fullWidth() const;
|
||||||
|
[[nodiscard]] int fullHeight() const;
|
||||||
|
|
||||||
const not_null<Data::CloudImage*> _data;
|
const not_null<Data::CloudImage*> _data;
|
||||||
mutable std::shared_ptr<Data::CloudImageView> _media;
|
mutable std::shared_ptr<Data::CloudImageView> _media;
|
||||||
Ui::Text::String _title, _description;
|
Ui::Text::String _title, _description;
|
||||||
ClickHandlerPtr _link;
|
ClickHandlerPtr _link;
|
||||||
|
|
||||||
int fullWidth() const;
|
mutable QImage _imageCache;
|
||||||
int fullHeight() const;
|
mutable Ui::BubbleRounding _imageCacheRounding;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -149,8 +149,8 @@ private:
|
||||||
mutable std::shared_ptr<Data::PhotoMedia> _dataMedia;
|
mutable std::shared_ptr<Data::PhotoMedia> _dataMedia;
|
||||||
mutable std::unique_ptr<Streamed> _streamed;
|
mutable std::unique_ptr<Streamed> _streamed;
|
||||||
mutable QImage _imageCache;
|
mutable QImage _imageCache;
|
||||||
int _serviceWidth = 0;
|
|
||||||
mutable std::optional<Ui::BubbleRounding> _imageCacheRounding;
|
mutable std::optional<Ui::BubbleRounding> _imageCacheRounding;
|
||||||
|
int _serviceWidth = 0;
|
||||||
mutable bool _imageCacheBlurred = false;
|
mutable bool _imageCacheBlurred = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue