mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added ability to duplicate items in photo editor.
This commit is contained in:
parent
808c9e3d2c
commit
049945a9b9
5 changed files with 47 additions and 4 deletions
|
@ -117,7 +117,6 @@ Paint::Paint(
|
|||
size,
|
||||
x,
|
||||
y);
|
||||
item->setZValue((*_lastZ)++);
|
||||
_scene->addItem(item);
|
||||
_scene->clearSelection();
|
||||
}, lifetime());
|
||||
|
|
|
@ -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*>(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());
|
||||
}
|
||||
|
|
|
@ -70,6 +70,12 @@ protected:
|
|||
void setAspectRatio(float64 aspectRatio);
|
||||
|
||||
virtual void performFlip();
|
||||
virtual std::shared_ptr<ItemBase> duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> 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<float64> _zoom;
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
|
|
@ -101,4 +101,19 @@ void ItemSticker::performFlip() {
|
|||
_pixmap = _pixmap.transformed(QTransform().scale(-1, 1));
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemBase> ItemSticker::duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y) const {
|
||||
return std::make_shared<ItemSticker>(
|
||||
_document,
|
||||
std::move(zoomValue),
|
||||
std::move(zPtr),
|
||||
size,
|
||||
x,
|
||||
y);
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -38,6 +38,12 @@ public:
|
|||
int type() const override;
|
||||
protected:
|
||||
void performFlip() override;
|
||||
std::shared_ptr<ItemBase> duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y) const override;
|
||||
private:
|
||||
const not_null<DocumentData*> _document;
|
||||
const std::shared_ptr<Data::DocumentMedia> _mediaView;
|
||||
|
|
Loading…
Add table
Reference in a new issue