mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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.
|
// Undo / Redo.
|
||||||
controllers->undoController->performRequestChanges(
|
controllers->undoController->performRequestChanges(
|
||||||
) | rpl::start_with_next([=](const Undo &command) {
|
) | rpl::start_with_next([=](const Undo &command) {
|
||||||
const auto isUndo = (command == Undo::Undo);
|
if (command == Undo::Undo) {
|
||||||
|
_scene->performUndo();
|
||||||
const auto filtered = _scene->items(isUndo
|
} else {
|
||||||
? Qt::DescendingOrder
|
_scene->performRedo();
|
||||||
: 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_hasUndo = _scene->hasUndo();
|
_hasUndo = _scene->hasUndo();
|
||||||
|
|
|
@ -171,6 +171,24 @@ bool Scene::hasRedo() const {
|
||||||
return ranges::any_of(_items, &NumberedItem::isUndidStatus);
|
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() {
|
Scene::~Scene() {
|
||||||
// Prevent destroying by scene of all items.
|
// Prevent destroying by scene of all items.
|
||||||
QGraphicsScene::removeItem(_canvas.get());
|
QGraphicsScene::removeItem(_canvas.get());
|
||||||
|
|
|
@ -52,6 +52,9 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] bool hasUndo() const;
|
[[nodiscard]] bool hasUndo() const;
|
||||||
[[nodiscard]] bool hasRedo() const;
|
[[nodiscard]] bool hasRedo() const;
|
||||||
|
|
||||||
|
void performUndo();
|
||||||
|
void performRedo();
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue