2020-04-13 18:58:16 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 15:34:11 +02:00
|
|
|
** @file vplayout.cpp
|
2020-04-13 18:58:16 +02:00
|
|
|
** @author Ronan Le Tiec
|
|
|
|
** @date 13 4, 2020
|
|
|
|
**
|
|
|
|
** @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) 2020 Valentina project
|
|
|
|
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
2020-05-23 15:34:11 +02:00
|
|
|
#include "vplayout.h"
|
2020-05-23 15:29:57 +02:00
|
|
|
#include "vppiecelist.h"
|
2020-05-23 15:42:51 +02:00
|
|
|
#include "vppiece.h"
|
2020-04-13 18:58:16 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
VPLayout::VPLayout() :
|
2020-05-23 15:29:57 +02:00
|
|
|
m_unplacedPieceList(new VPPieceList(this))
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces"));
|
2020-04-18 11:31:55 +02:00
|
|
|
|
2020-05-23 15:29:57 +02:00
|
|
|
// create a standard default piecelist:
|
|
|
|
VPPieceList *pieceList = new VPPieceList(this);
|
|
|
|
pieceList->SetName(QObject::tr("Layout"));
|
|
|
|
AddPieceList(pieceList);
|
2020-05-08 23:49:41 +02:00
|
|
|
|
2020-05-23 15:29:57 +02:00
|
|
|
// sets the default active piece list
|
|
|
|
SetFocusedPieceList();
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
VPLayout::~VPLayout()
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
qDeleteAll(m_pieceLists);
|
|
|
|
delete m_unplacedPieceList;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
VPPieceList* VPLayout::GetUnplacedPieceList()
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
return m_unplacedPieceList;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
VPPieceList* VPLayout::AddPieceList()
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
VPPieceList *newPieceList = new VPPieceList(this);
|
|
|
|
m_pieceLists.append(newPieceList);
|
|
|
|
return newPieceList;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
VPPieceList* VPLayout::AddPieceList(VPPieceList *pieceList)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
m_pieceLists.append(pieceList);
|
|
|
|
return pieceList;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
QList<VPPieceList *> VPLayout::GetPiecesLists()
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
return m_pieceLists;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 17:40:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:42:51 +02:00
|
|
|
QList<VPPiece *> VPLayout::GetSelectedPieces()
|
2020-05-05 17:40:36 +02:00
|
|
|
{
|
2020-05-23 15:42:51 +02:00
|
|
|
QList<VPPiece *> result = QList<VPPiece *>();
|
2020-05-05 17:40:36 +02:00
|
|
|
|
2020-05-23 15:29:57 +02:00
|
|
|
QList<VPPieceList *> pieceLists = m_pieceLists;
|
|
|
|
pieceLists.prepend(m_unplacedPieceList);
|
2020-05-05 17:40:36 +02:00
|
|
|
|
2020-05-23 15:29:57 +02:00
|
|
|
for (auto pieceList : pieceLists)
|
2020-05-05 17:40:36 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
for (auto piece : pieceList->GetPieces())
|
2020-05-05 17:40:36 +02:00
|
|
|
{
|
|
|
|
if(piece->GetIsSelected())
|
|
|
|
{
|
|
|
|
result.append(piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetUnit(Unit unit)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
m_unit = unit;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
Unit VPLayout::GetUnit() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
return m_unit;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutSize(qreal width, qreal height)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
m_size.setWidth(width);
|
|
|
|
m_size.setHeight(height);
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutSizeConverted(qreal width, qreal height)
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
2020-04-23 14:42:36 +02:00
|
|
|
m_size.setWidth(UnitConvertor(width, m_unit, Unit::Px));
|
|
|
|
m_size.setHeight(UnitConvertor(height, m_unit, Unit::Px));
|
2020-04-19 11:58:43 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutSize(const QSizeF &size)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
m_size = size;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutSizeConverted(const QSizeF &size)
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
|
|
|
m_size = QSizeF(
|
2020-04-23 14:42:36 +02:00
|
|
|
UnitConvertor(size.width(), m_unit, Unit::Px),
|
|
|
|
UnitConvertor(size.height(), m_unit, Unit::Px)
|
2020-04-19 11:58:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
QSizeF VPLayout::GetLayoutSize() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
return m_size;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
QSizeF VPLayout::GetLayoutSizeConverted() const
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
|
|
|
QSizeF convertedSize = QSizeF(
|
|
|
|
UnitConvertor(m_size.width(), Unit::Px, m_unit),
|
|
|
|
UnitConvertor(m_size.height(), Unit::Px, m_unit)
|
|
|
|
);
|
|
|
|
|
|
|
|
return convertedSize;
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
m_margins.setLeft(left);
|
|
|
|
m_margins.setTop(top);
|
|
|
|
m_margins.setRight(right);
|
2020-04-18 16:32:54 +02:00
|
|
|
m_margins.setBottom(bottom);
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutMarginsConverted(qreal left, qreal top, qreal right, qreal bottom)
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
2020-04-13 18:58:16 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutMargins(const QMarginsF &margins)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
m_margins = margins;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetLayoutMarginsConverted(const QMarginsF &margins)
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
|
|
|
m_margins = UnitConvertor(margins, m_unit, Unit::Px);
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
QMarginsF VPLayout::GetLayoutMargins() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
return m_margins;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
QMarginsF VPLayout::GetLayoutMarginsConverted() const
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
|
|
|
return UnitConvertor(m_margins, Unit::Px, m_unit);
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetFollowGrainline(FollowGrainline state)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
m_followGrainLine = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
FollowGrainline VPLayout::GetFollowGrainline() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_followGrainLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetPiecesGap(qreal value)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
m_piecesGap = value;
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetPiecesGapConverted(qreal value)
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
|
|
|
m_piecesGap = UnitConvertor(value, m_unit, Unit::Px);
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
qreal VPLayout::GetPiecesGap() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_piecesGap;
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
qreal VPLayout::GetPiecesGapConverted() const
|
2020-04-19 11:58:43 +02:00
|
|
|
{
|
|
|
|
return UnitConvertor(m_piecesGap, Unit::Px, m_unit);
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetWarningSuperpositionOfPieces(bool state)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
m_warningSuperpositionOfPieces = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
bool VPLayout::GetWarningSuperpositionOfPieces() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_warningSuperpositionOfPieces;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetWarningPiecesOutOfBound(bool state)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
m_warningPiecesOutOfBound = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
bool VPLayout::GetWarningPiecesOutOfBound() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_warningPiecesOutOfBound;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetStickyEdges(bool state)
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
m_stickyEdges = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
bool VPLayout::GetStickyEdges() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_stickyEdges;
|
|
|
|
}
|
2020-05-06 15:05:01 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::ClearSelection()
|
2020-05-06 15:05:01 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
m_unplacedPieceList->ClearSelection();
|
2020-05-09 09:00:27 +02:00
|
|
|
|
2020-05-23 15:29:57 +02:00
|
|
|
for (auto pieceList : m_pieceLists)
|
2020-05-06 15:05:01 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
pieceList->ClearSelection();
|
2020-05-06 15:05:01 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-08 23:49:41 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
void VPLayout::SetFocusedPieceList(VPPieceList* focusedPieceList)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
if(focusedPieceList == nullptr)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
m_focusedPieceList = m_pieceLists.first();
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
m_focusedPieceList = focusedPieceList;
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
VPPieceList* VPLayout::GetFocusedPieceList()
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
return m_focusedPieceList;
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:42:51 +02:00
|
|
|
void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
VPPieceList* pieceListBefore = piece->GetPieceList();
|
2020-05-08 23:49:41 +02:00
|
|
|
|
2020-05-23 15:29:57 +02:00
|
|
|
if(pieceListBefore != nullptr)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
piece->GetPieceList()->RemovePiece(piece);
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
2020-05-23 15:29:57 +02:00
|
|
|
pieceList->AddPiece(piece);
|
2020-05-08 23:49:41 +02:00
|
|
|
|
|
|
|
// signal, that a piece was moved
|
2020-05-23 15:29:57 +02:00
|
|
|
emit PieceMovedToPieceList(piece, pieceListBefore,pieceList);
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|