Sheet orientation and piece transform
This commit is contained in:
parent
4ad2c854b2
commit
2cc3c93dea
|
@ -68,7 +68,13 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -77,6 +83,12 @@ QRectF VPGraphicsSheet::GetMarginsRect() const
|
|||
{
|
||||
QMarginsF margins = m_sheet->GetSheetMargins();
|
||||
QSizeF size = m_sheet->GetSheetSize();
|
||||
|
||||
if(m_sheet->GetOrientation() == PageOrientation::Landscape)
|
||||
{
|
||||
size.transpose();
|
||||
}
|
||||
|
||||
QRectF rect = QRectF(
|
||||
QPointF(margins.left(),margins.top()),
|
||||
QPointF(size.width()-margins.right(), size.height()-margins.bottom())
|
||||
|
|
|
@ -67,8 +67,8 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
|
|||
m_layout->SetFocusedSheet();
|
||||
|
||||
// ----- for test purposes, to be removed------------------
|
||||
sheet->SetSheetMarginsConverted(2, 2, 2, 2);
|
||||
sheet->SetSheetSizeConverted(30.0, 45);
|
||||
sheet->SetSheetMarginsConverted(1, 1, 1, 1);
|
||||
sheet->SetSheetSizeConverted(84.1, 118.9);
|
||||
sheet->SetPiecesGapConverted(1);
|
||||
|
||||
m_layout->SetUnit(Unit::Cm);
|
||||
|
@ -795,18 +795,6 @@ void VPMainWindow::on_SheetSizeChanged()
|
|||
{
|
||||
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
|
||||
|
||||
m_graphicsView->RefreshLayout();
|
||||
|
@ -815,14 +803,15 @@ void VPMainWindow::on_SheetSizeChanged()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPMainWindow::on_SheetOrientationChanged()
|
||||
{
|
||||
// swap the width and length
|
||||
qreal width_before = ui->doubleSpinBoxSheetWidth->value();
|
||||
qreal length_before = ui->doubleSpinBoxSheetLength->value();
|
||||
|
||||
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, length_before);
|
||||
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, width_before);
|
||||
|
||||
m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value());
|
||||
// Updates the orientation
|
||||
if(ui->radioButtonSheetPortrait->isChecked())
|
||||
{
|
||||
m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Portrait);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Landscape);
|
||||
}
|
||||
|
||||
// TODO Undo / Redo
|
||||
|
||||
|
|
|
@ -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
|
||||
// (0,0) in the sheet coordinate system
|
||||
QRectF boundingRect = DetailBoundingRect();
|
||||
m_offset = boundingRect.topLeft();
|
||||
QPointF offset = boundingRect.topLeft();
|
||||
matrix = GetMatrix();
|
||||
matrix.translate(-m_offset.x() ,-m_offset.y());
|
||||
matrix.translate(-offset.x() ,-offset.y());
|
||||
SetMatrix(matrix);
|
||||
}
|
||||
|
||||
|
@ -98,9 +98,7 @@ void VPPiece::SetPieceMirrored(bool value)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPPiece::SetPosition(QPointF point)
|
||||
{
|
||||
QTransform matrix = GetMatrix();
|
||||
matrix.translate(point.x() - matrix.dx() - m_offset.x(), point.y() - matrix.dy() - m_offset.y());
|
||||
SetMatrix(matrix);
|
||||
m_transform.translate(point.x() - m_transform.dx(), point.y() - m_transform.dy());
|
||||
|
||||
emit PositionChanged();
|
||||
}
|
||||
|
@ -108,7 +106,7 @@ void VPPiece::SetPosition(QPointF point)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPointF VPPiece::GetPosition()
|
||||
{
|
||||
return QPointF(GetMatrix().dx() + m_offset.x(), GetMatrix().dy()+m_offset.y());
|
||||
return QPointF(m_transform.dx(),m_transform.dy());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -151,12 +151,12 @@ signals:
|
|||
private:
|
||||
Q_DISABLE_COPY(VPPiece)
|
||||
|
||||
QPointF m_offset{QPointF()};
|
||||
|
||||
QVector<QPointF> m_grainline{QVector<QPointF>()};
|
||||
bool m_isGrainlineEnabled{false};
|
||||
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()};
|
||||
// use a separate value for now because it's not easy to get the angle from the transform matrix
|
||||
qreal m_pieceAngle{0};
|
||||
|
|
|
@ -107,6 +107,22 @@ QSizeF VPSheet::GetSheetSizeConverted() const
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -104,6 +104,18 @@ public:
|
|||
*/
|
||||
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
|
||||
* @param left in Unit::Px
|
||||
|
@ -205,6 +217,11 @@ private:
|
|||
*/
|
||||
QSizeF m_size{};
|
||||
|
||||
/**
|
||||
* @brief holds the orientation of the sheet
|
||||
*/
|
||||
PageOrientation m_orientation {PageOrientation::Portrait};
|
||||
|
||||
// margins
|
||||
/**
|
||||
* @brief m_margins the margins in Unit::Px
|
||||
|
|
Loading…
Reference in New Issue
Block a user