Preview grid of the tiles on the sheet

This commit is contained in:
Ronan Le Tiec 2020-11-14 17:31:34 +01:00
parent dddf1fe654
commit e7cd13b703
8 changed files with 152 additions and 14 deletions

View File

@ -27,6 +27,8 @@
*************************************************************************/
#include "vpgraphicssheet.h"
#include "vplayout.h"
#include <QtMath>
//---------------------------------------------------------------------------------------------------------------------
VPGraphicsSheet::VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent):
@ -68,6 +70,66 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
painter->drawRect(GetSheetRect());
}
// show the tiles grid. Maybe it shouldn't be in the graphics sheet, maybe better in maingraphicsview
VPLayout* layout = m_sheet->GetLayout();
if(layout->GetShowTiles())
{
pen.setColor(QColor(255,0,0,127));
pen.setStyle(Qt::DashLine);
painter->setPen(pen);
QSizeF tilesSize = layout->GetTilesSize();
QSizeF sheetSize = m_sheet->GetSheetSize();
QMarginsF tilesMargins = layout->GetTilesMargins();
PageOrientation tilesOrientation = layout->GetTilesOrientation();
PageOrientation sheetOrientation = m_sheet->GetOrientation();
qreal colWidth = 0;
qreal rowHeight = 0;
if(tilesOrientation == PageOrientation::Portrait)
{
colWidth = tilesSize.width() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px));
rowHeight = tilesSize.height() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px));
}
else
{
colWidth = tilesSize.height() - (tilesMargins.left()+ tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px));
rowHeight = tilesSize.width() - (tilesMargins.top()+ tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px));
}
// the "+ UnitConvertor(1, Unit::Cm, Unit::Px)" is because of the part for gluing and where we
// have infos of the single tile. Maybe it's not the right value, to be corrected.
qreal drawingWidth = 0;
qreal drawingHeight = 0;
if(sheetOrientation == PageOrientation::Portrait)
{
drawingWidth = sheetSize.width();
drawingHeight = sheetSize.height();
}
else
{
drawingWidth = sheetSize.height();
drawingHeight = sheetSize.width();
}
int nbCol = qCeil(drawingWidth/colWidth);
int nbRow = qCeil(drawingHeight/rowHeight);
for(int i=0;i<=nbCol;i++)
{
painter->drawLine(QPointF(i*colWidth, 0), QPointF(i*colWidth,nbRow*rowHeight));
}
for(int j=0;j<=nbRow;j++)
{
painter->drawLine(QPointF(0, j*rowHeight), QPointF(nbCol*colWidth, j*rowHeight));
}
}
m_boundingRect = GetSheetRect();
}

View File

@ -84,8 +84,14 @@ VMainGraphicsScene* VPMainGraphicsView::GetScene()
//---------------------------------------------------------------------------------------------------------------------
void VPMainGraphicsView::PrepareForExport()
{
m_layout->ClearSelection();
m_graphicsSheet->SetShowBorder(false);
m_graphicsSheet->SetShowMargin(false);
m_showTilesTmp = m_layout->GetShowTiles();
m_layout->SetShowTiles(false);
RefreshLayout();
}
@ -94,6 +100,9 @@ void VPMainGraphicsView::CleanAfterExport()
{
m_graphicsSheet->SetShowBorder(true);
m_graphicsSheet->SetShowMargin(true);
m_layout->SetShowTiles(m_showTilesTmp);
RefreshLayout();
}

View File

@ -99,6 +99,11 @@ private:
QList<VPGraphicsPiece*> m_graphicsPieces{};
/**
* variable to hold temporarly hte value of the show tiles
*/
bool m_showTilesTmp{false};
};
#endif // VPMAINGRAPHICSVIEW_H

View File

