diff --git a/src/app/puzzle/layout/layoutdef.cpp b/src/app/puzzle/layout/layoutdef.cpp new file mode 100644 index 000000000..2b3b47df3 --- /dev/null +++ b/src/app/puzzle/layout/layoutdef.cpp @@ -0,0 +1,92 @@ +/************************************************************************ + ** + ** @file layoutdef.cpp + ** @author Roman Telezhynskyi + ** @date 31 8, 2021 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2021 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "layoutdef.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +auto GrainlineTypeToStr(GrainlineType type) -> QString +{ + QString result; + switch (type) + { + case GrainlineType::Horizontal: + result = QStringLiteral("horizontal"); + break; + case GrainlineType::Vertical: + result = QStringLiteral("vertical"); + break; + case GrainlineType::NotFixed: + default: + result = QStringLiteral("notFixed"); + break; + } + return result; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StrToGrainlineType(const QString &string) -> GrainlineType +{ + const QStringList types + { + QStringLiteral("horizontal"), // 0 + QStringLiteral("vertical"), // 1 + QStringLiteral("notFixed") // 2 + }; + + GrainlineType type = GrainlineType::NotFixed; + switch (types.indexOf(string)) + { + case 0:// horizontal + type = GrainlineType::Horizontal; + break; + case 2:// vertical + type = GrainlineType::Vertical; + break; + case 3:// notFixed + default: + type = GrainlineType::NotFixed; + break; + } + return type; +} + + +//--------------------------------------------------------------------------------------------------------------------- +bool VPTransformationOrigon::operator==(const VPTransformationOrigon &origin) const +{ + return this->origin == origin.origin && custom == origin.custom; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VPTransformationOrigon::operator!=(const VPTransformationOrigon &origin) const +{ + return !VPTransformationOrigon::operator==(origin); +} diff --git a/src/app/puzzle/layout/layoutdef.h b/src/app/puzzle/layout/layoutdef.h index 320d3cf0a..faa19b23c 100644 --- a/src/app/puzzle/layout/layoutdef.h +++ b/src/app/puzzle/layout/layoutdef.h @@ -48,9 +48,13 @@ using VPSheetWeakPtr = QWeakPointer; enum class GrainlineType : qint8 { Vertical, - Horizontal + Horizontal, + NotFixed }; +auto GrainlineTypeToStr(GrainlineType type) -> QString; +auto StrToGrainlineType(const QString &string) -> GrainlineType; + struct VPTransformationOrigon { QPointF origin{}; @@ -60,16 +64,4 @@ struct VPTransformationOrigon bool operator!=(const VPTransformationOrigon &origin) const; }; -//--------------------------------------------------------------------------------------------------------------------- -inline bool VPTransformationOrigon::operator==(const VPTransformationOrigon &origin) const -{ - return this->origin == origin.origin && custom == origin.custom; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline bool VPTransformationOrigon::operator!=(const VPTransformationOrigon &origin) const -{ - return !VPTransformationOrigon::operator==(origin); -} - #endif // LAYOUTDEF_H diff --git a/src/app/puzzle/layout/vplayout.cpp b/src/app/puzzle/layout/vplayout.cpp index ab75992b8..97ffaedda 100644 --- a/src/app/puzzle/layout/vplayout.cpp +++ b/src/app/puzzle/layout/vplayout.cpp @@ -67,11 +67,6 @@ auto VPLayout::CreateLayout(QUndoStack *undoStack) -> VPLayoutPtr layout->LayoutSettings().SetIgnoreTilesMargins(settings->GetLayoutTileIgnoreMargins()); layout->LayoutSettings().SetTilesMargins(settings->GetLayoutTileMargins()); - layout->LayoutSettings().SetIgnoreMargins(settings->GetLayoutSheetIgnoreMargins()); - layout->LayoutSettings().SetSheetMargins(settings->GetLayoutSheetMargins()); - layout->LayoutSettings().SetSheetSize(QSizeF(settings->GetLayoutSheetPaperWidth(), - settings->GetLayoutSheetPaperHeight())); - layout->LayoutSettings().SetWarningSuperpositionOfPieces(settings->GetLayoutWarningPiecesSuperposition()); layout->LayoutSettings().SetWarningPiecesOutOfBound(settings->GetLayoutWarningPiecesOutOfBound()); layout->LayoutSettings().SetFollowGrainline(settings->GetLayoutFollowGrainline()); diff --git a/src/app/puzzle/layout/vplayoutsettings.cpp b/src/app/puzzle/layout/vplayoutsettings.cpp index a112787ad..b67cc79aa 100644 --- a/src/app/puzzle/layout/vplayoutsettings.cpp +++ b/src/app/puzzle/layout/vplayoutsettings.cpp @@ -202,336 +202,6 @@ void VPLayoutSettings::SetShowTiles(bool value) m_showTiles = value; } -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetTemplateSize(PaperSizeTemplate tmpl) -> QSizeF -{ - qreal height = 0; - qreal width = 0; - - switch (tmpl) - { - case PaperSizeTemplate::A0: - width = UnitConvertor(841, Unit::Mm, Unit::Px); - height = UnitConvertor(1189, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A1: - width = UnitConvertor(594, Unit::Mm, Unit::Px); - height = UnitConvertor(841, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A2: - width = UnitConvertor(420, Unit::Mm, Unit::Px); - height = UnitConvertor(594, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A3: - width = UnitConvertor(297, Unit::Mm, Unit::Px); - height = UnitConvertor(420, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::A4: - width = UnitConvertor(210, Unit::Mm, Unit::Px); - height = UnitConvertor(297, Unit::Mm, Unit::Px); - break; - - case PaperSizeTemplate::Letter: - width = UnitConvertor(8.5, Unit::Inch, Unit::Px); - height = UnitConvertor(11, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Legal: - width = UnitConvertor(8.5, Unit::Inch, Unit::Px); - height = UnitConvertor(14, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Tabloid: - width = UnitConvertor(11, Unit::Inch, Unit::Px); - height = UnitConvertor(17, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll24in: - width = UnitConvertor(24, Unit::Inch, Unit::Px); - height = UnitConvertor(48, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll30in: - width = UnitConvertor(30, Unit::Inch, Unit::Px); - height = UnitConvertor(60, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll36in: - width = UnitConvertor(36, Unit::Inch, Unit::Px); - height = UnitConvertor(72, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll42in: - width = UnitConvertor(42, Unit::Inch, Unit::Px); - height = UnitConvertor(84, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll44in: - width = UnitConvertor(44, Unit::Inch, Unit::Px); - height = UnitConvertor(88, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll48in: - width = UnitConvertor(48, Unit::Inch, Unit::Px); - height = UnitConvertor(96, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll62in: - width = UnitConvertor(62, Unit::Inch, Unit::Px); - height = UnitConvertor(124, Unit::Inch, Unit::Px); - break; - - case PaperSizeTemplate::Roll72in: - width = UnitConvertor(72, Unit::Inch, Unit::Px); - height = UnitConvertor(144, Unit::Inch, Unit::Px); - break; - - default: - break; - } - - return QSizeF(width, height); -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetTemplateName(PaperSizeTemplate tmpl) -> QString -{ - QString tmplName; - switch (tmpl) - { - case PaperSizeTemplate::A0: - tmplName = QString("A0"); - break; - - case PaperSizeTemplate::A1: - tmplName = QString("A1"); - break; - - case PaperSizeTemplate::A2: - tmplName = QString("A2"); - break; - - case PaperSizeTemplate::A3: - tmplName = QString("A3"); - break; - - case PaperSizeTemplate::A4: - tmplName = QString("A4"); - break; - - case PaperSizeTemplate::Letter: - tmplName = tr("Letter"); - break; - - case PaperSizeTemplate::Legal: - tmplName = tr("Legal"); - break; - - case PaperSizeTemplate::Tabloid: - tmplName = tr("Tabloid"); - break; - - case PaperSizeTemplate::Roll24in: - tmplName = tr("Roll 24in"); - break; - - case PaperSizeTemplate::Roll30in: - tmplName = tr("Roll 30in"); - break; - - case PaperSizeTemplate::Roll36in: - tmplName = tr("Roll 36in"); - break; - - case PaperSizeTemplate::Roll42in: - tmplName = tr("Roll 42in"); - break; - - case PaperSizeTemplate::Roll44in: - tmplName = tr("Roll 44in"); - break; - - case PaperSizeTemplate::Roll48in: - tmplName = tr("Roll 48in"); - break; - - case PaperSizeTemplate::Roll62in: - tmplName = tr("Roll 62in"); - break; - - case PaperSizeTemplate::Roll72in: - tmplName = tr("Roll 72in"); - break; - - case PaperSizeTemplate::Custom: - tmplName = tr("Custom"); - break; - - default: - break; - } - - if(not tmplName.isEmpty()) - { - tmplName += " " + QStringLiteral("(%1ppi)").arg(PrintDPI); - } - - return tmplName; -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetTemplate(QSizeF size) -> PaperSizeTemplate -{ - Q_UNUSED(size); - // TODO, float comparision not safe and problems with - // inch / cm - -// const int max = static_cast(PaperSizeTemplate::Custom); - -// for (int i=0; i < max; i++) -// { -// PaperSizeTemplate tmpl = static_cast(i); -// const QSizeF tmplSize = GetTemplateSize(tmpl); - -// if(size.width() == tmplSize.width()) -// { -// if(isRollTemplate(tmpl)) -// { -// return tmpl; -// } -// else if(size.height() == tmplSize.height()) -// { -// return tmpl; -// } -// } -// } - - return PaperSizeTemplate::Custom; -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::isRollTemplate(PaperSizeTemplate tmpl) -> bool -{ - switch (tmpl) { - case PaperSizeTemplate::Roll24in: - case PaperSizeTemplate::Roll30in: - case PaperSizeTemplate::Roll36in: - case PaperSizeTemplate::Roll42in: - case PaperSizeTemplate::Roll44in: - case PaperSizeTemplate::Roll48in: - case PaperSizeTemplate::Roll62in: - case PaperSizeTemplate::Roll72in: - return true; - default: - return false; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::PopulateComboBox(QVector *tmpls, QComboBox* comboBox) -{ - const QIcon icoPaper("://puzzleicon/16x16/template.png"); - const QIcon icoRoll("://puzzleicon/16x16/roll.png"); - - QIcon icon; - for (auto tmpl : *tmpls) - { - icon = (isRollTemplate(tmpl))? icoRoll : icoPaper; - comboBox->addItem(icon, GetTemplateName(tmpl), QVariant(static_cast(tmpl))); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetSize(qreal width, qreal height) -{ - m_size.setWidth(width); - m_size.setHeight(height); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetSizeConverted(qreal width, qreal height) -{ - m_size.setWidth(UnitConvertor(width, m_unit, Unit::Px)); - m_size.setHeight(UnitConvertor(height, m_unit, Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetSize(const QSizeF &size) -{ - m_size = size; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetSizeConverted(const QSizeF &size) -{ - m_size = QSizeF( - UnitConvertor(size.width(), m_unit, Unit::Px), - UnitConvertor(size.height(), m_unit, Unit::Px) - ); -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetSheetSize() const -> QSizeF -{ - return m_size; -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetSheetSizeConverted() const -> QSizeF -{ - QSizeF convertedSize = QSizeF( - UnitConvertor(m_size.width(), Unit::Px, m_unit), - UnitConvertor(m_size.height(), Unit::Px, m_unit) - ); - - return convertedSize; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom) -{ - m_margins.setLeft(left); - m_margins.setTop(top); - m_margins.setRight(right); - m_margins.setBottom(bottom); -} -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) -{ - m_margins.setLeft(UnitConvertor(left, m_unit, Unit::Px)); - m_margins.setTop(UnitConvertor(top, m_unit, Unit::Px)); - m_margins.setRight(UnitConvertor(right, m_unit, Unit::Px)); - m_margins.setBottom(UnitConvertor(bottom, m_unit, Unit::Px)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetMargins(const QMarginsF &margins) -{ - m_margins = margins; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetSheetMarginsConverted(const QMarginsF &margins) -{ - m_margins = UnitConvertor(margins, m_unit, Unit::Px); -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetSheetMargins() const -> QMarginsF -{ - return m_margins; -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::GetSheetMarginsConverted() const -> QMarginsF -{ - return UnitConvertor(m_margins, Unit::Px, m_unit); -} - //--------------------------------------------------------------------------------------------------------------------- void VPLayoutSettings::SetFollowGrainline(bool state) { @@ -652,15 +322,3 @@ void VPLayoutSettings::SetIgnoreTilesMargins(bool newIgnoreTilesMargins) { m_ignoreTilesMargins = newIgnoreTilesMargins; } - -//--------------------------------------------------------------------------------------------------------------------- -auto VPLayoutSettings::IgnoreMargins() const -> bool -{ - return m_ignoreMargins; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPLayoutSettings::SetIgnoreMargins(bool newIgnoreMargins) -{ - m_ignoreMargins = newIgnoreMargins; -} diff --git a/src/app/puzzle/layout/vplayoutsettings.h b/src/app/puzzle/layout/vplayoutsettings.h index aabfc9897..beb054378 100644 --- a/src/app/puzzle/layout/vplayoutsettings.h +++ b/src/app/puzzle/layout/vplayoutsettings.h @@ -35,26 +35,6 @@ #include "def.h" -enum class PaperSizeTemplate : qint8 { - A0 = 0, - A1, - A2, - A3, - A4, - Letter, - Legal, - Tabloid, - Roll24in, - Roll30in, - Roll36in, - Roll42in, - Roll44in, - Roll48in, - Roll62in, - Roll72in, - Custom -}; - class VPLayoutSettings { Q_DECLARE_TR_FUNCTIONS(VPLayoutSettings) @@ -252,122 +232,7 @@ public: */ void SetShowTiles(bool value); - /** - * @brief GetTemplateSize Returns the size in Px of the given template - * @param tmpl paper size template - * @return the size in Px - */ - static auto GetTemplateSize(PaperSizeTemplate tmpl) -> QSizeF; - - /** - * @brief GetTemplateName Returns the name of the given template - * @param tmpl paper size template - * @return name of the given template - */ - static auto GetTemplateName(PaperSizeTemplate tmpl) -> QString; - - /** - * @brief GetTemplate GetTemplate Returns the template that corresponds to the given size - * @param size the Size in Px - * @return template that corresponds to the given size - */ - static auto GetTemplate(QSizeF size) -> PaperSizeTemplate; - - /** - * @brief PopulateComboBox Populates the given combo with the given templates - * @param tmpls list of paper size templates - * @param comboBox pointer to the combobox - */ - static void PopulateComboBox(QVector *tmpls, QComboBox* comboBox); - - /** - * @brief isRollTemplate Returns wether the given template is a roll or not. - * @param tmpl paper size template - * @return true if the given template is a roll - */ - static auto isRollTemplate(PaperSizeTemplate tmpl) -> bool; - // Sheet - - /** - * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px - * @param width sheet width - * @param height sheet height - */ - void SetSheetSize(qreal width, qreal height); - - /** - * @brief SetSheetSize sets the size of the sheet, the values have to be in the layout's unit - * @param width sheet width - * @param height sheet height - */ - void SetSheetSizeConverted(qreal width, qreal height); - - /** - * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px - * @param size sheet size - */ - void SetSheetSize(const QSizeF &size); - /** - * @brief SetSheetSizeConverted sets the size of the sheet, the values have to be in the layout's unit - * @param size sheet size - */ - void SetSheetSizeConverted(const QSizeF &size); - - /** - * @brief GetSheetSize Returns the size in Unit::Px - * @return sheet size in Unit::Px - */ - auto GetSheetSize() const -> QSizeF; - - /** - * @brief GetSheetSizeConverted Returns the size in the layout's unit - * @return the size in the layout's unit - */ - auto GetSheetSizeConverted() const -> QSizeF; - - /** - * @brief SetSheetMargins, set the margins of the sheet, 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 SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetSheetMargins, set the margins of the sheet, 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 SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); - - /** - * @brief SetSheetMargins set the margins of the sheet, the values have to be in Unit::Px - * @param margins sheet margins - */ - void SetSheetMargins(const QMarginsF &margins); - - /** - * @brief SetSheetMargins set the margins of the sheet, the values have to be in the unit of the layout - * @param margins sheet margins - */ - void SetSheetMarginsConverted(const QMarginsF &margins); - - /** - * @brief GetSheetMargins Returns the size in Unit::Px - * @return the size in Unit::Px - */ - auto GetSheetMargins() const -> QMarginsF; - - /** - * @brief GetSheetMarginsConverted Returns the margins in the layout's unit - * @return the margins in the sheet's unit - */ - auto GetSheetMarginsConverted() const -> QMarginsF; - /** * @brief GetShowGrid Returns true if the placement grid has to be shown on the current sheet * @return true if the placement grid has to be shown on the current sheet @@ -433,9 +298,6 @@ public: auto IgnoreTilesMargins() const -> bool; void SetIgnoreTilesMargins(bool newIgnoreTilesMargins); - auto IgnoreMargins() const -> bool; - void SetIgnoreMargins(bool newIgnoreMargins); - private: Unit m_unit{Unit::Cm}; @@ -450,11 +312,6 @@ private: */ 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 @@ -465,19 +322,6 @@ private: bool m_showTiles{false}; - /** - * @brief m_size the Size in Unit::Px - */ - QSizeF m_size{}; - - // margins - /** - * @brief m_margins the margins in Unit::Px - */ - QMarginsF m_margins{}; - - bool m_ignoreMargins{false}; - // control bool m_followGrainLine{false}; diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index a30a4bf94..f6f5b90ee 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -216,7 +216,7 @@ void VPPiece::RotateToGrainline(const VPTransformationOrigon &origin) QLineF canonical(grainlinePoints.first().x(), grainlinePoints.first().y(), grainlinePoints.first().x()+100, grainlinePoints.first().y()); - GrainlineType grainlineType = sheet->GrainlineType(); + GrainlineType grainlineType = sheet->GrainlineOrientation(); auto DegreesAtFront = [grainline, canonical, grainlineType]() { diff --git a/src/app/puzzle/layout/vpsheet.cpp b/src/app/puzzle/layout/vpsheet.cpp index a07911516..5bae67f3b 100644 --- a/src/app/puzzle/layout/vpsheet.cpp +++ b/src/app/puzzle/layout/vpsheet.cpp @@ -29,12 +29,18 @@ #include "vplayout.h" #include "vppiece.h" +#include "../vpapplication.h" //--------------------------------------------------------------------------------------------------------------------- VPSheet::VPSheet(const VPLayoutPtr &layout) : m_layout(layout) { SCASSERT(layout != nullptr) + + VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); + SetIgnoreMargins(settings->GetLayoutSheetIgnoreMargins()); + SetSheetMargins(settings->GetLayoutSheetMargins()); + SetSheetSize(QSizeF(settings->GetLayoutSheetPaperWidth(), settings->GetLayoutSheetPaperHeight())); } //--------------------------------------------------------------------------------------------------------------------- @@ -111,19 +117,31 @@ void VPSheet::SetVisible(bool visible) } //--------------------------------------------------------------------------------------------------------------------- -auto VPSheet::GrainlineType() const -> enum GrainlineType +GrainlineType VPSheet::GrainlineOrientation() const { - VPLayoutPtr layout = GetLayout(); - if (not layout.isNull()) + if (m_grainlineType == GrainlineType::NotFixed) { - QSizeF size = layout->LayoutSettings().GetSheetSize(); - if (size.height() < size.width()) + if (m_size.height() < m_size.width()) { return GrainlineType::Horizontal; } + + return GrainlineType::Vertical; } - return GrainlineType::Vertical; + return m_grainlineType; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSheet::GetGrainlineType() const -> GrainlineType +{ + return m_grainlineType; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetGrainlineType(GrainlineType type) +{ + m_grainlineType = type; } //--------------------------------------------------------------------------------------------------------------------- @@ -244,48 +262,77 @@ void VPSheet::ValidatePiecesOutOfBound() const //--------------------------------------------------------------------------------------------------------------------- auto VPSheet::GetSheetRect() const -> QRectF { - return GetSheetRect(GetLayout()); + return QRectF(QPoint(0, 0), m_size); } //--------------------------------------------------------------------------------------------------------------------- auto VPSheet::GetMarginsRect() const -> QRectF { - return GetMarginsRect(GetLayout()); -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPSheet::GetSheetRect(const VPLayoutPtr &layout) -> QRectF -{ - if (layout.isNull()) + if (not m_ignoreMargins) { - return {}; - } - - QPoint topLeft = QPoint(0,0); - QSizeF size = layout->LayoutSettings().GetSheetSize(); - QRectF rect = QRectF(topLeft, size); - return rect; -} - -//--------------------------------------------------------------------------------------------------------------------- -auto VPSheet::GetMarginsRect(const VPLayoutPtr &layout) -> QRectF -{ - if (layout.isNull()) - { - return {}; - } - - QSizeF size = layout->LayoutSettings().GetSheetSize(); - - if (not layout->LayoutSettings().IgnoreMargins()) - { - QMarginsF margins = layout->LayoutSettings().GetSheetMargins(); - QRectF rect = QRectF(QPointF(margins.left(), margins.top()), - QPointF(size.width()-margins.right(), size.height()-margins.bottom())); + QRectF rect = QRectF(QPointF(m_margins.left(), m_margins.top()), + QPointF(m_size.width() - m_margins.right(), m_size.height() - m_margins.bottom())); return rect; } - return QRectF(0, 0, size.width(), size.height()); + return QRectF(0, 0, m_size.width(), m_size.height()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::RemoveUnusedLength() +{ + VPLayoutPtr layout = GetLayout(); + if (layout.isNull()) + { + return; + } + + QList pieces = GetPieces(); + if (pieces.isEmpty()) + { + return; + } + + QRectF piecesBoundingRect; + + for (const auto& piece : pieces) + { + if (not piece.isNull()) + { + piecesBoundingRect = piecesBoundingRect.united(piece->MappedDetailBoundingRect()); + } + } + + const qreal extra = 2; + QRectF sheetRect = GetSheetRect(); + GrainlineType type = GrainlineOrientation(); + + if (type == GrainlineType::Vertical) + { + qreal margin = 0; + if (not m_ignoreMargins) + { + margin = m_margins.bottom(); + } + + if (sheetRect.bottomRight().y() - margin > piecesBoundingRect.bottomRight().y()) + { + m_size = QSizeF(m_size.width(), piecesBoundingRect.bottomRight().y() + margin + extra); + } + } + else if (type == GrainlineType::Horizontal) + { + qreal margin = 0; + if (not m_ignoreMargins) + { + margin = m_margins.right(); + } + + if (sheetRect.topRight().x() - margin > piecesBoundingRect.topRight().x()) + { + m_size = QSizeF(piecesBoundingRect.topRight().x() + margin + extra, m_size.height()); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -313,3 +360,118 @@ void VPSheet::CheckPiecePositionValidity(const VPPiecePtr &piece) const ValidateSuperpositionOfPieces(); } } + +//--------------------------------------------------------------------------------------------------------------------- +Unit VPSheet::SheetUnits() const +{ + VPLayoutPtr layout = GetLayout(); + if (not layout.isNull()) + { + return layout->LayoutSettings().GetUnit(); + } + + return Unit::Cm; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSize(qreal width, qreal height) +{ + m_size.setWidth(width); + m_size.setHeight(height); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSizeConverted(qreal width, qreal height) +{ + Unit unit = SheetUnits(); + m_size.setWidth(UnitConvertor(width, unit, Unit::Px)); + m_size.setHeight(UnitConvertor(height, unit, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSize(const QSizeF &size) +{ + m_size = size; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetSizeConverted(const QSizeF &size) +{ + Unit unit = SheetUnits(); + m_size = QSizeF(UnitConvertor(size.width(), unit, Unit::Px), + UnitConvertor(size.height(), unit, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSheet::GetSheetSize() const -> QSizeF +{ + return m_size; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSheet::GetSheetSizeConverted() const -> QSizeF +{ + Unit unit = SheetUnits(); + QSizeF convertedSize = QSizeF( + UnitConvertor(m_size.width(), Unit::Px, unit), + UnitConvertor(m_size.height(), Unit::Px, unit) + ); + + return convertedSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom) +{ + m_margins.setLeft(left); + m_margins.setTop(top); + m_margins.setRight(right); + m_margins.setBottom(bottom); +} +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom) +{ + Unit unit = SheetUnits(); + m_margins.setLeft(UnitConvertor(left, unit, Unit::Px)); + m_margins.setTop(UnitConvertor(top, unit, Unit::Px)); + m_margins.setRight(UnitConvertor(right, unit, Unit::Px)); + m_margins.setBottom(UnitConvertor(bottom, unit, Unit::Px)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMargins(const QMarginsF &margins) +{ + m_margins = margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetSheetMarginsConverted(const QMarginsF &margins) +{ + Unit unit = SheetUnits(); + m_margins = UnitConvertor(margins, unit, Unit::Px); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSheet::GetSheetMargins() const -> QMarginsF +{ + return m_margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSheet::GetSheetMarginsConverted() const -> QMarginsF +{ + Unit unit = SheetUnits(); + return UnitConvertor(m_margins, Unit::Px, unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPSheet::IgnoreMargins() const -> bool +{ + return m_ignoreMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPSheet::SetIgnoreMargins(bool newIgnoreMargins) +{ + m_ignoreMargins = newIgnoreMargins; +} diff --git a/src/app/puzzle/layout/vpsheet.h b/src/app/puzzle/layout/vpsheet.h index febd396c7..ea8246e9d 100644 --- a/src/app/puzzle/layout/vpsheet.h +++ b/src/app/puzzle/layout/vpsheet.h @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ ** ** @file vpsheet.h ** @author Ronan Le Tiec @@ -75,7 +75,9 @@ public: bool IsVisible() const; void SetVisible(bool visible); - auto GrainlineType() const -> GrainlineType; + auto GrainlineOrientation() const -> GrainlineType; + auto GetGrainlineType() const -> GrainlineType; + void SetGrainlineType(GrainlineType type); auto TransformationOrigin() const -> const VPTransformationOrigon &; void SetTransformationOrigin(const VPTransformationOrigon &newTransformationOrigin); @@ -92,8 +94,89 @@ public: auto GetSheetRect() const -> QRectF; auto GetMarginsRect() const -> QRectF; - static auto GetSheetRect(const VPLayoutPtr &layout) -> QRectF; - static auto GetMarginsRect(const VPLayoutPtr &layout) -> QRectF; + void RemoveUnusedLength(); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px + * @param width sheet width + * @param height sheet height + */ + void SetSheetSize(qreal width, qreal height); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in the layout's unit + * @param width sheet width + * @param height sheet height + */ + void SetSheetSizeConverted(qreal width, qreal height); + + /** + * @brief SetSheetSize sets the size of the sheet, the values have to be in Unit::Px + * @param size sheet size + */ + void SetSheetSize(const QSizeF &size); + /** + * @brief SetSheetSizeConverted sets the size of the sheet, the values have to be in the layout's unit + * @param size sheet size + */ + void SetSheetSizeConverted(const QSizeF &size); + + /** + * @brief GetSheetSize Returns the size in Unit::Px + * @return sheet size in Unit::Px + */ + auto GetSheetSize() const -> QSizeF; + + /** + * @brief GetSheetSizeConverted Returns the size in the layout's unit + * @return the size in the layout's unit + */ + auto GetSheetSizeConverted() const -> QSizeF; + + /** + * @brief SetSheetMargins, set the margins of the sheet, 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 SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins, set the margins of the sheet, 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 SetSheetMarginsConverted(qreal left, qreal top, qreal right, qreal bottom); + + /** + * @brief SetSheetMargins set the margins of the sheet, the values have to be in Unit::Px + * @param margins sheet margins + */ + void SetSheetMargins(const QMarginsF &margins); + + /** + * @brief SetSheetMargins set the margins of the sheet, the values have to be in the unit of the layout + * @param margins sheet margins + */ + void SetSheetMarginsConverted(const QMarginsF &margins); + + /** + * @brief GetSheetMargins Returns the size in Unit::Px + * @return the size in Unit::Px + */ + auto GetSheetMargins() const -> QMarginsF; + + /** + * @brief GetSheetMarginsConverted Returns the margins in the layout's unit + * @return the margins in the sheet's unit + */ + auto GetSheetMarginsConverted() const -> QMarginsF; + + auto IgnoreMargins() const -> bool; + void SetIgnoreMargins(bool newIgnoreMargins); public slots: void CheckPiecePositionValidity(const VPPiecePtr &piece) const; @@ -112,6 +195,22 @@ private: VPTransformationOrigon m_transformationOrigin{}; + /** + * @brief m_size the Size in Unit::Px + */ + QSizeF m_size{}; + + // margins + /** + * @brief m_margins the margins in Unit::Px + */ + QMarginsF m_margins{}; + + bool m_ignoreMargins{false}; + + GrainlineType m_grainlineType{GrainlineType::NotFixed}; + + auto SheetUnits() const -> Unit; }; diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index d2a4b800d..33865dd6e 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -7,6 +7,7 @@ SOURCES += \ $$PWD/dialogs/configpages/puzzlepreferenceslayoutpage.cpp \ $$PWD/dialogs/dialogpuzzlepreferences.cpp \ $$PWD/dialogs/vpdialogabout.cpp \ + $$PWD/layout/layoutdef.cpp \ $$PWD/main.cpp \ $$PWD/undocommands/vpundoaddsheet.cpp \ $$PWD/undocommands/vpundocommand.cpp \ diff --git a/src/app/puzzle/scene/vpgraphicssheet.cpp b/src/app/puzzle/scene/vpgraphicssheet.cpp index 12810f888..3335369e2 100644 --- a/src/app/puzzle/scene/vpgraphicssheet.cpp +++ b/src/app/puzzle/scene/vpgraphicssheet.cpp @@ -105,13 +105,35 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o //--------------------------------------------------------------------------------------------------------------------- auto VPGraphicsSheet::GetSheetRect() const -> QRectF { - return VPSheet::GetSheetRect(m_layout.toStrongRef()); + VPLayoutPtr layout = m_layout.toStrongRef(); + if (layout.isNull()) + { + return {}; + } + + VPSheetPtr sheet = layout->GetFocusedSheet(); + if (sheet.isNull()) + { + return {}; + } + return sheet->GetSheetRect(); } //--------------------------------------------------------------------------------------------------------------------- auto VPGraphicsSheet::GetMarginsRect() const -> QRectF { - return VPSheet::GetMarginsRect(m_layout.toStrongRef()); + VPLayoutPtr layout = m_layout.toStrongRef(); + if (layout.isNull()) + { + return {}; + } + + VPSheetPtr sheet = layout->GetFocusedSheet(); + if (sheet.isNull()) + { + return {}; + } + return sheet->GetMarginsRect(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/share/resources/puzzleicon.qrc b/src/app/puzzle/share/resources/puzzleicon.qrc index 6c117d3fe..b99ed6215 100644 --- a/src/app/puzzle/share/resources/puzzleicon.qrc +++ b/src/app/puzzle/share/resources/puzzleicon.qrc @@ -16,5 +16,9 @@ puzzleicon/svg/icon_rotate_90_clockwise.svg puzzleicon/svg/icon_rotate_grainline_horizontal.svg puzzleicon/svg/icon_rotate_grainline_vertical.svg + puzzleicon/32X32/horizontal_grainline.png + puzzleicon/32X32/horizontal_grainline@2x.png + puzzleicon/32X32/vertical_grainline.png + puzzleicon/32X32/vertical_grainline@2x.png diff --git a/src/app/puzzle/share/resources/puzzleicon/32X32/horizontal_grainline.png b/src/app/puzzle/share/resources/puzzleicon/32X32/horizontal_grainline.png new file mode 100644 index 000000000..09e0e5ddc Binary files /dev/null and b/src/app/puzzle/share/resources/puzzleicon/32X32/horizontal_grainline.png differ diff --git a/src/app/puzzle/share/resources/puzzleicon/32X32/horizontal_grainline@2x.png b/src/app/puzzle/share/resources/puzzleicon/32X32/horizontal_grainline@2x.png new file mode 100644 index 000000000..4957393e3 Binary files /dev/null and b/src/app/puzzle/share/resources/puzzleicon/32X32/horizontal_grainline@2x.png differ diff --git a/src/app/puzzle/share/resources/puzzleicon/32X32/vertical_grainline.png b/src/app/puzzle/share/resources/puzzleicon/32X32/vertical_grainline.png new file mode 100644 index 000000000..f332842f6 Binary files /dev/null and b/src/app/puzzle/share/resources/puzzleicon/32X32/vertical_grainline.png differ diff --git a/src/app/puzzle/share/resources/puzzleicon/32X32/vertical_grainline@2x.png b/src/app/puzzle/share/resources/puzzleicon/32X32/vertical_grainline@2x.png new file mode 100644 index 000000000..ccfd215a4 Binary files /dev/null and b/src/app/puzzle/share/resources/puzzleicon/32X32/vertical_grainline@2x.png differ diff --git a/src/app/puzzle/vpexporter.cpp b/src/app/puzzle/vpexporter.cpp index 9a886bb12..f9d2b20ca 100644 --- a/src/app/puzzle/vpexporter.cpp +++ b/src/app/puzzle/vpexporter.cpp @@ -43,7 +43,7 @@ void VPExporter::Export(VPLayout* layout, LayoutExportFormats format, VPMainGrap SetFileName(fileName); - QSizeF size = QSizeF(layout->GetFocusedSheet()->GetLayout()->LayoutSettings().GetSheetSize()); + QSizeF size = QSizeF(layout->GetFocusedSheet()->GetSheetSize()); const QRectF rect = QRectF(0, 0, size.width(), size.height()); SetImageRect(rect); diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 8e1290d16..45dddf4a0 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -139,6 +139,12 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : { SetPropertyTabCurrentPieceData(); }); + connect(m_layout.get(), &VPLayout::ActiveSheetChanged, this, [this]() + { + m_tileFactory->refreshTileInfos(); + m_graphicsView->RefreshLayout(); + SetPropertyTabSheetData(); + }); connect(m_undoStack, &QUndoStack::cleanChanged, this, [this](bool clean) { @@ -393,6 +399,7 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) } m_carrousel->Refresh(); + m_layout->CheckPiecesPositionValidity(); LayoutWasSaved(false); } else @@ -665,6 +672,67 @@ void VPMainWindow::InitPropertyTabCurrentSheet() connect(ui->toolButtonSheetLandscapeOrientation, &QToolButton::toggled, this, &VPMainWindow::on_SheetOrientationChanged); + connect(ui->toolButtonGrainlineHorizontalOrientation, &QToolButton::clicked, this, [this](bool checked) + { + VPSheetPtr sheet = m_layout->GetFocusedSheet(); + if (sheet.isNull()) + { + return; + } + + if (checked) + { + sheet->SetGrainlineType(GrainlineType::Horizontal); + ui->toolButtonGrainlineVerticalOrientation->setChecked(false); + } + else + { + sheet->SetGrainlineType(GrainlineType::NotFixed); + } + + RotatePiecesToGrainline(); + LayoutWasSaved(false); + }); + + connect(ui->toolButtonGrainlineVerticalOrientation, &QToolButton::clicked, this, [this](bool checked) + { + VPSheetPtr sheet = m_layout->GetFocusedSheet(); + if (sheet.isNull()) + { + return; + } + + if (checked) + { + sheet->SetGrainlineType(GrainlineType::Vertical); + ui->toolButtonGrainlineHorizontalOrientation->setChecked(false); + } + else + { + sheet->SetGrainlineType(GrainlineType::NotFixed); + } + + RotatePiecesToGrainline(); + LayoutWasSaved(false); + }); + + connect(ui->pushButtonSheetRemoveUnusedLength, &QPushButton::clicked, this, [this]() + { + if (not m_layout.isNull()) + { + VPSheetPtr sheet = m_layout->GetFocusedSheet(); + if (not sheet.isNull()) + { + sheet->RemoveUnusedLength(); + LayoutWasSaved(false); + m_tileFactory->refreshTileInfos(); + m_graphicsView->RefreshLayout(); + m_graphicsView->RefreshPieces(); + SetPropertyTabSheetData(); + } + } + }); + // -------------------- margins ------------------------ ui->doubleSpinBoxSheetMarginLeft->setSuffix(suffix); ui->doubleSpinBoxSheetMarginRight->setSuffix(suffix); @@ -689,14 +757,14 @@ void VPMainWindow::InitPropertyTabCurrentSheet() ui->doubleSpinBoxSheetMarginTop->setDisabled(state != 0); ui->doubleSpinBoxSheetMarginBottom->setDisabled(state != 0); - m_layout->LayoutSettings().SetIgnoreMargins(state != 0); - LayoutWasSaved(false); - m_tileFactory->refreshTileInfos(); - m_graphicsView->RefreshLayout(); - VPSheetPtr sheet = m_layout->GetFocusedSheet(); if (not sheet.isNull()) { + sheet->SetIgnoreMargins(state != 0); + LayoutWasSaved(false); + m_tileFactory->refreshTileInfos(); + m_graphicsView->RefreshLayout(); + sheet->ValidatePiecesOutOfBound(); } } @@ -972,106 +1040,114 @@ void VPMainWindow::SetPropertyTabSheetData() { if (not m_layout.isNull()) { - ui->groupBoxSheetInfos->setDisabled(false); VPSheetPtr sheet = m_layout->GetFocusedSheet(); - SetLineEditValue(ui->lineEditSheetName, not sheet.isNull() ? sheet->GetName() : QString()); - - ui->groupBoxPaperFormat->setDisabled(false); - const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(UnitsToStr(m_layout->LayoutSettings().GetUnit())); - if (indexUnit != -1) + if (not sheet.isNull()) { - ui->comboBoxLayoutUnit->blockSignals(true); - ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); - ui->comboBoxLayoutUnit->blockSignals(false); + ui->groupBoxSheetInfos->setDisabled(false); + VPSheetPtr sheet = m_layout->GetFocusedSheet(); + SetLineEditValue(ui->lineEditSheetName, not sheet.isNull() ? sheet->GetName() : QString()); + + ui->groupBoxPaperFormat->setDisabled(false); + const qint32 indexUnit = ui->comboBoxLayoutUnit->findData(UnitsToStr(m_layout->LayoutSettings().GetUnit())); + if (indexUnit != -1) + { + ui->comboBoxLayoutUnit->blockSignals(true); + ui->comboBoxLayoutUnit->setCurrentIndex(indexUnit); + ui->comboBoxLayoutUnit->blockSignals(false); + } + else + { + ui->comboBoxLayoutUnit->setCurrentIndex(0); + } + + const QString suffix = " " + UnitsToStr(LayoutUnit(), true); + + ui->doubleSpinBoxSheetPaperWidth->setSuffix(suffix); + ui->doubleSpinBoxSheetPaperHeight->setSuffix(suffix); + + ui->doubleSpinBoxSheetMarginLeft->setSuffix(suffix); + ui->doubleSpinBoxSheetMarginRight->setSuffix(suffix); + ui->doubleSpinBoxSheetMarginTop->setSuffix(suffix); + ui->doubleSpinBoxSheetMarginBottom->setSuffix(suffix); + + // set Width / Length + QSizeF size = sheet->GetSheetSizeConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperWidth, size.width()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperHeight, size.height()); + + SheetPaperSizeChanged(); + FindSheetTemplate(); + + // set margins + ui->groupBoxSheetMargin->setDisabled(false); + QMarginsF margins = sheet->GetSheetMarginsConverted(); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginLeft, margins.left()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginTop, margins.top()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginRight, margins.right()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginBottom, margins.bottom()); + + CorrectSheetMaxMargins(); + + const bool ignoreMargins = sheet->IgnoreMargins(); + SetCheckBoxValue(ui->checkBoxLayoutIgnoreFileds, ignoreMargins); + + ui->doubleSpinBoxSheetMarginLeft->setDisabled(ignoreMargins); + ui->doubleSpinBoxSheetMarginRight->setDisabled(ignoreMargins); + ui->doubleSpinBoxSheetMarginTop->setDisabled(ignoreMargins); + ui->doubleSpinBoxSheetMarginBottom->setDisabled(ignoreMargins); + + GrainlineType type = sheet->GetGrainlineType(); + ui->toolButtonGrainlineHorizontalOrientation->setChecked(type == GrainlineType::Horizontal); + ui->toolButtonGrainlineVerticalOrientation->setChecked(type == GrainlineType::Vertical); + + // set placement grid + ui->groupBoxSheetGrid->setDisabled(false); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridColWidth, + m_layout->LayoutSettings().GetGridColWidthConverted()); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridRowHeight, + m_layout->LayoutSettings().GetGridRowHeightConverted()); + + SetCheckBoxValue(ui->checkBoxSheetShowGrid, m_layout->LayoutSettings().GetShowGrid()); + + ui->groupBoxSheetExport->setDisabled(false); + + return; } - else - { - ui->comboBoxLayoutUnit->setCurrentIndex(0); - } - - const QString suffix = " " + UnitsToStr(LayoutUnit(), true); - - ui->doubleSpinBoxSheetPaperWidth->setSuffix(suffix); - ui->doubleSpinBoxSheetPaperHeight->setSuffix(suffix); - - ui->doubleSpinBoxSheetMarginLeft->setSuffix(suffix); - ui->doubleSpinBoxSheetMarginRight->setSuffix(suffix); - ui->doubleSpinBoxSheetMarginTop->setSuffix(suffix); - ui->doubleSpinBoxSheetMarginBottom->setSuffix(suffix); - - // set Width / Length - QSizeF size = m_layout->LayoutSettings().GetSheetSizeConverted(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperWidth, size.width()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperHeight, size.height()); - - SheetPaperSizeChanged(); - FindSheetTemplate(); - - // set margins - ui->groupBoxSheetMargin->setDisabled(false); - QMarginsF margins = m_layout->LayoutSettings().GetSheetMarginsConverted(); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginLeft, margins.left()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginTop, margins.top()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginRight, margins.right()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginBottom, margins.bottom()); - - CorrectSheetMaxMargins(); - - const bool ignoreMargins = m_layout->LayoutSettings().IgnoreMargins(); - SetCheckBoxValue(ui->checkBoxLayoutIgnoreFileds, ignoreMargins); - - ui->doubleSpinBoxSheetMarginLeft->setDisabled(ignoreMargins); - ui->doubleSpinBoxSheetMarginRight->setDisabled(ignoreMargins); - ui->doubleSpinBoxSheetMarginTop->setDisabled(ignoreMargins); - ui->doubleSpinBoxSheetMarginBottom->setDisabled(ignoreMargins); - - // set placement grid - ui->groupBoxSheetGrid->setDisabled(false); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridColWidth, - m_layout->LayoutSettings().GetGridColWidthConverted()); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridRowHeight, - m_layout->LayoutSettings().GetGridRowHeightConverted()); - - SetCheckBoxValue(ui->checkBoxSheetShowGrid, m_layout->LayoutSettings().GetShowGrid()); - - ui->groupBoxSheetExport->setDisabled(false); } - else - { - ui->groupBoxSheetInfos->setDisabled(true); - SetLineEditValue(ui->lineEditSheetName, QString()); - ui->groupBoxPaperFormat->setDisabled(true); + ui->groupBoxSheetInfos->setDisabled(true); + SetLineEditValue(ui->lineEditSheetName, QString()); - ui->comboBoxLayoutUnit->blockSignals(true); - ui->comboBoxLayoutUnit->setCurrentIndex(-1); - ui->comboBoxLayoutUnit->blockSignals(false); + ui->groupBoxPaperFormat->setDisabled(true); - ui->comboBoxSheetTemplates->blockSignals(true); - ui->comboBoxSheetTemplates->setCurrentIndex(-1); - ui->comboBoxSheetTemplates->blockSignals(false); + ui->comboBoxLayoutUnit->blockSignals(true); + ui->comboBoxLayoutUnit->setCurrentIndex(-1); + ui->comboBoxLayoutUnit->blockSignals(false); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperWidth, 0); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperHeight, 0); + ui->comboBoxSheetTemplates->blockSignals(true); + ui->comboBoxSheetTemplates->setCurrentIndex(-1); + ui->comboBoxSheetTemplates->blockSignals(false); - ui->groupBoxSheetMargin->setDisabled(true); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperWidth, 0); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperHeight, 0); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginLeft, 0); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginTop, 0); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginRight, 0); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginBottom, 0); + ui->groupBoxSheetMargin->setDisabled(true); - SetCheckBoxValue(ui->checkBoxLayoutIgnoreFileds, false); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginLeft, 0); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginTop, 0); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginRight, 0); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetMarginBottom, 0); - ui->groupBoxSheetGrid->setDisabled(true); + SetCheckBoxValue(ui->checkBoxLayoutIgnoreFileds, false); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridColWidth, 0); - SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridRowHeight, 0); + ui->groupBoxSheetGrid->setDisabled(true); - SetCheckBoxValue(ui->checkBoxSheetShowGrid, false); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridColWidth, 0); + SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetGridRowHeight, 0); - ui->groupBoxSheetExport->setDisabled(true); - } + SetCheckBoxValue(ui->checkBoxSheetShowGrid, false); + + ui->groupBoxSheetExport->setDisabled(true); } //--------------------------------------------------------------------------------------------------------------------- @@ -1874,6 +1950,11 @@ void VPMainWindow::CorrectMaxMargins() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::RotatePiecesToGrainline() { + if (not m_layout->LayoutSettings().GetFollowGrainline()) + { + return; + } + QList sheets = m_layout->GetSheets(); for(const auto& sheet : sheets) { @@ -2163,9 +2244,13 @@ void VPMainWindow::on_SheetSizeChanged() { if (not m_layout.isNull()) { - m_layout->LayoutSettings().SetSheetSizeConverted( - ui->doubleSpinBoxSheetPaperWidth->value(), - ui->doubleSpinBoxSheetPaperHeight->value()); + VPSheetPtr sheet = m_layout->GetFocusedSheet(); + if (not sheet.isNull()) + { + sheet->SetSheetSizeConverted(ui->doubleSpinBoxSheetPaperWidth->value(), + ui->doubleSpinBoxSheetPaperHeight->value()); + } + FindSheetTemplate(); SheetPaperSizeChanged(); CorrectMaxMargins(); @@ -2187,7 +2272,11 @@ void VPMainWindow::on_SheetOrientationChanged(bool checked) SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperWidth, height); SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetPaperHeight, width); - m_layout->LayoutSettings().SetSheetSizeConverted(height, width); + VPSheetPtr sheet = m_layout->GetFocusedSheet(); + if (not sheet.isNull()) + { + sheet->SetSheetSizeConverted(height, width); + } SheetPaperSizeChanged(); CorrectMaxMargins(); @@ -2197,36 +2286,21 @@ void VPMainWindow::on_SheetOrientationChanged(bool checked) } } -//--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::on_pushButtonSheetRemoveUnusedLength_clicked() -{ - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO VPMainWindow::on_pushButtonSheetRemoveUnusedLength_clicked"); - int ret = msgBox.exec(); - - Q_UNUSED(ret); - - // TODO -} - - //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_SheetMarginChanged() { if (not m_layout.isNull()) { - m_layout->LayoutSettings().SetSheetMarginsConverted( - ui->doubleSpinBoxSheetMarginLeft->value(), - ui->doubleSpinBoxSheetMarginTop->value(), - ui->doubleSpinBoxSheetMarginRight->value(), - ui->doubleSpinBoxSheetMarginBottom->value()); - - LayoutWasSaved(false); - VPSheetPtr sheet = m_layout->GetFocusedSheet(); if (not sheet.isNull()) { + sheet->SetSheetMarginsConverted(ui->doubleSpinBoxSheetMarginLeft->value(), + ui->doubleSpinBoxSheetMarginTop->value(), + ui->doubleSpinBoxSheetMarginRight->value(), + ui->doubleSpinBoxSheetMarginBottom->value()); + + LayoutWasSaved(false); + sheet->ValidatePiecesOutOfBound(); } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index d1f29de1e..7340c8557 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -174,13 +174,6 @@ private slots: */ void on_SheetOrientationChanged(bool checked); - /** - * @brief on_pushButtonLayoutRemoveUnusedLength_clicked When the button - * "Remove unused length" in the sheet property tab is clicked. - * The slot is automatically connected through name convention. - */ - void on_pushButtonSheetRemoveUnusedLength_clicked(); - /** * @brief on_SheetMarginChanged When one of the margin values has been changed * in the sheet property tab. diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 9255cdd16..790ed2f94 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -189,7 +189,7 @@ QTabWidget::Rounded - 0 + 1 @@ -249,7 +249,7 @@ 0 0 - 358 + 392 700 @@ -686,8 +686,8 @@ 0 0 - 344 - 748 + 378 + 829 @@ -787,6 +787,51 @@ + + + + + 94 + 0 + + + + 2 + + + 99999.000000000000000 + + + + + + + + 94 + 0 + + + + 2 + + + 99999.990000000005239 + + + + + + + + 0 + 0 + + + + Length: + + + @@ -850,50 +895,82 @@ - - - - - 0 - 0 - - + + + + + + - Length: + Grainline orientation: + + + true - - - - - 94 - 0 - - - - 2 - - - 99999.000000000000000 - - - - - - - - 94 - 0 - - - - 2 - - - 99999.990000000005239 - - + + + + + + Force the grainline orientation to always be horizontal + + + ... + + + + :/puzzleicon/32X32/horizontal_grainline.png:/puzzleicon/32X32/horizontal_grainline.png + + + + 24 + 24 + + + + true + + + + + + + Force the grainline orientation to always be vertical + + + ... + + + + :/puzzleicon/32X32/vertical_grainline.png:/puzzleicon/32X32/vertical_grainline.png + + + + 24 + 24 + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -1133,7 +1210,7 @@ 0 0 - 358 + 392 700 @@ -1505,7 +1582,7 @@ 0 0 - 358 + 392 700 diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 452f13592..c3323b3f7 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -49,7 +49,12 @@ void VPTileFactory::refreshTileInfos() m_drawingAreaWidth += m_infoStripeWidth; } - QSizeF sheetSize = layout->LayoutSettings().GetSheetSize(); + QSizeF sheetSize; + VPSheetPtr sheet = layout->GetFocusedSheet(); + if (not sheet.isNull()) + { + sheetSize = sheet->GetSheetSize(); + } m_nbCol = qCeil(sheetSize.width()/m_drawingAreaWidth); m_nbRow = qCeil(sheetSize.height()/m_drawingAreaHeight); } diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 75f50fd7f..55a2c2b4d 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -241,10 +241,8 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout) ML::TagUnit, // 0 ML::TagTitle, // 1 ML::TagDescription, // 2 - ML::TagSize, // 3 - ML::TagMargin, // 4 - ML::TagControl, // 5 - ML::TagTiles // 6 + ML::TagControl, // 3 + ML::TagTiles // 4 }; while (readNextStartElement()) @@ -265,17 +263,11 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout) qDebug("read description"); layout->LayoutSettings().SetDescription(readElementText()); break; - case 3: // size - layout->LayoutSettings().SetSheetSize(ReadSize()); - break; - case 4: // margin - layout->LayoutSettings().SetSheetMargins(ReadMargins()); - break; - case 5: // control + case 3: // control qDebug("read control"); ReadControl(layout); break; - case 6: // tiles + case 4: // tiles qDebug("read tiles"); ReadTiles(layout); break; @@ -370,14 +362,19 @@ void VPLayoutFileReader::ReadSheet(const VPLayoutPtr &layout) { AssertRootTag(ML::TagSheet); + VPSheetPtr sheet(new VPSheet(layout)); + + QXmlStreamAttributes attribs = attributes(); + sheet->SetGrainlineType(StrToGrainlineType(ReadAttributeEmptyString(attribs, ML::AttrGrainlineType))); + const QStringList tags { ML::TagName, // 0 - ML::TagPieces // 1 + ML::TagSize, // 1 + ML::TagMargin, // 2 + ML::TagPieces // 3 }; - VPSheetPtr sheet(new VPSheet(layout)); - while (readNextStartElement()) { switch (tags.indexOf(name().toString())) @@ -385,7 +382,13 @@ void VPLayoutFileReader::ReadSheet(const VPLayoutPtr &layout) case 0: // name sheet->SetName(readElementText()); break; - case 1: // pieces + case 1: // size + sheet->SetSheetSize(ReadSize()); + break; + case 2: // margin + sheet->SetSheetMargins(ReadMargins()); + break; + case 3: // pieces ReadPieces(layout, sheet); break; default: diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 2588e7336..2d0666b04 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -154,22 +154,20 @@ void VPLayoutFileWriter::WriteLayout(const VPLayoutPtr &layout) { writeStartElement(ML::TagLayout); SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr); - WriteProperties(layout); + WriteLayoutProperties(layout); WritePieceList(layout->GetUnplacedPieces(), ML::TagUnplacedPieces); WriteSheets(layout); writeEndElement(); //layout } //--------------------------------------------------------------------------------------------------------------------- -void VPLayoutFileWriter::WriteProperties(const VPLayoutPtr &layout) +void VPLayoutFileWriter::WriteLayoutProperties(const VPLayoutPtr &layout) { writeStartElement(ML::TagProperties); writeTextElement(ML::TagUnit, UnitsToStr(layout->LayoutSettings().GetUnit())); writeTextElement(ML::TagTitle, layout->LayoutSettings().GetTitle()); writeTextElement(ML::TagDescription, layout->LayoutSettings().GetDescription()); - WriteSize(layout->LayoutSettings().GetSheetSize()); - WriteMargins(layout->LayoutSettings().GetSheetMargins()); writeStartElement(ML::TagControl); SetAttribute(ML::AttrWarningSuperposition, layout->LayoutSettings().GetWarningSuperpositionOfPieces()); @@ -205,8 +203,13 @@ void VPLayoutFileWriter::WriteSheets(const VPLayoutPtr &layout) void VPLayoutFileWriter::WriteSheet(const VPSheetPtr &sheet) { writeStartElement(ML::TagSheet); + SetAttributeOrRemoveIf(ML::AttrGrainlineType, GrainlineTypeToStr(sheet->GetGrainlineType()), + [](const QString &type) + {return type == GrainlineTypeToStr(GrainlineType::NotFixed);}); writeTextElement(ML::TagName, sheet->GetName()); + WriteSize(sheet->GetSheetSize()); + WriteMargins(sheet->GetSheetMargins()); WritePieceList(sheet->GetPieces(), ML::TagPieces); writeEndElement(); // sheet diff --git a/src/app/puzzle/xml/vplayoutfilewriter.h b/src/app/puzzle/xml/vplayoutfilewriter.h index 415b0da7e..6a327f28a 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.h +++ b/src/app/puzzle/xml/vplayoutfilewriter.h @@ -56,7 +56,7 @@ public: private: void WriteLayout(const VPLayoutPtr &layout); - void WriteProperties(const VPLayoutPtr &layout); + void WriteLayoutProperties(const VPLayoutPtr &layout); void WriteSheets(const VPLayoutPtr &layout); void WriteSheet(const VPSheetPtr &sheet); void WriteTiles(const VPLayoutPtr &layout); diff --git a/src/app/puzzle/xml/vplayoutliterals.cpp b/src/app/puzzle/xml/vplayoutliterals.cpp index b3445238c..bb182e4b5 100644 --- a/src/app/puzzle/xml/vplayoutliterals.cpp +++ b/src/app/puzzle/xml/vplayoutliterals.cpp @@ -97,6 +97,7 @@ const QString AttrItalic = QStringLiteral("italic"); const QString AttrAlignment = QStringLiteral("alignment"); const QString AttrGradationLabel = QStringLiteral("gradationLabel"); const QString AttrCopyNumber = QStringLiteral("copyNumber"); +const QString AttrGrainlineType = QStringLiteral("grainlineType"); const QString atFrontStr = QStringLiteral("atFront"); const QString atRearStr = QStringLiteral("atRear"); diff --git a/src/app/puzzle/xml/vplayoutliterals.h b/src/app/puzzle/xml/vplayoutliterals.h index e0eb540b6..f5cf4f6e2 100644 --- a/src/app/puzzle/xml/vplayoutliterals.h +++ b/src/app/puzzle/xml/vplayoutliterals.h @@ -102,6 +102,7 @@ extern const QString AttrItalic; extern const QString AttrAlignment; extern const QString AttrGradationLabel; extern const QString AttrCopyNumber; +extern const QString AttrGrainlineType; extern const QString atFrontStr; extern const QString atRearStr; diff --git a/src/libs/ifc/schema/layout/v0.1.0.xsd b/src/libs/ifc/schema/layout/v0.1.0.xsd index a9515c581..f907fc57a 100644 --- a/src/libs/ifc/schema/layout/v0.1.0.xsd +++ b/src/libs/ifc/schema/layout/v0.1.0.xsd @@ -8,20 +8,6 @@ - - - - - - - - - - - - - - @@ -199,6 +185,20 @@ + + + + + + + + + + + + + + @@ -336,6 +336,7 @@ + @@ -460,5 +461,12 @@ + + + + + + +