Fixed items order when opening photo editor with modified scene.

This commit is contained in:
23rd 2021-07-07 01:31:43 +03:00
parent 8ddbf08a97
commit 5bbf3a329d
4 changed files with 10 additions and 4 deletions

View file

@ -52,7 +52,6 @@ Paint::Paint(
std::shared_ptr<Controllers> controllers)
: RpWidget(parent)
, _controllers(controllers)
, _lastZ(std::make_shared<float64>(9000.))
, _scene(EnsureScene(modifications, imageSize))
, _view(base::make_unique_q<QGraphicsView>(_scene.get(), this))
, _imageSize(imageSize) {
@ -293,7 +292,7 @@ ItemBase::Data Paint::itemBaseData() const {
const auto y = s.height() / 2;
return ItemBase::Data{
.zoomValue = _transform.zoom.value(),
.zPtr = _lastZ,
.zPtr = _scene->lastZ(),
.size = size,
.x = x,
.y = y,

View file

@ -55,7 +55,6 @@ private:
bool isItemHidden(const std::shared_ptr<QGraphicsItem> &item) const;
const std::shared_ptr<Controllers> _controllers;
const std::shared_ptr<float64> _lastZ;
const std::shared_ptr<Scene> _scene;
const base::unique_qptr<QGraphicsView> _view;
const QSize _imageSize;

View file

@ -27,7 +27,8 @@ bool SkipMouseEvent(not_null<QGraphicsSceneMouseEvent*> event) {
Scene::Scene(const QRectF &rect)
: QGraphicsScene(rect)
, _canvas(std::make_shared<ItemCanvas>()) {
, _canvas(std::make_shared<ItemCanvas>())
, _lastZ(std::make_shared<float64>(9000.)) {
QGraphicsScene::addItem(_canvas.get());
_canvas->clearPixmap();
@ -134,6 +135,10 @@ std::vector<MTPInputDocument> Scene::attachedStickers() const {
}) | ranges::to_vector;
}
std::shared_ptr<float64> Scene::lastZ() const {
return _lastZ;
}
Scene::~Scene() {
// Prevent destroying by scene of all items.
QGraphicsScene::removeItem(_canvas.get());

View file

@ -40,6 +40,8 @@ public:
[[nodiscard]] std::vector<MTPInputDocument> attachedStickers() const;
[[nodiscard]] std::shared_ptr<float64> lastZ() const;
void cancelDrawing();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
@ -47,6 +49,7 @@ protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
private:
const std::shared_ptr<ItemCanvas> _canvas;
const std::shared_ptr<float64> _lastZ;
std::vector<ItemPtr> _items;