Tiles functions and persistence

This commit is contained in:
Ronan Le Tiec 2020-11-14 15:58:42 +01:00
parent 40c9e8161b
commit dddf1fe654
5 changed files with 413 additions and 39 deletions

View File

@ -230,3 +230,120 @@ VPSheet* VPLayout::GetFocusedSheet()
{ {
return m_focusedSheet; return m_focusedSheet;
} }
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSize(qreal width, qreal height)
{
m_tilesSize.setWidth(width);
m_tilesSize.setHeight(height);
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSizeConverted(qreal width, qreal height)
{
m_tilesSize.setWidth(UnitConvertor(width, GetUnit(), Unit::Px));
m_tilesSize.setHeight(UnitConvertor(height, GetUnit(), Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSize(const QSizeF &size)
{
m_tilesSize = size;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSizeConverted(const QSizeF &size)
{
m_tilesSize = QSizeF(
UnitConvertor(size.width(), GetUnit(), Unit::Px),
UnitConvertor(size.height(), GetUnit(), Unit::Px)
);
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPLayout::GetTilesSize() const
{
return m_tilesSize;
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPLayout::GetTilesSizeConverted() const
{
QSizeF convertedSize = QSizeF(
UnitConvertor(m_tilesSize.width(), Unit::Px, GetUnit()),
UnitConvertor(m_tilesSize.height(), Unit::Px, GetUnit())
);
return convertedSize;
}
//---------------------------------------------------------------------------------------------------------------------
PageOrientation VPLayout::GetTilesOrientation()
{
return m_tilesOrientation;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesOrientation(PageOrientation orientation)
{
if(orientation != m_tilesOrientation)
{
m_tilesOrientation = orientation;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom)
{
m_tilesMargins.setLeft(left);
m_tilesMargins.setTop(top);
m_tilesMargins.setRight(right);
m_tilesMargins.setBottom(bottom);
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom)
{
m_tilesMargins.setLeft(UnitConvertor(left, GetUnit(), Unit::Px));
m_tilesMargins.setTop(UnitConvertor(top, GetUnit(), Unit::Px));
m_tilesMargins.setRight(UnitConvertor(right, GetUnit(), Unit::Px));
m_tilesMargins.setBottom(UnitConvertor(bottom, GetUnit(), Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMargins(const QMarginsF &margins)
{
m_tilesMargins = margins;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMarginsConverted(const QMarginsF &margins)
{
m_tilesMargins = UnitConvertor(margins, GetUnit(), Unit::Px);
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPLayout::GetTilesMargins() const
{
return m_tilesMargins;
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPLayout::GetTilesMarginsConverted() const
{
return UnitConvertor(m_tilesMargins, Unit::Px, GetUnit());
}
//---------------------------------------------------------------------------------------------------------------------
bool VPLayout::GetShowTiles()
{
return m_showTiles;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetShowTiles(bool value)
{
m_showTiles = value;
}

View File

@ -138,6 +138,111 @@ public:
VPSheet* GetFocusedSheet(); VPSheet* GetFocusedSheet();
/**
* @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px
* @param width tiles width
* @param height tiles height
*/
void SetTilesSize(qreal width, qreal height);
/**
* @brief SetTilesSizeConverted sets the size of the sheet, the values have to be in the layout's unit
* @param width tiles width
* @param height tiles height
*/
void SetTilesSizeConverted(qreal width, qreal height);
/**
* @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px
* @param size sheet size
*/
void SetTilesSize(const QSizeF &size);
/**
* @brief SetTilesSizeConverted sets the size of the tiles, the values have to be in the layout's unit
* @param size sheet size
*/
void SetTilesSizeConverted(const QSizeF &size);
/**
* @brief GetTilesSize Returns the size of the tiles in Unit::Px
* @return sheet size in Unit::Px
*/
QSizeF GetTilesSize() const;
/**
* @brief GetTilesSizeConverted Returns the size of the tiles in the layout's unit
* @return the size in the layout's unit
*/
QSizeF GetTilesSizeConverted() const;
/**
* @brief GetOrientation Returns the orientation of the tiles
* @return orientation of the tiles
*/
PageOrientation GetTilesOrientation();
/**
* @brief SetOrientation Sets the orientation of the tiles to the given value
* @param orientation the new tiles orientation
*/
void SetTilesOrientation(PageOrientation orientation);
/**
* @brief SetTilesMargins, set the margins of the tiles, the values have to be in Unit::Px
* @param left in Unit::Px
* @param top in Unit::Px
* @param right in Unit::Px
* @param bottom in Unit::Px
*/
void SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom);
/**
* @brief SetSheetMargins, set the margins of the tiles, the values have to be in the unit of the layout
* @param left in Unit::Px
* @param top in Unit::Px
* @param right in Unit::Px
* @param bottom in Unit::Px
*/
void SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom);
/**
* @brief SetTilesMargins set the margins of the tiles, the values have to be in Unit::Px
* @param margins tiles margins
*/
void SetTilesMargins(const QMarginsF &margins);
/**
* @brief SetTilesMarginsConverted set the margins of the tiles, the values have to be in the unit of the layout
* @param margins tiles margins
*/
void SetTilesMarginsConverted(const QMarginsF &margins);
/**
* @brief GetTilesMargins Returns margins of the tiles in Unit::Px
* @return the size in Unit::Px
*/
QMarginsF GetTilesMargins() const;
/**
* @brief GetTilesMarginsConverted Returns the margins of the tiles in the layout's unit
* @return the margins in the tiles's unit
*/
QMarginsF GetTilesMarginsConverted() const;
/**
* @brief GetShowTiles Returns true if the tiles has to be shown on the current sheet
* @return
*/
bool GetShowTiles();
/**
* @brief SetShowTiles Sets wether to show the tiles on the current sheet or not
* @param value true to show the tiles
*/
void SetShowTiles(bool value);
signals: signals:
void PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter); void PieceMovedToPieceList(VPPiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter);
@ -169,6 +274,23 @@ private:
QString m_description{}; QString m_description{};
/**
* @brief m_size the Size of the tiles in Unit::Px
*/
QSizeF m_tilesSize{};
/**
* @brief holds the orientation of the tiles
*/
PageOrientation m_tilesOrientation {PageOrientation::Portrait};
// margins
/**
* @brief m_margins the margins of the tiles in Unit::Px
*/
QMarginsF m_tilesMargins{};
bool m_showTiles{false};
}; };
#endif // VPLAYOUT_H #endif // VPLAYOUT_H

View File

@ -78,6 +78,12 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
m_layout->SetWarningSuperpositionOfPieces(true); m_layout->SetWarningSuperpositionOfPieces(true);
m_layout->SetTitle(QString("My Test Layout")); m_layout->SetTitle(QString("My Test Layout"));
m_layout->SetDescription(QString("Description of my Layout")); m_layout->SetDescription(QString("Description of my Layout"));
m_layout->SetTilesSizeConverted(21,29.7);
m_layout->SetTilesOrientation(PageOrientation::Portrait);
m_layout->SetTilesMarginsConverted(1,1,1,1);
m_layout->SetShowTiles(true);
// -------------------------------------------------------- // --------------------------------------------------------
ui->setupUi(this); ui->setupUi(this);
@ -269,27 +275,6 @@ void VPMainWindow::InitPropertyTabCurrentSheet()
// FIXME ---- For MVP we hide a few things. To be displayed when functions there // FIXME ---- For MVP we hide a few things. To be displayed when functions there
ui->pushButtonSheetRemoveUnusedLength->hide(); ui->pushButtonSheetRemoveUnusedLength->hide();
ui->groupBoxSheetControl->hide(); ui->groupBoxSheetControl->hide();
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::InitPropertyTabLayout()
{
// FIXME ---- For MVP we hide a few things. To be displayed when functions there
ui->groupBoxLayoutControl->hide();
// -------------------- init the unit combobox ---------------------
ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm)));
ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm)));
ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch)));
// set default unit - TODO when we have the setting for the unit
// const qint32 indexUnit = -1;//ui->comboBoxLayoutUnit->findData(qApp->ValentinaSettings()->GetUnit());
// if (indexUnit != -1)
// {
// ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
// }
// some of the UI Elements are connected to the slots via auto-connect // some of the UI Elements are connected to the slots via auto-connect
// see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect // see https://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect
@ -326,14 +311,52 @@ void VPMainWindow::InitPropertyTabLayout()
// TODO init the file format export combobox // TODO init the file format export combobox
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::InitPropertyTabTiles() void VPMainWindow::InitPropertyTabTiles()
{ {
// for the MVP we don't want the tiles tab. // -------------------- layout width, length, orientation ------------------------
// we remove it. As soon as we need it, update this code connect(ui->doubleSpinBoxSheetWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
ui->tabWidgetProperties->removeTab(2); // remove tiles &VPMainWindow::on_TilesSizeChanged);
connect(ui->doubleSpinBoxSheetLength, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesSizeChanged);
connect(ui->radioButtonSheetPortrait, QOverload<bool>::of(&QRadioButton::clicked), this,
&VPMainWindow::on_TilesOrientationChanged);
connect(ui->radioButtonSheetLandscape, QOverload<bool>::of(&QRadioButton::clicked), this,
&VPMainWindow::on_TilesOrientationChanged);
// -------------------- margins ------------------------
connect(ui->doubleSpinBoxSheetMarginTop, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
connect(ui->doubleSpinBoxSheetMarginRight, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
connect(ui->doubleSpinBoxSheetMarginBottom, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
connect(ui->doubleSpinBoxSheetMarginLeft, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&VPMainWindow::on_TilesMarginChanged);
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::InitPropertyTabLayout()
{
// FIXME ---- For MVP we hide a few things. To be displayed when functions there
ui->groupBoxLayoutControl->hide();
// -------------------- init the unit combobox ---------------------
ui->comboBoxLayoutUnit->addItem(tr("Centimeters"), QVariant(UnitsToStr(Unit::Cm)));
ui->comboBoxLayoutUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm)));
ui->comboBoxLayoutUnit->addItem(tr("Inches"), QVariant(UnitsToStr(Unit::Inch)));
// set default unit - TODO when we have the setting for the unit
// const qint32 indexUnit = -1;//ui->comboBoxLayoutUnit->findData(qApp->ValentinaSettings()->GetUnit());
// if (indexUnit != -1)
// {
// ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit);
// }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -423,7 +446,7 @@ void VPMainWindow::SetPropertyTabSheetData()
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, size.height()); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, size.height());
// Set Orientation // Set Orientation
if(size.width() <= size.height()) if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait)
{ {
ui->radioButtonSheetPortrait->setChecked(true); ui->radioButtonSheetPortrait->setChecked(true);
} }
@ -446,6 +469,36 @@ void VPMainWindow::SetPropertyTabSheetData()
SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges()); SetCheckBoxValue(ui->checkBoxSheetStickyEdges, m_layout->GetFocusedSheet()->GetStickyEdges());
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::SetPropertyTabTilesData()
{
// set Width / Length
QSizeF size = m_layout->GetTilesSizeConverted();
SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesWidth, size.width());
SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesLength, size.height());
// Set Orientation
if(m_layout->GetTilesOrientation() == PageOrientation::Portrait)
{
ui->radioButtonSheetPortrait->setChecked(true);
}
else
{
ui->radioButtonSheetLandscape->setChecked(true);
}
// set margins
QMarginsF margins = m_layout->GetTilesMarginsConverted();
SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginLeft, margins.left());
SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginTop, margins.top());
SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginRight, margins.right());
SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginBottom, margins.bottom());
// set "show tiles" checkbox
ui->checkBoxTilesShowTiles->setChecked(m_layout->GetShowTiles());
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::SetPropertyTabLayoutData() void VPMainWindow::SetPropertyTabLayoutData()
{ {
@ -467,11 +520,7 @@ void VPMainWindow::SetPropertyTabLayoutData()
SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces()); SetCheckBoxValue(ui->checkBoxLayoutWarningPiecesSuperposition, m_layout->GetWarningSuperpositionOfPieces());
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::SetPropertyTabTilesData()
{
// TODO
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::InitMainGraphics() void VPMainWindow::InitMainGraphics()
@ -941,6 +990,62 @@ void VPMainWindow::on_SheetMarginChanged()
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_TilesSizeChanged()
{
m_layout->SetTilesSizeConverted(ui->doubleSpinBoxTilesWidth->value(), ui->doubleSpinBoxTilesLength->value());
// TODO Undo / Redo
m_graphicsView->RefreshLayout();
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_TilesOrientationChanged()
{
// Updates the orientation
if(ui->radioButtonTilesPortrait->isChecked())
{
m_layout->SetTilesOrientation(PageOrientation::Portrait);
}
else
{
m_layout->SetTilesOrientation(PageOrientation::Landscape);
}
// TODO Undo / Redo
m_graphicsView->RefreshLayout();
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_TilesMarginChanged()
{
m_layout->GetFocusedSheet()->SetSheetMarginsConverted(
ui->doubleSpinBoxTilesMarginLeft->value(),
ui->doubleSpinBoxTilesMarginTop->value(),
ui->doubleSpinBoxTilesMarginRight->value(),
ui->doubleSpinBoxTilesMarginBottom->value()
);
// TODO Undo / Redo
m_graphicsView->RefreshLayout();
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_checkBoxTilesShowTiles_toggled(bool checked)
{
m_layout->SetShowTiles(checked);
// TODO Undo / Redo
m_graphicsView->RefreshLayout();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_SheetFollowGrainlineChanged() void VPMainWindow::on_SheetFollowGrainlineChanged()
{ {

View File

@ -285,33 +285,33 @@ private slots:
void on_comboBoxSheetTemplate_currentIndexChanged(int index); void on_comboBoxSheetTemplate_currentIndexChanged(int index);
/** /**
* @brief LayoutSizeChanged When the width or the length has been changed in * @brief on_SheetSizeChanged When the width or the length has been changed in
* the layout property tab * the sheet property tab
*/ */
void on_SheetSizeChanged(); void on_SheetSizeChanged();
/** /**
* @brief LayoutOrientationChanged When one of the radio boxes for the layout * @brief on_SheetOrientationChanged When one of the radio boxes for the sheet
* orientation has been clicked * orientation has been clicked
*/ */
void on_SheetOrientationChanged(); void on_SheetOrientationChanged();
/** /**
* @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button * @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button
* "Remove unused length" in the layout property tab is clicked. * "Remove unused length" in the sheet property tab is clicked.
* The slot is automatically connected through name convention. * The slot is automatically connected through name convention.
*/ */
void on_pushButtonSheetRemoveUnusedLength_clicked(); void on_pushButtonSheetRemoveUnusedLength_clicked();
/** /**
* @brief on_LayoutMarginChanged When one of the margin values has been changed * @brief on_SheetMarginChanged When one of the margin values has been changed
* in the layout property tab. * in the sheet property tab.
*/ */
void on_SheetMarginChanged(); void on_SheetMarginChanged();
/** /**
* @brief LayoutFollowGrainlineChanged When one of the radio boxes for the * @brief LayoutFollowGrainlineChanged When one of the radio boxes for the
* "Follow grainline" has been clicked in the layout property tab. * "Follow grainline" has been clicked in the sheet property tab.
*/ */
void on_SheetFollowGrainlineChanged(); void on_SheetFollowGrainlineChanged();
@ -323,6 +323,33 @@ private slots:
*/ */
void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value); void on_doubleSpinBoxSheetPiecesGap_valueChanged(double value);
/**
* @brief on_TilesSizeChanged When the width or the length has been changed in
* the tiles property tab
*/
void on_TilesSizeChanged();
/**
* @brief on_TilesOrientationChanged When one of the radio boxes for the tiles
* orientation has been clicked
*/
void on_TilesOrientationChanged();
/**
* @brief on_TilesMarginChanged When one of the margin values has been changed
* in the tiles property tab.
*/
void on_TilesMarginChanged();
/**
* @brief on_checkBoxTilesShowTiles_toggled When the checkbox "show tiles" is
* clicked
* @param checked´
*/
void on_checkBoxTilesShowTiles_toggled(bool checked);
/** /**
* @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the * @brief on_checkBoxLayoutWarningPiecesSuperposition_toggled When the
* "Warning when pieces superposition" checkbox value in the layout * "Warning when pieces superposition" checkbox value in the layout

View File

@ -176,7 +176,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>2</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -530,7 +530,7 @@
<string/> <string/>
</attribute> </attribute>
<attribute name="toolTip"> <attribute name="toolTip">
<string>Layout properties</string> <string>Sheet properties</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayoutSheetProperty"> <layout class="QVBoxLayout" name="verticalLayoutSheetProperty">
<property name="leftMargin"> <property name="leftMargin">
@ -1199,6 +1199,9 @@
<attribute name="title"> <attribute name="title">
<string/> <string/>
</attribute> </attribute>
<attribute name="toolTip">
<string>Layout properties</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayoutLayoutProperty"> <layout class="QVBoxLayout" name="verticalLayoutLayoutProperty">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>