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,
 | 
									size,
 | 
				
			||||||
				x,
 | 
									x,
 | 
				
			||||||
				y);
 | 
									y);
 | 
				
			||||||
			item->setZValue((*_lastZ)++);
 | 
					 | 
				
			||||||
			_scene->addItem(item);
 | 
								_scene->addItem(item);
 | 
				
			||||||
			_scene->clearSelection();
 | 
								_scene->clearSelection();
 | 
				
			||||||
		}, lifetime());
 | 
							}, lifetime());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,16 +56,17 @@ ItemBase::ItemBase(
 | 
				
			||||||
	Qt::DashLine,
 | 
						Qt::DashLine,
 | 
				
			||||||
	Qt::SquareCap,
 | 
						Qt::SquareCap,
 | 
				
			||||||
	Qt::RoundJoin)
 | 
						Qt::RoundJoin)
 | 
				
			||||||
, _horizontalSize(size) {
 | 
					, _horizontalSize(size)
 | 
				
			||||||
 | 
					, _zoom(std::move(zoomValue)) {
 | 
				
			||||||
	setFlags(QGraphicsItem::ItemIsMovable
 | 
						setFlags(QGraphicsItem::ItemIsMovable
 | 
				
			||||||
		| QGraphicsItem::ItemIsSelectable
 | 
							| QGraphicsItem::ItemIsSelectable
 | 
				
			||||||
		| QGraphicsItem::ItemIsFocusable);
 | 
							| QGraphicsItem::ItemIsFocusable);
 | 
				
			||||||
	setAcceptHoverEvents(true);
 | 
						setAcceptHoverEvents(true);
 | 
				
			||||||
	setPos(x, y);
 | 
						setPos(x, y);
 | 
				
			||||||
 | 
						setZValue((*_lastZ)++);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto &handleSize = st::photoEditorItemHandleSize;
 | 
						const auto &handleSize = st::photoEditorItemHandleSize;
 | 
				
			||||||
	std::move(
 | 
						_zoom.value(
 | 
				
			||||||
		zoomValue
 | 
					 | 
				
			||||||
	) | rpl::start_with_next([=](float64 zoom) {
 | 
						) | rpl::start_with_next([=](float64 zoom) {
 | 
				
			||||||
		_scaledHandleSize = handleSize / zoom;
 | 
							_scaledHandleSize = handleSize / zoom;
 | 
				
			||||||
		_scaledInnerMargins = QMarginsF(
 | 
							_scaledInnerMargins = QMarginsF(
 | 
				
			||||||
| 
						 | 
					@ -187,6 +188,21 @@ void ItemBase::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
 | 
				
			||||||
	_menu->addAction(tr::lng_photo_editor_menu_flip(tr::now), [=] {
 | 
						_menu->addAction(tr::lng_photo_editor_menu_flip(tr::now), [=] {
 | 
				
			||||||
		setFlip(!flipped());
 | 
							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());
 | 
						_menu->popup(event->screenPos());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,6 +70,12 @@ protected:
 | 
				
			||||||
	void setAspectRatio(float64 aspectRatio);
 | 
						void setAspectRatio(float64 aspectRatio);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	virtual void performFlip();
 | 
						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:
 | 
					private:
 | 
				
			||||||
	HandleType handleType(const QPointF &pos) const;
 | 
						HandleType handleType(const QPointF &pos) const;
 | 
				
			||||||
	QRectF rightHandleRect() const;
 | 
						QRectF rightHandleRect() const;
 | 
				
			||||||
| 
						 | 
					@ -94,6 +100,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool _flipped = false;
 | 
						bool _flipped = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rpl::variable<float64> _zoom;
 | 
				
			||||||
	rpl::lifetime _lifetime;
 | 
						rpl::lifetime _lifetime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,4 +101,19 @@ void ItemSticker::performFlip() {
 | 
				
			||||||
	_pixmap = _pixmap.transformed(QTransform().scale(-1, 1));
 | 
						_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
 | 
					} // namespace Editor
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,12 @@ public:
 | 
				
			||||||
	int type() const override;
 | 
						int type() const override;
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
	void performFlip() override;
 | 
						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:
 | 
					private:
 | 
				
			||||||
	const not_null<DocumentData*> _document;
 | 
						const not_null<DocumentData*> _document;
 | 
				
			||||||
	const std::shared_ptr<Data::DocumentMedia> _mediaView;
 | 
						const std::shared_ptr<Data::DocumentMedia> _mediaView;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue