From c5c707f0fd8796d6a333194a5f76dae6a889344f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 21 Mar 2021 20:00:56 +0300 Subject: [PATCH] Fixed independence of item and scene transforms when adding. --- Telegram/SourceFiles/editor/editor_paint.cpp | 10 ++++++++-- Telegram/SourceFiles/editor/editor_paint.h | 7 ++++++- .../editor/scene/scene_item_sticker.cpp | 19 +++++++++++++++---- .../editor/scene/scene_item_sticker.h | 2 ++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/editor/editor_paint.cpp b/Telegram/SourceFiles/editor/editor_paint.cpp index a83f19100..0543f624d 100644 --- a/Telegram/SourceFiles/editor/editor_paint.cpp +++ b/Telegram/SourceFiles/editor/editor_paint.cpp @@ -112,11 +112,13 @@ Paint::Paint( const auto y = s.height() / 2; const auto item = std::make_shared( document, - _zoom.value(), + _transform.zoom.value(), _lastZ, size, x, y); + item->setFlip(_transform.flipped); + item->setRotation(-_transform.angle); _scene->addItem(item); _scene->clearSelection(); }, lifetime()); @@ -152,7 +154,11 @@ void Paint::applyTransform(QRect geometry, int angle, bool flipped) { _view->setTransform(QTransform().scale(ratioW, ratioH).rotate(angle)); _view->setGeometry(QRect(QPoint(), size)); - _zoom = size.width() / float64(_scene->sceneRect().width()); + _transform = { + .angle = angle, + .flipped = flipped, + .zoom = size.width() / float64(_scene->sceneRect().width()), + }; } std::shared_ptr Paint::saveScene() const { diff --git a/Telegram/SourceFiles/editor/editor_paint.h b/Telegram/SourceFiles/editor/editor_paint.h index bfcb7a803..721ef7d30 100644 --- a/Telegram/SourceFiles/editor/editor_paint.h +++ b/Telegram/SourceFiles/editor/editor_paint.h @@ -55,13 +55,18 @@ private: const base::unique_qptr _view; const QSize _imageSize; + struct { + int angle = 0; + bool flipped = false; + rpl::variable zoom = 0.; + } _transform; + std::vector _previousItems; std::vector> _itemsToRemove; rpl::variable _hasUndo = true; rpl::variable _hasRedo = true; - rpl::variable _zoom = 0.; }; diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp index 0345c0d1a..34a47bcf9 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp @@ -51,8 +51,8 @@ ItemSticker::ItemSticker( Lottie::Quality::High); _lottie.player->updates( ) | rpl::start_with_next([=] { - _pixmap = App::pixmapFromImageInPlace( - _lottie.player->frame()); + updatePixmap(App::pixmapFromImageInPlace( + _lottie.player->frame())); _lottie.player = nullptr; _lottie.lifetime.destroy(); update(); @@ -63,11 +63,12 @@ ItemSticker::ItemSticker( if (!sticker) { return false; } - _pixmap = sticker->pixNoCache( + auto pixmap = sticker->pixNoCache( sticker->width() * cIntRetinaFactor(), sticker->height() * cIntRetinaFactor(), Images::Option::Smooth); - _pixmap.setDevicePixelRatio(cRetinaFactor()); + pixmap.setDevicePixelRatio(cRetinaFactor()); + updatePixmap(std::move(pixmap)); return true; }; if (!updateThumbnail()) { @@ -81,6 +82,15 @@ ItemSticker::ItemSticker( } } +void ItemSticker::updatePixmap(QPixmap &&pixmap) { + _pixmap = std::move(pixmap); + if (flipped()) { + performFlip(); + } else { + update(); + } +} + void ItemSticker::paint( QPainter *p, const QStyleOptionGraphicsItem *option, @@ -99,6 +109,7 @@ int ItemSticker::type() const { void ItemSticker::performFlip() { _pixmap = _pixmap.transformed(QTransform().scale(-1, 1)); + update(); } std::shared_ptr ItemSticker::duplicate( diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.h b/Telegram/SourceFiles/editor/scene/scene_item_sticker.h index 6254f30cf..ff6cc5a1f 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.h +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.h @@ -48,6 +48,8 @@ private: const not_null _document; const std::shared_ptr _mediaView; + void updatePixmap(QPixmap &&pixmap); + struct { std::unique_ptr player; rpl::lifetime lifetime;