valentina/src/app/puzzle/vpuzzlelayout.cpp

248 lines
8.9 KiB
C++
Raw Normal View History

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"
#include "vpuzzlelayer.h"
2020-04-26 12:09:28 +02:00
#include "vpuzzlepiece.h"
2020-04-13 18:58:16 +02:00
//---------------------------------------------------------------------------------------------------------------------
VPuzzleLayout::VPuzzleLayout() :
m_unplacedPiecesLayer(new VPuzzleLayer())
2020-04-13 18:58:16 +02:00
{
2020-04-26 12:09:28 +02:00
m_unplacedPiecesLayer->SetName(QObject::tr("Unplaced pieces"));
2020-04-18 11:31:55 +02:00
2020-04-26 12:09:28 +02:00
// create a standard default layer:
VPuzzleLayer *layer = new VPuzzleLayer();
layer->SetName(QObject::tr("Layout"));
AddLayer(layer);
2020-04-13 18:58:16 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleLayout::~VPuzzleLayout()
{
2020-04-23 14:37:02 +02:00
qDeleteAll(m_layers);
delete m_unplacedPiecesLayer;
2020-04-13 18:58:16 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzleLayout::GetUnplacedPiecesLayer()
{
return m_unplacedPiecesLayer;
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzleLayout::AddLayer()
{
VPuzzleLayer *newLayer = new VPuzzleLayer();
m_layers.append(newLayer);
return newLayer;
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzleLayout::AddLayer(VPuzzleLayer *layer)
{
m_layers.append(layer);
return layer;
}
//---------------------------------------------------------------------------------------------------------------------
QList<VPuzzleLayer *> VPuzzleLayout::GetLayers()
{
return m_layers;
}
//---------------------------------------------------------------------------------------------------------------------
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;
}