From f718410df34a7a3ad1087abd9aaa45589d10119a Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 3 Apr 2019 14:16:45 +0400 Subject: [PATCH] Improve sticker sending by drag-n-drop preview. --- Telegram/SourceFiles/boxes/send_files_box.cpp | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index e517fe24e..d40ea4efb 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -40,6 +40,7 @@ namespace { constexpr auto kMinPreviewWidth = 20; constexpr auto kShrinkDuration = crl::time(150); constexpr auto kDragDuration = crl::time(200); +const auto kStickerMimeString = qstr("image/webp"); class SingleMediaPreview : public Ui::RpWidget { public: @@ -53,6 +54,7 @@ public: not_null controller, QImage preview, bool animated, + bool sticker, const QString &animatedPreviewPath); bool canSendAsPhoto() const { @@ -73,6 +75,7 @@ private: not_null _controller; bool _animated = false; + bool _sticker = false; bool _canSendAsPhoto = false; QPixmap _preview; int _previewLeft = 0; @@ -587,11 +590,13 @@ SingleMediaPreview *SingleMediaPreview::Create( preview.height())) { return nullptr; } + const auto sticker = (file.information->filemime == kStickerMimeString); return Ui::CreateChild( parent, controller, preview, animated, + sticker, animationPreview ? file.path : QString()); } @@ -600,15 +605,19 @@ SingleMediaPreview::SingleMediaPreview( not_null controller, QImage preview, bool animated, + bool sticker, const QString &animatedPreviewPath) : RpWidget(parent) , _controller(controller) -, _animated(animated) { +, _animated(animated) +, _sticker(sticker) { Expects(!preview.isNull()); - _canSendAsPhoto = !_animated && Storage::ValidateThumbDimensions( - preview.width(), - preview.height()); + _canSendAsPhoto = !_animated + && !_sticker + && Storage::ValidateThumbDimensions( + preview.width(), + preview.height()); preparePreview(preview, animatedPreviewPath); } @@ -712,11 +721,13 @@ void SingleMediaPreview::clipCallback(Media::Clip::Notification notification) { void SingleMediaPreview::paintEvent(QPaintEvent *e) { Painter p(this); - if (_previewLeft > st::boxPhotoPadding.left()) { - p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _previewLeft - st::boxPhotoPadding.left(), _previewHeight, st::confirmBg); - } - if (_previewLeft + _previewWidth < width() - st::boxPhotoPadding.right()) { - p.fillRect(_previewLeft + _previewWidth, st::boxPhotoPadding.top(), width() - st::boxPhotoPadding.right() - _previewLeft - _previewWidth, _previewHeight, st::confirmBg); + if (!_sticker) { + if (_previewLeft > st::boxPhotoPadding.left()) { + p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _previewLeft - st::boxPhotoPadding.left(), _previewHeight, st::confirmBg); + } + if (_previewLeft + _previewWidth < width() - st::boxPhotoPadding.right()) { + p.fillRect(_previewLeft + _previewWidth, st::boxPhotoPadding.top(), width() - st::boxPhotoPadding.right() - _previewLeft - _previewWidth, _previewHeight, st::confirmBg); + } } if (_gifPreview && _gifPreview->started()) { auto s = QSize(_previewWidth, _previewHeight);