From 54710608d6bcc8f5fcac66dd75abc1e6ad0a0f25 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 26 Aug 2021 08:50:11 +0300 Subject: [PATCH] Better piece flipping. --- src/app/puzzle/layout/vppiece.cpp | 16 ++++++++++++++++ src/app/puzzle/layout/vppiece.h | 5 +++++ src/app/puzzle/vpmainwindow.cpp | 9 ++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index 2d925c461..c1147f75e 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -243,3 +243,19 @@ void VPPiece::SetPatternLabelData(const VTextManager &data) { VLayoutPiece::SetPatternLabelData(data); } + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::Flip() +{ + QTransform pieceMatrix = GetMatrix(); + QPointF center = pieceMatrix.map(DetailBoundingRect().center()); + + QTransform m; + m.translate(center.x(), 0); + m.scale(-1, 1); + m.translate(-center.x(), 0); + + pieceMatrix *= m; + SetMatrix(pieceMatrix); + SetMirror(!IsMirror()); +} diff --git a/src/app/puzzle/layout/vppiece.h b/src/app/puzzle/layout/vppiece.h index 58768e5a8..d1825b754 100644 --- a/src/app/puzzle/layout/vppiece.h +++ b/src/app/puzzle/layout/vppiece.h @@ -101,6 +101,11 @@ public: auto GetPatternLabelData() const ->VTextManager; void SetPatternLabelData(const VTextManager &data); + /** + * @brief Flip horizontally mirror around center of bounding rect + */ + void Flip(); + private: Q_DISABLE_COPY(VPPiece) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index d2c4a9d75..fd9388dd2 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -570,9 +570,12 @@ void VPMainWindow::InitPropertyTabCurrentPiece() VPPiecePtr selectedPiece = selectedPieces.first(); if (not selectedPiece.isNull()) { - selectedPiece->SetMirror(checked); - LayoutWasSaved(false); - emit m_layout->PieceTransformationChanged(selectedPiece); + if (selectedPiece->IsMirror() != checked) + { + selectedPiece->Flip(); + LayoutWasSaved(false); + emit m_layout->PieceTransformationChanged(selectedPiece); + } } } });