2021-03-03 09:24:35 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <base/unique_qptr.h>
|
2021-07-07 18:14:50 +00:00
|
|
|
#include <editor/photo_editor_inner_common.h>
|
2021-03-03 09:24:35 +00:00
|
|
|
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
|
|
|
|
class QGraphicsSceneMouseEvent;
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class RpWidget;
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Editor {
|
|
|
|
|
|
|
|
class ItemCanvas;
|
2021-03-14 09:44:49 +00:00
|
|
|
class NumberedItem;
|
2021-03-03 09:24:35 +00:00
|
|
|
|
|
|
|
class Scene final : public QGraphicsScene {
|
|
|
|
public:
|
2021-07-07 21:51:45 +00:00
|
|
|
using ItemPtr = std::shared_ptr<NumberedItem>;
|
2021-03-10 15:51:23 +00:00
|
|
|
|
2021-03-03 09:24:35 +00:00
|
|
|
Scene(const QRectF &rect);
|
|
|
|
~Scene();
|
|
|
|
void applyBrush(const QColor &color, float size);
|
|
|
|
|
2021-03-10 15:51:23 +00:00
|
|
|
[[nodiscard]] std::vector<ItemPtr> items(
|
2021-03-14 09:44:49 +00:00
|
|
|
Qt::SortOrder order = Qt::DescendingOrder) const;
|
2021-07-07 21:51:45 +00:00
|
|
|
void addItem(ItemPtr item);
|
2021-03-10 15:51:23 +00:00
|
|
|
void removeItem(not_null<QGraphicsItem*> item);
|
2021-07-08 12:29:04 +00:00
|
|
|
void removeItem(const ItemPtr &item);
|
2021-03-08 16:31:48 +00:00
|
|
|
[[nodiscard]] rpl::producer<> addsItem() const;
|
2021-07-04 14:22:57 +00:00
|
|
|
[[nodiscard]] rpl::producer<> removesItem() const;
|
2021-03-03 09:24:35 +00:00
|
|
|
|
2021-07-06 22:31:43 +00:00
|
|
|
[[nodiscard]] std::shared_ptr<float64> lastZ() const;
|
|
|
|
|
2021-07-06 23:10:13 +00:00
|
|
|
void updateZoom(float64 zoom);
|
|
|
|
|
2021-05-08 15:02:41 +00:00
|
|
|
void cancelDrawing();
|
2021-07-07 18:14:50 +00:00
|
|
|
|
2021-07-07 21:57:40 +00:00
|
|
|
[[nodiscard]] bool hasUndo() const;
|
|
|
|
[[nodiscard]] bool hasRedo() const;
|
2021-07-07 22:03:00 +00:00
|
|
|
|
|
|
|
void performUndo();
|
|
|
|
void performRedo();
|
2021-07-08 12:29:04 +00:00
|
|
|
|
|
|
|
void save(SaveState state);
|
|
|
|
void restore(SaveState state);
|
|
|
|
|
|
|
|
void clearRedoList();
|
2021-03-03 09:24:35 +00:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
private:
|
2021-07-08 12:29:04 +00:00
|
|
|
void removeIf(Fn<bool(const ItemPtr &)> proj);
|
2021-03-10 15:51:23 +00:00
|
|
|
const std::shared_ptr<ItemCanvas> _canvas;
|
2021-07-06 22:31:43 +00:00
|
|
|
const std::shared_ptr<float64> _lastZ;
|
2021-03-10 15:51:23 +00:00
|
|
|
|
|
|
|
std::vector<ItemPtr> _items;
|
2021-03-03 09:24:35 +00:00
|
|
|
|
|
|
|
float64 _lastLineZ = 0.;
|
2021-03-14 09:44:49 +00:00
|
|
|
int _itemNumber = 0;
|
|
|
|
|
2021-07-04 14:22:57 +00:00
|
|
|
rpl::event_stream<> _addsItem, _removesItem;
|
2021-03-03 09:24:35 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Editor
|