mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Moved performing of Undo/Redo from Editor::Paint to Editor::Scene.
This commit is contained in:
parent
aef2148ed0
commit
1e3044fbf4
3 changed files with 25 additions and 12 deletions
|
@ -67,18 +67,10 @@ Paint::Paint(
|
|||
// Undo / Redo.
|
||||
controllers->undoController->performRequestChanges(
|
||||
) | rpl::start_with_next([=](const Undo &command) {
|
||||
const auto isUndo = (command == Undo::Undo);
|
||||
|
||||
const auto filtered = _scene->items(isUndo
|
||||
? Qt::DescendingOrder
|
||||
: Qt::AscendingOrder);
|
||||
|
||||
auto proj = [&](const ItemPtr &i) {
|
||||
return isUndo ? i->isVisible() : isItemHidden(i);
|
||||
};
|
||||
const auto it = ranges::find_if(filtered, std::move(proj));
|
||||
if (it != filtered.end()) {
|
||||
(*it)->setVisible(!isUndo);
|
||||
if (command == Undo::Undo) {
|
||||
_scene->performUndo();
|
||||
} else {
|
||||
_scene->performRedo();
|
||||
}
|
||||
|
||||
_hasUndo = _scene->hasUndo();
|
||||
|
|
|
@ -171,6 +171,24 @@ bool Scene::hasRedo() const {
|
|||
return ranges::any_of(_items, &NumberedItem::isUndidStatus);
|
||||
}
|
||||
|
||||
void Scene::performUndo() {
|
||||
const auto filtered = items(Qt::DescendingOrder);
|
||||
|
||||
const auto it = ranges::find_if(filtered, &NumberedItem::isNormalStatus);
|
||||
if (it != filtered.end()) {
|
||||
(*it)->setStatus(NumberedItem::Status::Undid);
|
||||
}
|
||||
}
|
||||
|
||||
void Scene::performRedo() {
|
||||
const auto filtered = items(Qt::AscendingOrder);
|
||||
|
||||
const auto it = ranges::find_if(filtered, &NumberedItem::isUndidStatus);
|
||||
if (it != filtered.end()) {
|
||||
(*it)->setStatus(NumberedItem::Status::Normal);
|
||||
}
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
// Prevent destroying by scene of all items.
|
||||
QGraphicsScene::removeItem(_canvas.get());
|
||||
|
|
|
@ -52,6 +52,9 @@ public:
|
|||
|
||||
[[nodiscard]] bool hasUndo() const;
|
||||
[[nodiscard]] bool hasRedo() const;
|
||||
|
||||
void performUndo();
|
||||
void performRedo();
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
|
Loading…
Add table
Reference in a new issue