valentina/src/app/puzzle/vpsheet.cpp

531 lines
17 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file vpsheet.cpp
** @author Ronan Le Tiec
** @date 23 5, 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 17:46:46 +02:00
#include "vpsheet.h"
#include "vppiecelist.h"
#include "vplayout.h"
//---------------------------------------------------------------------------------------------------------------------
VPSheet::VPSheet(VPLayout* layout) :
m_layout(layout)
{
2020-05-24 14:55:03 +02:00
m_pieceList = new VPPieceList(layout, this);
}
//---------------------------------------------------------------------------------------------------------------------
VPSheet::~VPSheet()
{
delete m_pieceList;
}
2020-11-20 15:51:24 +01:00
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPSheet::GetTemplateSize(PaperSizeTemplate tmpl)
{
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);
}
//---------------------------------------------------------------------------------------------------------------------
QString VPSheet::GetTemplateName(PaperSizeTemplate tmpl)
{
2020-11-21 13:26:38 +01:00
QString tmplName;
2020-11-20 15:51:24 +01:00
switch (tmpl)
{
case PaperSizeTemplate::A0:
2020-11-21 13:26:38 +01:00
tmplName = QString("A0");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::A1:
2020-11-21 13:26:38 +01:00
tmplName = QString("A1");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::A2:
2020-11-21 13:26:38 +01:00
tmplName = QString("A2");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::A3:
2020-11-21 13:26:38 +01:00
tmplName = QString("A3");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::A4:
2020-11-21 13:26:38 +01:00
tmplName = QString("A4");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Letter:
2020-11-21 13:26:38 +01:00
tmplName = tr("Letter");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Legal:
2020-11-21 13:26:38 +01:00
tmplName = tr("Legal");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Tabloid:
2020-11-21 13:26:38 +01:00
tmplName = tr("Tabloid");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll24in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 24in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll30in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 30in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll36in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 36in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll42in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 42in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll44in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 44in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll48in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 48in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll62in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 62in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Roll72in:
2020-11-21 13:26:38 +01:00
tmplName = tr("Roll 72in");
break;
2020-11-20 15:51:24 +01:00
case PaperSizeTemplate::Custom:
2020-11-21 13:26:38 +01:00
tmplName = tr("Custom");
break;
2020-11-20 15:51:24 +01:00
default:
break;
}
2020-11-21 13:26:38 +01:00
if(not tmplName.isEmpty())
{
tmplName += " " + QStringLiteral("(%1ppi)").arg(PrintDPI);
}
return tmplName;
2020-11-20 15:51:24 +01:00
}
//---------------------------------------------------------------------------------------------------------------------
PaperSizeTemplate VPSheet::GetTemplate(QSizeF size)
{
2020-11-21 13:26:38 +01:00
Q_UNUSED(size);
2020-11-20 16:24:53 +01:00
// TODO, float comparision not safe and problems with
// inch / cm
// const int max = static_cast<int>(PaperSizeTemplate::Custom);
// for (int i=0; i < max; i++)
// {
// PaperSizeTemplate tmpl = static_cast<PaperSizeTemplate>(i);
// const QSizeF tmplSize = GetTemplateSize(tmpl);
// if(size.width() == tmplSize.width())
// {
// if(isRollTemplate(tmpl))
// {
// return tmpl;
// }
// else if(size.height() == tmplSize.height())
// {
// return tmpl;
// }
// }
// }
2020-11-20 15:51:24 +01:00
return PaperSizeTemplate::Custom;
}
//---------------------------------------------------------------------------------------------------------------------
bool VPSheet::isRollTemplate(PaperSizeTemplate tmpl)
{
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 VPSheet::PopulateComboBox(QVector<PaperSizeTemplate> *tmpls, QComboBox* comboBox)
{
2020-11-20 16:24:53 +01:00
const QIcon icoPaper("://puzzleicon/16x16/template.png");
const QIcon icoRoll("://puzzleicon/16x16/roll.png");
QIcon icon;
2020-11-20 15:51:24 +01:00
for (auto tmpl : *tmpls)
{
2020-11-20 16:24:53 +01:00
icon = (isRollTemplate(tmpl))? icoRoll : icoPaper;
comboBox->addItem(icon, GetTemplateName(tmpl), QVariant(static_cast<int>(tmpl)));
2020-11-20 15:51:24 +01:00
}
}
2020-11-14 17:31:34 +01:00
//---------------------------------------------------------------------------------------------------------------------
VPLayout* VPSheet::GetLayout()
{
return m_layout;
}
//---------------------------------------------------------------------------------------------------------------------
VPPieceList* VPSheet::GetPieceList()
{
return m_pieceList;
}
//---------------------------------------------------------------------------------------------------------------------
QString VPSheet::GetName() const
{
return m_name;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetName(const QString &name)
{
m_name = name;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetSize(qreal width, qreal height)
{
m_size.setWidth(width);
m_size.setHeight(height);
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetSizeConverted(qreal width, qreal height)
{
m_size.setWidth(UnitConvertor(width, m_layout->GetUnit(), Unit::Px));
m_size.setHeight(UnitConvertor(height, m_layout->GetUnit(), Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetSize(const QSizeF &size)
{
m_size = size;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetSizeConverted(const QSizeF &size)
{
m_size = QSizeF(
UnitConvertor(size.width(), m_layout->GetUnit(), Unit::Px),
UnitConvertor(size.height(), m_layout->GetUnit(), Unit::Px)
);
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPSheet::GetSheetSize() const
{
return m_size;
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPSheet::GetSheetSizeConverted() const
{
QSizeF convertedSize = QSizeF(
UnitConvertor(m_size.width(), Unit::Px, m_layout->GetUnit()),
UnitConvertor(m_size.height(), Unit::Px, m_layout->GetUnit())
);
return convertedSize;
}
2020-06-25 16:59:48 +02:00
//---------------------------------------------------------------------------------------------------------------------
PageOrientation VPSheet::GetOrientation()
{
return m_orientation;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetOrientation(PageOrientation orientation)
{
if(orientation != m_orientation)
{
m_orientation = orientation;
}
}
//---------------------------------------------------------------------------------------------------------------------
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)
{
m_margins.setLeft(UnitConvertor(left, m_layout->GetUnit(), Unit::Px));
m_margins.setTop(UnitConvertor(top, m_layout->GetUnit(), Unit::Px));
m_margins.setRight(UnitConvertor(right, m_layout->GetUnit(), Unit::Px));
m_margins.setBottom(UnitConvertor(bottom, m_layout->GetUnit(), Unit::Px));
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetMargins(const QMarginsF &margins)
{
m_margins = margins;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetMarginsConverted(const QMarginsF &margins)
{
m_margins = UnitConvertor(margins, m_layout->GetUnit(), Unit::Px);
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPSheet::GetSheetMargins() const
{
return m_margins;
}
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPSheet::GetSheetMarginsConverted() const
{
return UnitConvertor(m_margins, Unit::Px, m_layout->GetUnit());
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetFollowGrainline(FollowGrainline state)
{
m_followGrainLine = state;
}
//---------------------------------------------------------------------------------------------------------------------
FollowGrainline VPSheet::GetFollowGrainline() const
{
return m_followGrainLine;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetPiecesGap(qreal value)
{
m_piecesGap = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetPiecesGapConverted(qreal value)
{
m_piecesGap = UnitConvertor(value, m_layout->GetUnit(), Unit::Px);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPSheet::GetPiecesGap() const
2020-05-23 17:46:46 +02:00
{
return m_piecesGap;
}
2020-05-23 17:46:46 +02:00
//---------------------------------------------------------------------------------------------------------------------
qreal VPSheet::GetPiecesGapConverted() const
{
return UnitConvertor(m_piecesGap, Unit::Px, m_layout->GetUnit());
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetStickyEdges(bool state)
{
m_stickyEdges = state;
}
//---------------------------------------------------------------------------------------------------------------------
bool VPSheet::GetStickyEdges() const
{
return m_stickyEdges;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::ClearSelection()
{
m_pieceList->ClearSelection();
2020-05-23 17:46:46 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
bool VPSheet::GetShowGrid()
{
return m_showGrid;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetShowGrid(bool value)
{
m_showGrid = value;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPSheet::GetGridColWidth() const
{
return m_gridColWidth;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPSheet::GetGridColWidthConverted() const
{
return UnitConvertor(m_gridColWidth, Unit::Px, m_layout->GetUnit());
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetGridColWidth(qreal value)
{
m_gridColWidth = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetGridColWidthConverted(qreal value)
{
m_gridColWidth = UnitConvertor(value, m_layout->GetUnit(), Unit::Px);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPSheet::GetGridRowHeight() const
{
return m_gridRowHeight;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPSheet::GetGridRowHeightConverted() const
{
return UnitConvertor(m_gridRowHeight, Unit::Px, m_layout->GetUnit());
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetGridRowHeight(qreal value)
{
m_gridRowHeight = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetGridRowHeightConverted(qreal value)
{
m_gridRowHeight = UnitConvertor(value, m_layout->GetUnit(), Unit::Px);
}