2020-04-13 18:58:16 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpuzzlelayout.cpp
|
|
|
|
** @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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
#include "vpuzzlelayout.h"
|
2020-05-23 15:29:57 +02:00
|
|
|
#include "vppiecelist.h"
|
2020-04-26 12:09:28 +02:00
|
|
|
#include "vpuzzlepiece.h"
|
2020-04-13 18:58:16 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPuzzleLayout::VPuzzleLayout() :
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPuzzleLayout::~VPuzzleLayout()
|
|
|
|
{
|
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:29:57 +02:00
|
|
|
VPPieceList* VPuzzleLayout::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:29:57 +02:00
|
|
|
VPPieceList* VPuzzleLayout::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:29:57 +02:00
|
|
|
VPPieceList* VPuzzleLayout::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:29:57 +02:00
|
|
|
QList<VPPieceList *> VPuzzleLayout::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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<VPuzzlePiece *> VPuzzleLayout::GetSelectedPieces()
|
|
|
|
{
|
|
|
|
QList<VPuzzlePiece *> result = QList<VPuzzlePiece *>();
|
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetUnit(Unit unit)
|
|
|
|
{
|
2020-04-18 11:31:55 +02:00
|
|
|
m_unit = unit;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 14:26:24 +02:00
|
|
|
Unit VPuzzleLayout::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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetLayoutSize(qreal width, qreal height)
|
|
|
|
{
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetLayoutSizeConverted(qreal width, qreal height)
|
|
|
|
{
|
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-04-23 14:03:14 +02:00
|
|
|
void VPuzzleLayout::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-04-23 14:03:14 +02:00
|
|
|
void VPuzzleLayout::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-04-23 14:50:20 +02:00
|
|
|
QSizeF VPuzzleLayout::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-04-23 14:50:20 +02:00
|
|
|
QSizeF VPuzzleLayout::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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal bottom)
|
|
|
|
{
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetLayoutMarginsConverted(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));
|
|
|
|
}
|
2020-04-13 18:58:16 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 14:03:14 +02:00
|
|
|
void VPuzzleLayout::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-04-23 14:03:14 +02:00
|
|
|
void VPuzzleLayout::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-04-23 14:50:20 +02:00
|
|
|
QMarginsF VPuzzleLayout::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-04-23 14:50:20 +02:00
|
|
|
QMarginsF VPuzzleLayout::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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetFollowGrainline(FollowGrainline state)
|
|
|
|
{
|
|
|
|
m_followGrainLine = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 17:09:48 +02:00
|
|
|
FollowGrainline VPuzzleLayout::GetFollowGrainline() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_followGrainLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetPiecesGap(qreal value)
|
|
|
|
{
|
|
|
|
m_piecesGap = value;
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetPiecesGapConverted(qreal value)
|
|
|
|
{
|
|
|
|
m_piecesGap = UnitConvertor(value, m_unit, Unit::Px);
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 14:50:20 +02:00
|
|
|
qreal VPuzzleLayout::GetPiecesGap() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_piecesGap;
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:58:43 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 14:50:20 +02:00
|
|
|
qreal VPuzzleLayout::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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetWarningSuperpositionOfPieces(bool state)
|
|
|
|
{
|
|
|
|
m_warningSuperpositionOfPieces = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 14:50:20 +02:00
|
|
|
bool VPuzzleLayout::GetWarningSuperpositionOfPieces() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_warningSuperpositionOfPieces;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetWarningPiecesOutOfBound(bool state)
|
|
|
|
{
|
|
|
|
m_warningPiecesOutOfBound = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 14:50:20 +02:00
|
|
|
bool VPuzzleLayout::GetWarningPiecesOutOfBound() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_warningPiecesOutOfBound;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::SetStickyEdges(bool state)
|
|
|
|
{
|
|
|
|
m_stickyEdges = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-04-23 14:50:20 +02:00
|
|
|
bool VPuzzleLayout::GetStickyEdges() const
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
|
|
|
return m_stickyEdges;
|
|
|
|
}
|
2020-05-06 15:05:01 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPuzzleLayout::ClearSelection()
|
|
|
|
{
|
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:29:57 +02:00
|
|
|
void VPuzzleLayout::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:29:57 +02:00
|
|
|
VPPieceList* VPuzzleLayout::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:29:57 +02:00
|
|
|
void VPuzzleLayout::MovePieceToPieceList(VPuzzlePiece* 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
|
|
|
}
|