valentina/src/app/puzzle/vplayout.cpp

350 lines
11 KiB
C++
Raw Normal View History

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"
#include "vpsheet.h"
2020-04-13 18:58:16 +02:00
2020-05-24 19:53:51 +02:00
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(pLayout, "p.layout")
2020-04-13 18:58:16 +02:00
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:34:11 +02:00
VPLayout::VPLayout() :
2020-05-24 14:55:03 +02:00
m_unplacedPieceList(new VPPieceList(this)),
m_sheets(QList<VPSheet*>())
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-13 18:58:16 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 15:34:11 +02:00
VPLayout::~VPLayout()
2020-04-13 18:58:16 +02:00
{
qDeleteAll(m_sheets);
2020-05-23 15:29:57 +02:00
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
}
//---------------------------------------------------------------------------------------------------------------------
VPSheet* VPLayout::AddSheet()
2020-04-13 18:58:16 +02:00
{
VPSheet *newSheet = new VPSheet(this);
m_sheets.append(newSheet);
return newSheet;
2020-04-13 18:58:16 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
VPSheet* VPLayout::AddSheet(VPSheet *sheet)
2020-04-13 18:58:16 +02:00
{
m_sheets.append(sheet);
return sheet;
2020-04-13 18:58:16 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
QList<VPSheet *> VPLayout::GetSheets()
2020-04-13 18:58:16 +02:00
{
return m_sheets;
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
QList<VPPieceList *> pieceLists = QList<VPPieceList *>();
pieceLists.append(m_unplacedPieceList);
for (auto sheet : m_sheets)
{
pieceLists.append(sheet->GetPieceList());
}
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-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::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;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTitle(QString title)
{
m_title = title;
}
//---------------------------------------------------------------------------------------------------------------------
QString VPLayout::GetTitle() const
{
return m_title;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetDescription(QString description)
{
m_description = description;
}
//---------------------------------------------------------------------------------------------------------------------
QString VPLayout::GetDescription() const
{
return m_description;
}
2020-04-13 18:58:16 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::ClearSelection()
2020-04-13 18:58:16 +02:00
{
m_unplacedPieceList->ClearSelection();
2020-04-13 18:58:16 +02:00
for (auto sheet : m_sheets)
{
sheet->ClearSelection();
}
2020-04-13 18:58:16 +02:00
}
2020-05-24 19:53:51 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList)
{
if(m_unplacedPieceList != pieceList)
{
m_unplacedPieceList->ClearSelection();
}
for (auto sheet : m_sheets)
{
if(sheet->GetPieceList() != pieceList)
{
sheet->ClearSelection();
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList)
{
VPPieceList* pieceListBefore = piece->GetPieceList();
if(pieceListBefore != nullptr)
{
piece->GetPieceList()->RemovePiece(piece);
}
pieceList->AddPiece(piece);
// signal, that a piece was moved
emit PieceMovedToPieceList(piece, pieceListBefore,pieceList);
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetFocusedSheet(VPSheet *focusedSheet)
{
if(focusedSheet == nullptr)
{
m_focusedSheet = m_sheets.first();
}
else
{
m_focusedSheet = focusedSheet;
}
}
//---------------------------------------------------------------------------------------------------------------------
VPSheet* VPLayout::GetFocusedSheet()
{
return m_focusedSheet;
}
2020-11-14 15:58:42 +01:00
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSize(qreal width, qreal height)
{
m_tilesSize.setWidth(width);
m_tilesSize.setHeight(height);
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSizeConverted(qreal width, qreal height)
{
m_tilesSize.setWidth(UnitConvertor(width, GetUnit(), Unit::Px));
m_tilesSize.setHeight(UnitConvertor(height, GetUnit(), Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSize(const QSizeF &size)
{
m_tilesSize = size;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesSizeConverted(const QSizeF &size)
{
m_tilesSize = QSizeF(
UnitConvertor(size.width(), GetUnit(), Unit::Px),
UnitConvertor(size.height(), GetUnit(), Unit::Px)
);
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPLayout::GetTilesSize() const
{
return m_tilesSize;
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPLayout::GetTilesSizeConverted() const
{
QSizeF convertedSize = QSizeF(
UnitConvertor(m_tilesSize.width(), Unit::Px, GetUnit()),
UnitConvertor(m_tilesSize.height(), Unit::Px, GetUnit())
);
return convertedSize;
}
//---------------------------------------------------------------------------------------------------------------------
PageOrientation VPLayout::GetTilesOrientation()
{
return m_tilesOrientation;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesOrientation(PageOrientation orientation)
{
if(orientation != m_tilesOrientation)
{
m_tilesOrientation = orientation;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMargins(qreal left, qreal top, qreal right, qreal bottom)
{
m_tilesMargins.setLeft(left);
m_tilesMargins.setTop(top);
m_tilesMargins.setRight(right);
m_tilesMargins.setBottom(bottom);
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMarginsConverted(qreal left, qreal top, qreal right, qreal bottom)
{
m_tilesMargins.setLeft(UnitConvertor(left, GetUnit(), Unit::Px));
m_tilesMargins.setTop(UnitConvertor(top, GetUnit(), Unit::Px));
m_tilesMargins.setRight(UnitConvertor(right, GetUnit(), Unit::Px));
m_tilesMargins.setBottom(UnitConvertor(bottom, GetUnit(), Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMargins(const QMarginsF &margins)
{
m_tilesMargins = margins;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetTilesMarginsConverted(const QMarginsF &margins)
{
m_tilesMargins = UnitConvertor(margins, GetUnit(), Unit::Px);
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPLayout::GetTilesMargins() const
{
return m_tilesMargins;
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPLayout::GetTilesMarginsConverted() const
{
return UnitConvertor(m_tilesMargins, Unit::Px, GetUnit());
}
//---------------------------------------------------------------------------------------------------------------------
bool VPLayout::GetShowTiles()
{
return m_showTiles;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetShowTiles(bool value)
{
m_showTiles = value;
}