Sheet orientation and piece transform

This commit is contained in:
Ronan Le Tiec 2020-06-25 16:59:48 +02:00
parent 4ad2c854b2
commit 2cc3c93dea
6 changed files with 63 additions and 31 deletions

View File

@ -68,7 +68,13 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QRectF VPGraphicsSheet::GetSheetRect() const QRectF VPGraphicsSheet::GetSheetRect() const
{ {
QRectF rect = QRectF(QPointF(0,0), m_sheet->GetSheetSize()); QPoint topLeft = QPoint(0,0);
QSizeF size = m_sheet->GetSheetSize();
if(m_sheet->GetOrientation() == PageOrientation::Landscape)
{
size.transpose();
}
QRectF rect = QRectF(topLeft, size);
return rect; return rect;
} }
@ -77,6 +83,12 @@ QRectF VPGraphicsSheet::GetMarginsRect() const
{ {
QMarginsF margins = m_sheet->GetSheetMargins(); QMarginsF margins = m_sheet->GetSheetMargins();
QSizeF size = m_sheet->GetSheetSize(); QSizeF size = m_sheet->GetSheetSize();
if(m_sheet->GetOrientation() == PageOrientation::Landscape)
{
size.transpose();
}
QRectF rect = QRectF( QRectF rect = QRectF(
QPointF(margins.left(),margins.top()), QPointF(margins.left(),margins.top()),
QPointF(size.width()-margins.right(), size.height()-margins.bottom()) QPointF(size.width()-margins.right(), size.height()-margins.bottom())

View File

@ -67,8 +67,8 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
m_layout->SetFocusedSheet(); m_layout->SetFocusedSheet();
// ----- for test purposes, to be removed------------------ // ----- for test purposes, to be removed------------------
sheet->SetSheetMarginsConverted(2, 2, 2, 2); sheet->SetSheetMarginsConverted(1, 1, 1, 1);
sheet->SetSheetSizeConverted(30.0, 45); sheet->SetSheetSizeConverted(84.1, 118.9);
sheet->SetPiecesGapConverted(1); sheet->SetPiecesGapConverted(1);
m_layout->SetUnit(Unit::Cm); m_layout->SetUnit(Unit::Cm);
@ -795,18 +795,6 @@ void VPMainWindow::on_SheetSizeChanged()
{ {
m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value());
// updates orientation - no need to block signals because the signal reacts on "clicked"
if(ui->doubleSpinBoxSheetWidth->value() <= ui->doubleSpinBoxSheetLength->value())
{
//portrait
ui->radioButtonSheetPortrait->setChecked(true);
}
else
{
//landscape
ui->radioButtonSheetLandscape->setChecked(true);
}
// TODO Undo / Redo // TODO Undo / Redo
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
@ -815,14 +803,15 @@ void VPMainWindow::on_SheetSizeChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_SheetOrientationChanged() void VPMainWindow::on_SheetOrientationChanged()
{ {
// swap the width and length // Updates the orientation
qreal width_before = ui->doubleSpinBoxSheetWidth->value(); if(ui->radioButtonSheetPortrait->isChecked())
qreal length_before = ui->doubleSpinBoxSheetLength->value(); {
m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Portrait);
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, length_before); }
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, width_before); else
{
m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Landscape);
}
// TODO Undo / Redo // TODO Undo / Redo

View File

@ -55,9 +55,9 @@ VPPiece::VPPiece(VLayoutPiece layoutPiece): VLayoutPiece(layoutPiece)
// then translate the piece so that the top left corner of the bouding rect of the piece is at the position // then translate the piece so that the top left corner of the bouding rect of the piece is at the position
// (0,0) in the sheet coordinate system // (0,0) in the sheet coordinate system
QRectF boundingRect = DetailBoundingRect(); QRectF boundingRect = DetailBoundingRect();
m_offset = boundingRect.topLeft(); QPointF offset = boundingRect.topLeft();
matrix = GetMatrix(); matrix = GetMatrix();
matrix.translate(-m_offset.x() ,-m_offset.y()); matrix.translate(-offset.x() ,-offset.y());
SetMatrix(matrix); SetMatrix(matrix);
} }
@ -98,9 +98,7 @@ void VPPiece::SetPieceMirrored(bool value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPPiece::SetPosition(QPointF point) void VPPiece::SetPosition(QPointF point)
{ {
QTransform matrix = GetMatrix(); m_transform.translate(point.x() - m_transform.dx(), point.y() - m_transform.dy());
matrix.translate(point.x() - matrix.dx() - m_offset.x(), point.y() - matrix.dy() - m_offset.y());
SetMatrix(matrix);
emit PositionChanged(); emit PositionChanged();
} }
@ -108,7 +106,7 @@ void VPPiece::SetPosition(QPointF point)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VPPiece::GetPosition() QPointF VPPiece::GetPosition()
{ {
return QPointF(GetMatrix().dx() + m_offset.x(), GetMatrix().dy()+m_offset.y()); return QPointF(m_transform.dx(),m_transform.dy());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -151,12 +151,12 @@ signals:
private: private:
Q_DISABLE_COPY(VPPiece) Q_DISABLE_COPY(VPPiece)
QPointF m_offset{QPointF()};
QVector<QPointF> m_grainline{QVector<QPointF>()}; QVector<QPointF> m_grainline{QVector<QPointF>()};
bool m_isGrainlineEnabled{false}; bool m_isGrainlineEnabled{false};
qreal m_grainlineAngle{0}; qreal m_grainlineAngle{0};
// for now separate the position of the piece to the matrix coming from vlayoutpiece
// because it's difficult to have the origin of the piece by (0,0)
QTransform m_transform{QTransform()}; QTransform m_transform{QTransform()};
// use a separate value for now because it's not easy to get the angle from the transform matrix // use a separate value for now because it's not easy to get the angle from the transform matrix
qreal m_pieceAngle{0}; qreal m_pieceAngle{0};

View File

@ -107,6 +107,22 @@ QSizeF VPSheet::GetSheetSizeConverted() const
return convertedSize; return convertedSize;
} }
//---------------------------------------------------------------------------------------------------------------------
PageOrientation VPSheet::GetOrientation()
{
return m_orientation;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetOrientation(PageOrientation orientation)
{
if(orientation != m_orientation)
{
m_orientation = orientation;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom) void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom)
{ {

View File

@ -104,6 +104,18 @@ public:
*/ */
QSizeF GetSheetSizeConverted() const; QSizeF GetSheetSizeConverted() const;
/**
* @brief GetOrientation Returns the orientation of the sheet
* @return orientation of the sheet
*/
PageOrientation GetOrientation();
/**
* @brief SetOrientation Sets the orientation of the sheet to the given value
* @param orientation the new page orientation
*/
void SetOrientation(PageOrientation orientation);
/** /**
* @brief SetSheetMargins, set the margins of the sheet, the values have to be in Unit::Px * @brief SetSheetMargins, set the margins of the sheet, the values have to be in Unit::Px
* @param left in Unit::Px * @param left in Unit::Px
@ -205,6 +217,11 @@ private:
*/ */
QSizeF m_size{}; QSizeF m_size{};
/**
* @brief holds the orientation of the sheet
*/
PageOrientation m_orientation {PageOrientation::Portrait};
// margins // margins
/** /**
* @brief m_margins the margins in Unit::Px * @brief m_margins the margins in Unit::Px