diff --git a/Telegram/SourceFiles/editor/editor_paint.cpp b/Telegram/SourceFiles/editor/editor_paint.cpp index ed6aa2183..a06f97388 100644 --- a/Telegram/SourceFiles/editor/editor_paint.cpp +++ b/Telegram/SourceFiles/editor/editor_paint.cpp @@ -117,7 +117,6 @@ Paint::Paint( size, x, y); - item->setZValue((*_lastZ)++); _scene->addItem(item); _scene->clearSelection(); }, lifetime()); diff --git a/Telegram/SourceFiles/editor/scene_item_base.cpp b/Telegram/SourceFiles/editor/scene_item_base.cpp index 8b781d848..cb076d7c0 100644 --- a/Telegram/SourceFiles/editor/scene_item_base.cpp +++ b/Telegram/SourceFiles/editor/scene_item_base.cpp @@ -56,16 +56,17 @@ ItemBase::ItemBase( Qt::DashLine, Qt::SquareCap, Qt::RoundJoin) -, _horizontalSize(size) { +, _horizontalSize(size) +, _zoom(std::move(zoomValue)) { setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable); setAcceptHoverEvents(true); setPos(x, y); + setZValue((*_lastZ)++); const auto &handleSize = st::photoEditorItemHandleSize; - std::move( - zoomValue + _zoom.value( ) | rpl::start_with_next([=](float64 zoom) { _scaledHandleSize = handleSize / zoom; _scaledInnerMargins = QMarginsF( @@ -187,6 +188,21 @@ void ItemBase::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { _menu->addAction(tr::lng_photo_editor_menu_flip(tr::now), [=] { setFlip(!flipped()); }); + _menu->addAction(tr::lng_photo_editor_menu_duplicate(tr::now), [=] { + if (const auto s = static_cast(scene())) { + const auto newItem = duplicate( + _zoom.value(), + _lastZ, + _horizontalSize, + scenePos().x() + _horizontalSize / 3, + scenePos().y() + _verticalSize / 3); + newItem->setFlip(flipped()); + newItem->setRotation(rotation()); + s->clearSelection(); + newItem->setSelected(true); + s->addItem(newItem); + } + }); _menu->popup(event->screenPos()); } diff --git a/Telegram/SourceFiles/editor/scene_item_base.h b/Telegram/SourceFiles/editor/scene_item_base.h index a9e20b81b..3530b96e3 100644 --- a/Telegram/SourceFiles/editor/scene_item_base.h +++ b/Telegram/SourceFiles/editor/scene_item_base.h @@ -70,6 +70,12 @@ protected: void setAspectRatio(float64 aspectRatio); virtual void performFlip(); + virtual std::shared_ptr duplicate( + rpl::producer zoomValue, + std::shared_ptr zPtr, + int size, + int x, + int y) const = 0; private: HandleType handleType(const QPointF &pos) const; QRectF rightHandleRect() const; @@ -94,6 +100,7 @@ private: bool _flipped = false; + rpl::variable _zoom; rpl::lifetime _lifetime; }; diff --git a/Telegram/SourceFiles/editor/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene_item_sticker.cpp index 1a517fe91..9c29f7cd2 100644 --- a/Telegram/SourceFiles/editor/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene_item_sticker.cpp @@ -101,4 +101,19 @@ void ItemSticker::performFlip() { _pixmap = _pixmap.transformed(QTransform().scale(-1, 1)); } +std::shared_ptr ItemSticker::duplicate( + rpl::producer zoomValue, + std::shared_ptr zPtr, + int size, + int x, + int y) const { + return std::make_shared( + _document, + std::move(zoomValue), + std::move(zPtr), + size, + x, + y); +} + } // namespace Editor diff --git a/Telegram/SourceFiles/editor/scene_item_sticker.h b/Telegram/SourceFiles/editor/scene_item_sticker.h index edf819e4c..f78186974 100644 --- a/Telegram/SourceFiles/editor/scene_item_sticker.h +++ b/Telegram/SourceFiles/editor/scene_item_sticker.h @@ -38,6 +38,12 @@ public: int type() const override; protected: void performFlip() override; + std::shared_ptr duplicate( + rpl::producer zoomValue, + std::shared_ptr zPtr, + int size, + int x, + int y) const override; private: const not_null _document; const std::shared_ptr _mediaView;