valentina/src/libs/vgeometry/vplacelabelitem.cpp

242 lines
8.2 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file vplacelabelitem.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 15 10, 2017
**
** @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) 2017 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 "vplacelabelitem.h"
#include "vplacelabelitem_p.h"
#include "../vpatterndb/vcontainer.h"
#include <qnumeric.h>
#include <QPolygonF>
#include <QTransform>
#include <QPainterPath>
//---------------------------------------------------------------------------------------------------------------------
VPlaceLabelItem::VPlaceLabelItem()
: VPointF(), d(new VPlaceLabelItemData)
{
setType(GOType::PlaceLabel);
setMode(Draw::Modeling);
}
//---------------------------------------------------------------------------------------------------------------------
VPlaceLabelItem::VPlaceLabelItem(const VPlaceLabelItem &item)
: VPointF(item), d(item.d)
{}
//---------------------------------------------------------------------------------------------------------------------
VPlaceLabelItem::~VPlaceLabelItem()
{}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetWidthFormula() const -> QString
{
return d->width;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetWidthFormula() -> QString &
{
return d->width;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetWidth() const -> qreal
{
return d->wValue;
}
//---------------------------------------------------------------------------------------------------------------------
void VPlaceLabelItem::SetWidth(qreal value, const QString &formula)
{
d->wValue = value;
d->width = formula;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetHeightFormula() const -> QString
{
return d->height;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetHeightFormula() -> QString &
{
return d->height;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetHeight() const -> qreal
{
return d->hValue;
}
//---------------------------------------------------------------------------------------------------------------------
void VPlaceLabelItem::SetHeight(qreal value, const QString &formula)
{
d->hValue = value;
d->height = formula;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetAngleFormula() const -> QString
{
return d->angle;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetAngleFormula() -> QString &
{
return d->angle;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetAngle() const -> qreal
{
return d->aValue;
}
//---------------------------------------------------------------------------------------------------------------------
void VPlaceLabelItem::SetAngle(qreal value, const QString &formula)
{
d->aValue = value;
d->angle = formula;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetVisibilityTrigger() const -> QString
{
return d->visibilityTrigger;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetVisibilityTrigger() -> QString &
{
return d->visibilityTrigger;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::IsVisible() const -> bool
{
bool visible = true;
if (qIsInf(d->isVisible) || qIsNaN(d->isVisible))
{
qWarning() << QObject::tr("Visibility trigger contains error and will be ignored");
}
else if (qFuzzyIsNull(d->isVisible))
{
visible = false;
}
return visible;
}
//---------------------------------------------------------------------------------------------------------------------
void VPlaceLabelItem::SetVisibilityTrigger(qreal visible, const QString &formula)
{
d->visibilityTrigger = formula;
d->isVisible = visible;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetCorrectionAngle() const -> qreal
{
return d->correctionAngle;
}
//---------------------------------------------------------------------------------------------------------------------
void VPlaceLabelItem::SetCorrectionAngle(qreal value)
{
d->correctionAngle = value;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetCenterPoint() const -> quint32
{
return d->centerPoint;
}
//---------------------------------------------------------------------------------------------------------------------
void VPlaceLabelItem::SetCenterPoint(quint32 id)
{
d->centerPoint = id;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::GetLabelType() const -> PlaceLabelType
{
return d->type;
}
//---------------------------------------------------------------------------------------------------------------------
void VPlaceLabelItem::SetLabelType(PlaceLabelType type)
{
d->type = type;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::RotationMatrix() const -> QTransform
{
QTransform t;
t.translate(x(), y());
t.rotate(-d->aValue-d->correctionAngle);
t.translate(-x(), -y());
return t;
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::Box() const -> QRectF
{
return QRectF(0, 0, d->wValue, d->hValue);
}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::operator=(const VPlaceLabelItem &item) -> VPlaceLabelItem &
{
if ( &item == this )
{
return *this;
}
VPointF::operator=(item);
d = item.d;
return *this;
}
#ifdef Q_COMPILER_RVALUE_REFS
//---------------------------------------------------------------------------------------------------------------------
2022-08-12 17:50:13 +02:00
VPlaceLabelItem::VPlaceLabelItem(VPlaceLabelItem &&item) Q_DECL_NOTHROW
: VPointF(std::move(item)), d(std::move(item.d))
{}
//---------------------------------------------------------------------------------------------------------------------
2023-05-03 13:07:02 +02:00
auto VPlaceLabelItem::operator=(VPlaceLabelItem &&item) Q_DECL_NOTHROW->VPlaceLabelItem &
{
VPointF::operator=(item);
std::swap(d, item.d);
return *this;
}
#endif