From c5a3375d78326a6d6d103316ffb3d6e1edddc4fe Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 8 Apr 2024 18:58:23 +0300 Subject: [PATCH] Animate piece transformation with stickying animation. --- src/app/puzzle/vpmainwindow.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 9f2060d5c..4c121de20 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -3479,8 +3479,7 @@ void VPMainWindow::TranslatePieceRelatively(const VPPiecePtr &piece, const QRect pieceDy += dy * ((pieceRect.topLeft().y() - rect.topLeft().y()) / rect.height()) * 2.; } - auto *command = new VPUndoPieceMove(piece, pieceDx, pieceDy); - m_layout->UndoStack()->push(command); + m_layout->UndoStack()->push(new VPUndoPieceMove(piece, pieceDx, pieceDy)); if (m_layout->LayoutSettings().IsStickyEdges()) { @@ -3488,9 +3487,14 @@ void VPMainWindow::TranslatePieceRelatively(const VPPiecePtr &piece, const QRect qreal stickyTranslateY = 0; if (piece->StickyPosition(stickyTranslateX, stickyTranslateY)) { + QTime const dieTime = QTime::currentTime().addMSecs(150); + while (QTime::currentTime() < dieTime) + { + QCoreApplication::processEvents(QEventLoop::AllEvents, 50); + } + bool const allowMerge = selectedPiecesCount == 1; - auto *stickyCommand = new VPUndoPieceMove(piece, stickyTranslateX, stickyTranslateY, allowMerge); - m_layout->UndoStack()->push(stickyCommand); + m_layout->UndoStack()->push(new VPUndoPieceMove(piece, stickyTranslateX, stickyTranslateY, allowMerge)); } } } @@ -3525,8 +3529,7 @@ void VPMainWindow::RotatePieces() origin.origin = rect.center(); origin.custom = true; - auto *command = new VPUndoPieceRotate(piece, origin, angle, angle); - m_layout->UndoStack()->push(command); + m_layout->UndoStack()->push(new VPUndoPieceRotate(piece, origin, angle, angle)); } } m_layout->UndoStack()->endMacro();