mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Nice price tag on sending media.
This commit is contained in:
parent
6c1e7357c6
commit
d47c5df73d
9 changed files with 132 additions and 21 deletions
|
@ -398,6 +398,18 @@ void SendFilesBox::Block::applyChanges() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage SendFilesBox::Block::generatePriceTagBackground() const {
|
||||||
|
const auto preview = _preview.get();
|
||||||
|
if (_isAlbum) {
|
||||||
|
const auto album = static_cast<Ui::AlbumPreview*>(preview);
|
||||||
|
return album->generatePriceTagBackground();
|
||||||
|
} else if (_isSingleMedia) {
|
||||||
|
const auto media = static_cast<Ui::SingleMediaPreview*>(preview);
|
||||||
|
return media->generatePriceTagBackground();
|
||||||
|
}
|
||||||
|
return QImage();
|
||||||
|
}
|
||||||
|
|
||||||
SendFilesBox::SendFilesBox(
|
SendFilesBox::SendFilesBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
|
@ -737,18 +749,17 @@ void SendFilesBox::refreshPriceTag() {
|
||||||
}
|
}
|
||||||
if (!hasPrice()) {
|
if (!hasPrice()) {
|
||||||
_priceTag = nullptr;
|
_priceTag = nullptr;
|
||||||
|
_priceTagBg = QImage();
|
||||||
} else if (!_priceTag) {
|
} else if (!_priceTag) {
|
||||||
_priceTag = std::make_unique<Ui::RpWidget>(_inner.data());
|
_priceTag = std::make_unique<Ui::RpWidget>(_inner.data());
|
||||||
const auto raw = _priceTag.get();
|
const auto raw = _priceTag.get();
|
||||||
|
|
||||||
raw->show();
|
raw->show();
|
||||||
raw->paintRequest() | rpl::start_with_next([=] {
|
raw->paintRequest() | rpl::start_with_next([=] {
|
||||||
auto p = QPainter(raw);
|
if (_priceTagBg.isNull()) {
|
||||||
auto hq = PainterHighQualityEnabler(p);
|
_priceTagBg = preparePriceTagBg(raw->size());
|
||||||
p.setBrush(st::toastBg);
|
}
|
||||||
p.setPen(Qt::NoPen);
|
QPainter(raw).drawImage(0, 0, _priceTagBg);
|
||||||
const auto radius = std::min(raw->width(), raw->height()) / 2.;
|
|
||||||
p.drawRoundedRect(raw->rect(), radius, radius);
|
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
|
|
||||||
const auto session = &_show->session();
|
const auto session = &_show->session();
|
||||||
|
@ -785,9 +796,44 @@ void SendFilesBox::refreshPriceTag() {
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
} else {
|
} else {
|
||||||
_priceTag->raise();
|
_priceTag->raise();
|
||||||
|
_priceTag->update();
|
||||||
|
_priceTagBg = QImage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage SendFilesBox::preparePriceTagBg(QSize size) const {
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
|
const auto outer = _blocks.empty()
|
||||||
|
? size
|
||||||
|
: _inner->widgetAt(0)->geometry().size();
|
||||||
|
auto bg = _blocks.empty()
|
||||||
|
? QImage()
|
||||||
|
: _blocks.front().generatePriceTagBackground();
|
||||||
|
if (bg.isNull()) {
|
||||||
|
bg = QImage(ratio, ratio, QImage::Format_ARGB32_Premultiplied);
|
||||||
|
bg.fill(Qt::black);
|
||||||
|
}
|
||||||
|
const auto bgSize = bg.size() / bg.devicePixelRatio();
|
||||||
|
|
||||||
|
auto result = QImage(size * ratio, QImage::Format_ARGB32_Premultiplied);
|
||||||
|
result.setDevicePixelRatio(ratio);
|
||||||
|
result.fill(Qt::black);
|
||||||
|
auto p = QPainter(&result);
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
p.drawImage(
|
||||||
|
QRect(
|
||||||
|
(size.width() - outer.width()) / 2,
|
||||||
|
(size.height() - outer.height()) / 2,
|
||||||
|
outer.width(),
|
||||||
|
outer.height()),
|
||||||
|
bg);
|
||||||
|
p.fillRect(QRect(QPoint(), size), st::msgDateImgBg);
|
||||||
|
p.end();
|
||||||
|
|
||||||
|
const auto radius = std::min(size.width(), size.height()) / 2;
|
||||||
|
return Images::Round(std::move(result), Images::CornersMask(radius));
|
||||||
|
}
|
||||||
|
|
||||||
void SendFilesBox::addMenuButton() {
|
void SendFilesBox::addMenuButton() {
|
||||||
const auto details = _sendMenuDetails();
|
const auto details = _sendMenuDetails();
|
||||||
if (!hasSendMenu(details)) {
|
if (!hasSendMenu(details)) {
|
||||||
|
|
|
@ -166,6 +166,8 @@ private:
|
||||||
void toggleSpoilers(bool enabled);
|
void toggleSpoilers(bool enabled);
|
||||||
void applyChanges();
|
void applyChanges();
|
||||||
|
|
||||||
|
[[nodiscard]] QImage generatePriceTagBackground() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
base::unique_qptr<Ui::RpWidget> _preview;
|
base::unique_qptr<Ui::RpWidget> _preview;
|
||||||
not_null<std::vector<Ui::PreparedFile>*> _items;
|
not_null<std::vector<Ui::PreparedFile>*> _items;
|
||||||
|
@ -196,6 +198,7 @@ private:
|
||||||
[[nodiscard]] bool canChangePrice() const;
|
[[nodiscard]] bool canChangePrice() const;
|
||||||
[[nodiscard]] bool hasPrice() const;
|
[[nodiscard]] bool hasPrice() const;
|
||||||
void refreshPriceTag();
|
void refreshPriceTag();
|
||||||
|
[[nodiscard]] QImage preparePriceTagBg(QSize size) const;
|
||||||
|
|
||||||
bool validateLength(const QString &text) const;
|
bool validateLength(const QString &text) const;
|
||||||
void refreshButtons();
|
void refreshButtons();
|
||||||
|
@ -259,6 +262,7 @@ private:
|
||||||
Fn<void()> _cancelledCallback;
|
Fn<void()> _cancelledCallback;
|
||||||
rpl::variable<uint64> _price = 0;
|
rpl::variable<uint64> _price = 0;
|
||||||
std::unique_ptr<Ui::RpWidget> _priceTag;
|
std::unique_ptr<Ui::RpWidget> _priceTag;
|
||||||
|
QImage _priceTagBg;
|
||||||
bool _confirmed = false;
|
bool _confirmed = false;
|
||||||
bool _invertCaption = false;
|
bool _invertCaption = false;
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ void Photo::draw(Painter &p, const PaintContext &context) const {
|
||||||
}
|
}
|
||||||
} else if (preview) {
|
} else if (preview) {
|
||||||
drawPriceTag(p, rthumb, context, [&] {
|
drawPriceTag(p, rthumb, context, [&] {
|
||||||
return _spoiler ? _spoiler->background : QImage();
|
return priceTagBackground();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (showEnlarge) {
|
if (showEnlarge) {
|
||||||
|
@ -447,9 +447,10 @@ void Photo::drawPriceTag(
|
||||||
|| _priceTag->darken != darken
|
|| _priceTag->darken != darken
|
||||||
|| _priceTag->fg != fg
|
|| _priceTag->fg != fg
|
||||||
|| _priceTag->star != star) {
|
|| _priceTag->star != star) {
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
auto bg = generateBackground();
|
auto bg = generateBackground();
|
||||||
if (bg.isNull()) {
|
if (bg.isNull()) {
|
||||||
bg = QImage(2, 2, QImage::Format_ARGB32_Premultiplied);
|
bg = QImage(ratio, ratio, QImage::Format_ARGB32_Premultiplied);
|
||||||
bg.fill(Qt::black);
|
bg.fill(Qt::black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +475,6 @@ void Photo::drawPriceTag(
|
||||||
const auto outer = inner.marginsAdded(st::paidTagPadding);
|
const auto outer = inner.marginsAdded(st::paidTagPadding);
|
||||||
const auto size = outer.size();
|
const auto size = outer.size();
|
||||||
const auto radius = std::min(size.width(), size.height()) / 2;
|
const auto radius = std::min(size.width(), size.height()) / 2;
|
||||||
const auto ratio = style::DevicePixelRatio();
|
|
||||||
auto cache = QImage(
|
auto cache = QImage(
|
||||||
size * ratio,
|
size * ratio,
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
|
|
@ -84,6 +84,10 @@ rpl::producer<bool> AbstractSingleMediaPreview::spoileredChanges() const {
|
||||||
return _spoileredChanges.events();
|
return _spoileredChanges.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage AbstractSingleMediaPreview::generatePriceTagBackground() const {
|
||||||
|
return (_previewBlurred.isNull() ? _preview : _previewBlurred).toImage();
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractSingleMediaPreview::preparePreview(QImage preview) {
|
void AbstractSingleMediaPreview::preparePreview(QImage preview) {
|
||||||
auto maxW = 0;
|
auto maxW = 0;
|
||||||
auto maxH = 0;
|
auto maxH = 0;
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
[[nodiscard]] bool canHaveSpoiler() const;
|
[[nodiscard]] bool canHaveSpoiler() const;
|
||||||
[[nodiscard]] rpl::producer<bool> spoileredChanges() const;
|
[[nodiscard]] rpl::producer<bool> spoileredChanges() const;
|
||||||
|
|
||||||
|
[[nodiscard]] QImage generatePriceTagBackground() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool supportsSpoilers() const = 0;
|
virtual bool supportsSpoilers() const = 0;
|
||||||
virtual bool drawBackground() const = 0;
|
virtual bool drawBackground() const = 0;
|
||||||
|
|
|
@ -20,6 +20,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
|
namespace Media::Streaming {
|
||||||
|
|
||||||
|
[[nodiscard]] QImage PrepareBlurredBackground(QSize outer, QImage frame);
|
||||||
|
|
||||||
|
} // namespace Media::Streaming
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -610,8 +616,47 @@ void AlbumPreview::switchToDrag() {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<int> AlbumPreview::thumbModified() const {
|
QImage AlbumPreview::generatePriceTagBackground() const {
|
||||||
return _thumbModified.events();
|
auto wmax = 0;
|
||||||
|
auto hmax = 0;
|
||||||
|
for (auto &thumb : _thumbs) {
|
||||||
|
const auto geometry = thumb->geometry();
|
||||||
|
accumulate_max(wmax, geometry.x() + geometry.width());
|
||||||
|
accumulate_max(hmax, geometry.y() + geometry.height());
|
||||||
|
}
|
||||||
|
const auto size = QSize(wmax, hmax);
|
||||||
|
if (size.isEmpty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
|
const auto full = size * ratio;
|
||||||
|
const auto skip = st::historyGroupSkip;
|
||||||
|
auto result = QImage(full, QImage::Format_ARGB32_Premultiplied);
|
||||||
|
result.setDevicePixelRatio(ratio);
|
||||||
|
result.fill(Qt::black);
|
||||||
|
auto p = QPainter(&result);
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
for (auto &thumb : _thumbs) {
|
||||||
|
const auto geometry = thumb->geometry();
|
||||||
|
if (geometry.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto w = geometry.width();
|
||||||
|
const auto h = geometry.height();
|
||||||
|
const auto wscale = (w + skip) / float64(w);
|
||||||
|
const auto hscale = (h + skip) / float64(h);
|
||||||
|
p.save();
|
||||||
|
p.translate(geometry.center());
|
||||||
|
p.scale(wscale, hscale);
|
||||||
|
p.translate(-geometry.center());
|
||||||
|
thumb->paintInAlbum(p, 0, 0, 0., 0.);
|
||||||
|
p.restore();
|
||||||
|
}
|
||||||
|
p.end();
|
||||||
|
|
||||||
|
return ::Media::Streaming::PrepareBlurredBackground(
|
||||||
|
full,
|
||||||
|
std::move(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
@ -47,7 +47,11 @@ public:
|
||||||
return _thumbChanged.events();
|
return _thumbChanged.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<int> thumbModified() const;
|
[[nodiscard]] rpl::producer<int> thumbModified() const {
|
||||||
|
return _thumbModified.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QImage generatePriceTagBackground() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
|
@ -503,6 +503,10 @@ void AlbumThumbnail::paintFile(
|
||||||
_fileThumb.size() / style::DevicePixelRatio());
|
_fileThumb.size() / style::DevicePixelRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect AlbumThumbnail::geometry() const {
|
||||||
|
return _layout.geometry;
|
||||||
|
}
|
||||||
|
|
||||||
bool AlbumThumbnail::containsPoint(QPoint position) const {
|
bool AlbumThumbnail::containsPoint(QPoint position) const {
|
||||||
return _layout.geometry.contains(position);
|
return _layout.geometry.contains(position);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ public:
|
||||||
void setSpoiler(bool spoiler);
|
void setSpoiler(bool spoiler);
|
||||||
[[nodiscard]] bool hasSpoiler() const;
|
[[nodiscard]] bool hasSpoiler() const;
|
||||||
|
|
||||||
int photoHeight() const;
|
[[nodiscard]] int photoHeight() const;
|
||||||
int fileHeight() const;
|
[[nodiscard]] int fileHeight() const;
|
||||||
|
|
||||||
void paintInAlbum(
|
void paintInAlbum(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
|
@ -54,20 +54,22 @@ public:
|
||||||
void paintPhoto(Painter &p, int left, int top, int outerWidth);
|
void paintPhoto(Painter &p, int left, int top, int outerWidth);
|
||||||
void paintFile(Painter &p, int left, int top, int outerWidth);
|
void paintFile(Painter &p, int left, int top, int outerWidth);
|
||||||
|
|
||||||
bool containsPoint(QPoint position) const;
|
[[nodiscard]] QRect geometry() const;
|
||||||
bool buttonsContainPoint(QPoint position) const;
|
[[nodiscard]] bool containsPoint(QPoint position) const;
|
||||||
AttachButtonType buttonTypeFromPoint(QPoint position) const;
|
[[nodiscard]] bool buttonsContainPoint(QPoint position) const;
|
||||||
int distanceTo(QPoint position) const;
|
[[nodiscard]] AttachButtonType buttonTypeFromPoint(
|
||||||
bool isPointAfter(QPoint position) const;
|
QPoint position) const;
|
||||||
|
[[nodiscard]] int distanceTo(QPoint position) const;
|
||||||
|
[[nodiscard]] bool isPointAfter(QPoint position) const;
|
||||||
void moveInAlbum(QPoint to);
|
void moveInAlbum(QPoint to);
|
||||||
QPoint center() const;
|
[[nodiscard]] QPoint center() const;
|
||||||
void suggestMove(float64 delta, Fn<void()> callback);
|
void suggestMove(float64 delta, Fn<void()> callback);
|
||||||
void finishAnimations();
|
void finishAnimations();
|
||||||
|
|
||||||
void setButtonVisible(bool value);
|
void setButtonVisible(bool value);
|
||||||
void moveButtons(int thumbTop);
|
void moveButtons(int thumbTop);
|
||||||
|
|
||||||
bool isCompressedSticker() const;
|
[[nodiscard]] bool isCompressedSticker() const;
|
||||||
|
|
||||||
static constexpr auto kShrinkDuration = crl::time(150);
|
static constexpr auto kShrinkDuration = crl::time(150);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue