Better piece flipping.

This commit is contained in:
Roman Telezhynskyi 2021-08-26 08:50:11 +03:00
parent d32bbfcfd4
commit 54710608d6
3 changed files with 27 additions and 3 deletions

View File

@ -243,3 +243,19 @@ void VPPiece::SetPatternLabelData(const VTextManager &data)
{ {
VLayoutPiece::SetPatternLabelData(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());
}

View File

@ -101,6 +101,11 @@ public:
auto GetPatternLabelData() const ->VTextManager; auto GetPatternLabelData() const ->VTextManager;
void SetPatternLabelData(const VTextManager &data); void SetPatternLabelData(const VTextManager &data);
/**
* @brief Flip horizontally mirror around center of bounding rect
*/
void Flip();
private: private:
Q_DISABLE_COPY(VPPiece) Q_DISABLE_COPY(VPPiece)

View File

@ -570,11 +570,14 @@ void VPMainWindow::InitPropertyTabCurrentPiece()
VPPiecePtr selectedPiece = selectedPieces.first(); VPPiecePtr selectedPiece = selectedPieces.first();
if (not selectedPiece.isNull()) if (not selectedPiece.isNull())
{ {
selectedPiece->SetMirror(checked); if (selectedPiece->IsMirror() != checked)
{
selectedPiece->Flip();
LayoutWasSaved(false); LayoutWasSaved(false);
emit m_layout->PieceTransformationChanged(selectedPiece); emit m_layout->PieceTransformationChanged(selectedPiece);
} }
} }
}
}); });
// Translate // Translate