2017-10-15 11:25:20 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @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
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2017-10-15 11:25:20 +02:00
|
|
|
**
|
|
|
|
** 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 "../vpatterndb/vcontainer.h"
|
2023-07-15 09:58:28 +02:00
|
|
|
#include "vplacelabelitem_p.h"
|
2017-10-15 11:25:20 +02:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
#include <QPainterPath>
|
2017-10-15 11:25:20 +02:00
|
|
|
#include <QPolygonF>
|
|
|
|
#include <QTransform>
|
2023-07-15 09:58:28 +02:00
|
|
|
#include <qnumeric.h>
|
2017-10-15 11:25:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VPlaceLabelItem::VPlaceLabelItem()
|
2023-07-15 09:58:28 +02:00
|
|
|
: d(new VPlaceLabelItemData)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
setType(GOType::PlaceLabel);
|
|
|
|
setMode(Draw::Modeling);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
COPY_CONSTRUCTOR_IMPL_2(VPlaceLabelItem, VPointF)
|
2017-10-15 11:25:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
VPlaceLabelItem::~VPlaceLabelItem() = default;
|
2017-10-15 11:25:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetWidthFormula() const -> QString
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetWidthFormula() -> QString &
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetWidth() const -> qreal
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
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
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetHeightFormula() -> QString &
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetHeight() const -> qreal
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
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
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetAngleFormula() -> QString &
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetAngle() const -> qreal
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPlaceLabelItem::SetAngle(qreal value, const QString &formula)
|
|
|
|
{
|
|
|
|
d->aValue = value;
|
|
|
|
d->angle = formula;
|
|
|
|
}
|
|
|
|
|
2018-07-20 09:30:05 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetVisibilityTrigger() const -> QString
|
2018-07-20 09:30:05 +02:00
|
|
|
{
|
|
|
|
return d->visibilityTrigger;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetVisibilityTrigger() -> QString &
|
2018-07-20 09:30:05 +02:00
|
|
|
{
|
|
|
|
return d->visibilityTrigger;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::IsVisible() const -> bool
|
2018-07-20 09:30:05 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetCorrectionAngle() const -> qreal
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->correctionAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPlaceLabelItem::SetCorrectionAngle(qreal value)
|
|
|
|
{
|
|
|
|
d->correctionAngle = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetCenterPoint() const -> quint32
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->centerPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPlaceLabelItem::SetCenterPoint(quint32 id)
|
|
|
|
{
|
|
|
|
d->centerPoint = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::GetLabelType() const -> PlaceLabelType
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return d->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPlaceLabelItem::SetLabelType(PlaceLabelType type)
|
|
|
|
{
|
|
|
|
d->type = type;
|
|
|
|
}
|
|
|
|
|
2019-05-27 13:54:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::RotationMatrix() const -> QTransform
|
2019-05-27 13:54:44 +02:00
|
|
|
{
|
|
|
|
QTransform t;
|
|
|
|
t.translate(x(), y());
|
2023-07-15 09:58:28 +02:00
|
|
|
t.rotate(-d->aValue - d->correctionAngle);
|
2019-05-27 13:54:44 +02:00
|
|
|
t.translate(-x(), -y());
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::Box() const -> QRectF
|
2019-05-27 13:54:44 +02:00
|
|
|
{
|
|
|
|
return QRectF(0, 0, d->wValue, d->hValue);
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VPlaceLabelItem::operator=(const VPlaceLabelItem &item) -> VPlaceLabelItem &
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
if (&item == this)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VPointF::operator=(item);
|
|
|
|
d = item.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VPlaceLabelItem::VPlaceLabelItem(VPlaceLabelItem &&item) noexcept
|
2023-07-15 09:58:28 +02:00
|
|
|
: VPointF(std::move(item)),
|
|
|
|
d(std::move(item.d))
|
|
|
|
{
|
|
|
|
}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
auto VPlaceLabelItem::operator=(VPlaceLabelItem &&item) noexcept -> VPlaceLabelItem &
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
2019-12-30 16:13:18 +01:00
|
|
|
VPointF::operator=(item);
|
2019-12-30 12:00:57 +01:00
|
|
|
std::swap(d, item.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
#endif
|