@ -318,23 +318,23 @@ void VPMainWindow::InitPropertyTabCurrentSheet()
void VPMainWindow::InitPropertyTabTiles()
{
// -------------------- layout width, length, orientation ------------------------
connect(ui->doubleSpinBoxSheetWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
connect(ui->doubleSpinBoxTilesWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesSizeChanged);
connect(ui->doubleSpinBoxSheetLength, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
connect(ui->doubleSpinBoxTilesLength, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesSizeChanged);
connect(ui->radioButtonSheetPortrait, QOverload<bool>::of(&QRadioButton::clicked), this,
connect(ui->radioButtonTilesPortrait, QOverload<bool>::of(&QRadioButton::clicked), this,
&VPMainWindow::on_TilesOrientationChanged);
connect(ui->radioButtonSheetLandscape, QOverload<bool>::of(&QRadioButton::clicked), this,
connect(ui->radioButtonTilesLandscape, QOverload<bool>::of(&QRadioButton::clicked), this,
&VPMainWindow::on_TilesOrientationChanged);
// -------------------- margins ------------------------
connect(ui->doubleSpinBoxSheetMarginTop, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
connect(ui->doubleSpinBoxTilesMarginTop, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
connect(ui->doubleSpinBoxSheetMarginRight, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
connect(ui->doubleSpinBoxTilesMarginRight, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
connect(ui->doubleSpinBoxSheetMarginBottom, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
connect(ui->doubleSpinBoxTilesMarginBottom, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
connect(ui->doubleSpinBoxSheetMarginLeft, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
connect(ui->doubleSpinBoxTilesMarginLeft, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
}
@ -1021,7 +1021,7 @@ void VPMainWindow::on_TilesOrientationChanged()
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_TilesMarginChanged()
{
m_layout->GetFocusedSheet()->SetSheetMarginsConverted(
m_layout->SetTilesMarginsConverted(
ui->doubleSpinBoxTilesMarginLeft->value(),
ui->doubleSpinBoxTilesMarginTop->value(),
ui->doubleSpinBoxTilesMarginRight->value(),
@ -1034,7 +1034,6 @@ void VPMainWindow::on_TilesMarginChanged()
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked)
{
@ -1045,6 +1044,36 @@ void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked)
m_graphicsView->RefreshLayout();
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_pushButtonTilesExport_clicked()
{
// svg export to do some test for the first test
QString dir = QDir::homePath();
QString filters(tr("PDF Files") + QLatin1String("(*.pdf)"));
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"),
dir + QLatin1String("/") + tr("Layout") + QLatin1String(".pdf"),
filters, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
if(not fileName.isEmpty())
{
m_graphicsView->PrepareForExport();
// TODO : Tiles export
m_graphicsView->CleanAfterExport();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_SheetFollowGrainlineChanged()

View File

@ -349,6 +349,10 @@ private slots:
*/
void on_checkBoxTilesShowTiles_toggled(bool checked);
/**
* @brief on_pushButtonTilesExport_clicked When the export tiles button is clicked
*/
void on_pushButtonTilesExport_clicked();
/**
* @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the

View File

@ -1106,10 +1106,18 @@
</widget>
</item>
<item row="1" column="4">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginRight"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginRight">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginLeft"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginLeft">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="labelTilesMarginTop">
@ -1122,7 +1130,11 @@
</widget>
</item>
<item row="0" column="3">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginTop"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginTop">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="labelTilesMarginBottom">
@ -1135,7 +1147,11 @@
</widget>
</item>
<item row="2" column="3">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginBottom"/>
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesMarginBottom">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>

View File

@ -43,6 +43,12 @@ VPSheet::~VPSheet()
delete m_pieceList;
}
//---------------------------------------------------------------------------------------------------------------------
VPLayout* VPSheet::GetLayout()
{
return m_layout;
}
//---------------------------------------------------------------------------------------------------------------------
VPPieceList* VPSheet::GetPieceList()
{

View File

@ -49,6 +49,12 @@ public:
~VPSheet();
/**
* @brief GetLayout Returns the Layout of the sheet
* @return
*/
VPLayout* GetLayout();
/**
* @brief GetPieceList returns the piece list of the sheet
* @return piece list
@ -203,6 +209,7 @@ public:
void SetStickyEdges(bool state);
bool GetStickyEdges() const;
private:
Q_DISABLE_COPY(VPSheet)