Compare commits

..

4 commits

Author SHA1 Message Date
Roman Telezhynskyi eeaba2f3c5 Lupdate. 2023-05-22 17:40:00 +03:00
Roman Telezhynskyi 7410d188ce Piece labels line break. 2023-05-22 17:30:18 +03:00
Roman Telezhynskyi 1dbd0c7c56 Improve clang format settings. 2023-05-22 17:27:42 +03:00
Roman Telezhynskyi e540c6292c Refactoring.
Fix code style.
2023-05-22 17:27:42 +03:00
43 changed files with 8919 additions and 8002 deletions

View file

@ -35,3 +35,4 @@ IndentAccessModifiers: false
AccessModifierOffset: -4 AccessModifierOffset: -4
SpaceBeforeParens: ControlStatementsExceptControlMacros SpaceBeforeParens: ControlStatementsExceptControlMacros
IndentCaseLabels: true IndentCaseLabels: true
StatementMacros: ['Q_OBJECT', 'Q_UNUSED']

View file

@ -28,6 +28,7 @@
- New notch type - Check Notch. - New notch type - Check Notch.
- Control a notch width and angle with formulas. - Control a notch width and angle with formulas.
- Independent translation for piece labels. - Independent translation for piece labels.
- Piece labels line break.
# Valentina 0.7.52 September 12, 2022 # Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru. - Fix crash when default locale is ru.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -28,32 +28,32 @@
#include "vpgraphicspiece.h" #include "vpgraphicspiece.h"
#include <QPen>
#include <QBrush>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneContextMenuEvent>
#include <QMenu>
#include <QtMath>
#include <QGraphicsScene>
#include <QApplication> #include <QApplication>
#include <QBrush>
#include <QGraphicsScene>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsSceneMouseEvent>
#include <QMenu>
#include <QPainter>
#include <QPen>
#include <QStyleOptionGraphicsItem>
#include <QtMath>
#include "../layout/vppiece.h"
#include "../layout/vplayout.h" #include "../layout/vplayout.h"
#include "../layout/vppiece.h"
#include "../layout/vpsheet.h" #include "../layout/vpsheet.h"
#include "../vlayout/vtextmanager.h"
#include "../vlayout/vgraphicsfillitem.h" #include "../vlayout/vgraphicsfillitem.h"
#include "../vlayout/vtextmanager.h"
#include "../vpapplication.h" #include "../vpapplication.h"
#include "compatibility.h"
#include "../vlayout/vlayoutpiecepath.h" #include "../vlayout/vlayoutpiecepath.h"
#include "compatibility.h"
#include "../vgeometry/vlayoutplacelabel.h" #include "../vgeometry/vlayoutplacelabel.h"
#include "undocommands/vpundopiecemove.h"
#include "undocommands/vpundomovepieceonsheet.h" #include "undocommands/vpundomovepieceonsheet.h"
#include "undocommands/vpundopiecemove.h"
#include "vpiecegrainline.h" #include "vpiecegrainline.h"
#include <QLoggingCategory> #include <QLoggingCategory>
@ -101,30 +101,17 @@ inline auto LineMatrix(const VPPiecePtr &piece, const QPointF &topLeft, qreal an
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline auto LineFont(const TextLine& tl, const QFont &base) -> QFont inline auto LineFont(const TextLine &tl, const QFont &base) -> QFont
{ {
QFont fnt = base; QFont fnt = base;
fnt.setPixelSize(base.pixelSize() + tl.m_iFontSize); fnt.setPointSize(base.pointSize() + tl.m_iFontSize);
fnt.setBold(tl.m_bold); fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);
return fnt; return fnt;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline auto LineText(const TextLine& tl, const QFontMetrics &fm, qreal width) -> QString inline auto LineAlign(const TextLine &tl, const QString &text, const QFontMetrics &fm, qreal width) -> qreal
{
QString qsText = tl.m_qsText;
if (TextWidth(fm, qsText) > width)
{
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(width));
}
return qsText;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto LineAlign(const TextLine& tl, const QString &text, const QFontMetrics &fm, qreal width) -> qreal
{ {
const int lineWidth = TextWidth(fm, text); const int lineWidth = TextWidth(fm, text);
@ -135,7 +122,7 @@ inline auto LineAlign(const TextLine& tl, const QString &text, const QFontMetric
} }
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
{ {
dX = (width - lineWidth)/2; dX = (width - lineWidth) / 2;
} }
else if ((tl.m_eAlign & Qt::AlignRight) > 0) else if ((tl.m_eAlign & Qt::AlignRight) > 0)
{ {
@ -153,8 +140,8 @@ inline auto SelectionBrush() -> QBrush
} // namespace } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPGraphicsPiece::VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent) : VPGraphicsPiece::VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent)
QGraphicsObject(parent), : QGraphicsObject(parent),
m_piece(piece) m_piece(piece)
{ {
// set some infos // set some infos
@ -190,7 +177,7 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF
shape.addPath(m_stickyPath); shape.addPath(m_stickyPath);
VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
const qreal halfPenWidth = settings->GetLayoutLineWidth()/2.; const qreal halfPenWidth = settings->GetLayoutLineWidth() / 2.;
return shape.boundingRect().adjusted(-halfPenWidth, -halfPenWidth, halfPenWidth, halfPenWidth); return shape.boundingRect().adjusted(-halfPenWidth, -halfPenWidth, halfPenWidth, halfPenWidth);
} }
@ -198,7 +185,7 @@ auto VPGraphicsPiece::boundingRect() const -> QRectF
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPGraphicsPiece::shape() const -> QPainterPath auto VPGraphicsPiece::shape() const -> QPainterPath
{ {
if(!m_cuttingLine.isEmpty()) if (!m_cuttingLine.isEmpty())
{ {
return m_cuttingLine; return m_cuttingLine;
} }
@ -222,11 +209,11 @@ void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event) void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
//perform the default behaviour // perform the default behaviour
QGraphicsObject::mousePressEvent(event); QGraphicsObject::mousePressEvent(event);
// change the cursor when clicking the left button // change the cursor when clicking the left button
if(event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
{ {
setCursor(Qt::ClosedHandCursor); setCursor(Qt::ClosedHandCursor);
@ -250,7 +237,7 @@ void VPGraphicsPiece::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
//perform the default behaviour // perform the default behaviour
QGraphicsItem::mouseReleaseEvent(event); QGraphicsItem::mouseReleaseEvent(event);
// change the cursor when clicking left button // change the cursor when clicking left button
@ -267,8 +254,8 @@ void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (layout->LayoutSettings().GetStickyEdges() && m_hasStickyPosition) if (layout->LayoutSettings().GetStickyEdges() && m_hasStickyPosition)
{ {
auto *command = new VPUndoPieceMove(piece, m_stickyTranslateX, m_stickyTranslateY, auto *command =
m_allowChangeMerge); new VPUndoPieceMove(piece, m_stickyTranslateX, m_stickyTranslateY, m_allowChangeMerge);
layout->UndoStack()->push(command); layout->UndoStack()->push(command);
SetStickyPoints(QVector<QPointF>()); SetStickyPoints(QVector<QPointF>());
@ -314,7 +301,7 @@ void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QList<VPSheetPtr> sheets = layout->GetSheets(); QList<VPSheetPtr> sheets = layout->GetSheets();
sheets.removeAll(piece->Sheet()); sheets.removeAll(piece->Sheet());
QVector<QAction*> moveToActions; QVector<QAction *> moveToActions;
if (not sheets.isEmpty()) if (not sheets.isEmpty())
{ {
@ -324,7 +311,7 @@ void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{ {
if (not sheet.isNull()) if (not sheet.isNull())
{ {
QAction* moveToSheet = moveMenu->addAction(sheet->GetName()); QAction *moveToSheet = moveMenu->addAction(sheet->GetName());
moveToSheet->setData(QVariant::fromValue(sheet)); moveToSheet->setData(QVariant::fromValue(sheet));
moveToActions.append(moveToSheet); moveToActions.append(moveToSheet);
} }
@ -399,29 +386,37 @@ void VPGraphicsPiece::InitPieceLabel(const QVector<QPointF> &labelShape, const V
const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length(); const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length();
const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length(); const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length();
const qreal angle = - QLineF(labelShape.at(0), labelShape.at(1)).angle(); const qreal angle = -QLineF(labelShape.at(0), labelShape.at(1)).angle();
const QColor color = PieceColor(); const QColor color = PieceColor();
const int maxLineWidth = tm.MaxLineWidth(static_cast<int>(dW)); const int maxLineWidth = tm.MaxLineWidth(static_cast<int>(dW));
qreal dY = 0; qreal dY = 0;
for (int i = 0; i < tm.GetSourceLinesCount(); ++i) const QVector<TextLine> labelLines = tm.GetLabelSourceLines(qFloor(dW), tm.GetFont());
for (const auto &tl : labelLines)
{ {
const TextLine& tl = tm.GetSourceLine(i);
const QFont fnt = LineFont(tl, tm.GetFont()); const QFont fnt = LineFont(tl, tm.GetFont());
const QFontMetrics fm(fnt); const QFontMetrics fm(fnt);
if (m_textAsPaths) if (m_textAsPaths)
{ {
dY += fm.height(); dY += fm.height();
}
if (dY > dH) if (dY > dH)
{ {
break; break;
} }
}
else
{
if (dY + fm.height() > dH)
{
break;
}
}
const QString qsText = LineText(tl, fm, dW); const QString qsText = tl.m_qsText;
const qreal dX = LineAlign(tl, qsText, fm, dW); const qreal dX = LineAlign(tl, qsText, fm, dW);
// set up the rotation around top-left corner matrix // set up the rotation around top-left corner matrix
const QTransform lineMatrix = LineMatrix(piece, labelShape.at(0), angle, QPointF(dX, dY), maxLineWidth); const QTransform lineMatrix = LineMatrix(piece, labelShape.at(0), angle, QPointF(dX, dY), maxLineWidth);
@ -429,9 +424,9 @@ void VPGraphicsPiece::InitPieceLabel(const QVector<QPointF> &labelShape, const V
if (m_textAsPaths) if (m_textAsPaths)
{ {
QPainterPath path; QPainterPath path;
path.addText(0, - static_cast<qreal>(fm.ascent())/6., fnt, qsText); path.addText(0, -static_cast<qreal>(fm.ascent()) / 6., fnt, qsText);
auto* item = new QGraphicsPathItem(this); auto *item = new QGraphicsPathItem(this);
item->setPath(path); item->setPath(path);
item->setBrush(QBrush(color)); item->setBrush(QBrush(color));
item->setTransform(lineMatrix); item->setTransform(lineMatrix);
@ -441,7 +436,7 @@ void VPGraphicsPiece::InitPieceLabel(const QVector<QPointF> &labelShape, const V
} }
else else
{ {
auto* item = new QGraphicsSimpleTextItem(this); auto *item = new QGraphicsSimpleTextItem(this);
item->setFont(fnt); item->setFont(fnt);
item->setText(qsText); item->setText(qsText);
item->setBrush(QBrush(color)); item->setBrush(QBrush(color));
@ -464,7 +459,7 @@ void VPGraphicsPiece::InitGrainlineItem()
return; return;
} }
if(piece->IsGrainlineEnabled()) if (piece->IsGrainlineEnabled())
{ {
m_grainlineItem = new VGraphicsFillItem(this); m_grainlineItem = new VGraphicsFillItem(this);
m_grainlineItem->setPath(VLayoutPiece::GrainlinePath(piece->GetMappedGrainlineShape())); m_grainlineItem->setPath(VLayoutPiece::GrainlinePath(piece->GetMappedGrainlineShape()));
@ -516,7 +511,7 @@ void VPGraphicsPiece::PaintSeamLine(QPainter *painter, const VPPiecePtr &piece)
if (not piece->IsHideMainPath() || not piece->IsSeamAllowance()) if (not piece->IsHideMainPath() || not piece->IsSeamAllowance())
{ {
QVector<VLayoutPoint> seamLinePoints = piece->GetMappedContourPoints(); QVector<VLayoutPoint> seamLinePoints = piece->GetMappedContourPoints();
if(!seamLinePoints.isEmpty()) if (!seamLinePoints.isEmpty())
{ {
m_seamLine.moveTo(ConstFirst(seamLinePoints)); m_seamLine.moveTo(ConstFirst(seamLinePoints));
for (int i = 1; i < seamLinePoints.size(); i++) for (int i = 1; i < seamLinePoints.size(); i++)
@ -541,7 +536,7 @@ void VPGraphicsPiece::PaintCuttingLine(QPainter *painter, const VPPiecePtr &piec
if (piece->IsSeamAllowance() && not piece->IsSeamAllowanceBuiltIn()) if (piece->IsSeamAllowance() && not piece->IsSeamAllowanceBuiltIn())
{ {
QVector<VLayoutPoint> cuttingLinepoints = piece->GetMappedSeamAllowancePoints(); QVector<VLayoutPoint> cuttingLinepoints = piece->GetMappedSeamAllowancePoints();
if(!cuttingLinepoints.isEmpty()) if (!cuttingLinepoints.isEmpty())
{ {
m_cuttingLine.moveTo(ConstFirst(cuttingLinepoints)); m_cuttingLine.moveTo(ConstFirst(cuttingLinepoints));
for (int i = 1; i < cuttingLinepoints.size(); i++) for (int i = 1; i < cuttingLinepoints.size(); i++)
@ -564,7 +559,7 @@ void VPGraphicsPiece::PaintCuttingLine(QPainter *painter, const VPPiecePtr &piec
void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece) void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece)
{ {
QVector<VLayoutPiecePath> internalPaths = piece->GetInternalPaths(); QVector<VLayoutPiecePath> internalPaths = piece->GetInternalPaths();
for (const auto& piecePath : internalPaths) for (const auto &piecePath : internalPaths)
{ {
QPainterPath path = piece->GetMatrix().map(piecePath.GetPainterPath()); QPainterPath path = piece->GetMatrix().map(piecePath.GetPainterPath());
@ -585,7 +580,7 @@ void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &pi
void VPGraphicsPiece::PaintPassmarks(QPainter *painter, const VPPiecePtr &piece) void VPGraphicsPiece::PaintPassmarks(QPainter *painter, const VPPiecePtr &piece)
{ {
QVector<VLayoutPassmark> passmarks = piece->GetMappedPassmarks(); QVector<VLayoutPassmark> passmarks = piece->GetMappedPassmarks();
for(auto &passmark : passmarks) for (auto &passmark : passmarks)
{ {
QPainterPath passmarkPath; QPainterPath passmarkPath;
for (auto &line : passmark.lines) for (auto &line : passmark.lines)
@ -610,7 +605,7 @@ void VPGraphicsPiece::PaintPassmarks(QPainter *painter, const VPPiecePtr &piece)
void VPGraphicsPiece::PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece) void VPGraphicsPiece::PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece)
{ {
QVector<VLayoutPlaceLabel> placeLabels = piece->GetPlaceLabels(); QVector<VLayoutPlaceLabel> placeLabels = piece->GetPlaceLabels();
for(auto &placeLabel : placeLabels) for (auto &placeLabel : placeLabels)
{ {
QPainterPath path = QPainterPath path =
VAbstractPiece::LabelShapePath(piece->MapPlaceLabelShape(VAbstractPiece::PlaceLabelShape(placeLabel))); VAbstractPiece::LabelShapePath(piece->MapPlaceLabelShape(VAbstractPiece::PlaceLabelShape(placeLabel)));
@ -807,7 +802,7 @@ auto VPGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &valu
{ {
if (scene() != nullptr) if (scene() != nullptr)
{ {
if(change == ItemSelectedHasChanged) if (change == ItemSelectedHasChanged)
{ {
VPPiecePtr piece = m_piece.toStrongRef(); VPPiecePtr piece = m_piece.toStrongRef();
if (not piece.isNull()) if (not piece.isNull())
@ -825,4 +820,3 @@ auto VPGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &valu
return QGraphicsObject::itemChange(change, value); return QGraphicsObject::itemChange(change, value);
} }

View file

@ -26,23 +26,24 @@
** **
** *************************************************************************/ ** *************************************************************************/
#include <Qt>
#include <QFont>
#include <QXmlStreamAttributes>
#include <ciso646>
#include "vpiecegrainline.h"
#include "vplayoutfilereader.h" #include "vplayoutfilereader.h"
#include "vplayoutliterals.h"
#include "../layout/vpsheet.h"
#include "../vlayout/vlayoutpiecepath.h"
#include "../vlayout/vtextmanager.h"
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "../ifc/exception/vexceptionconversionerror.h" #include "../ifc/exception/vexceptionconversionerror.h"
#include "../vpatterndb/floatItemData/floatitemdef.h"
#include "../vgeometry/vgeometrydef.h"
#include "../vgeometry/vlayoutplacelabel.h"
#include "../layout/vplayout.h" #include "../layout/vplayout.h"
#include "../layout/vppiece.h" #include "../layout/vppiece.h"
#include "../layout/vpsheet.h"
#include "../vgeometry/vgeometrydef.h"
#include "../vgeometry/vlayoutplacelabel.h"
#include "../vlayout/vlayoutpiecepath.h"
#include "../vlayout/vtextmanager.h"
#include "../vmisc/vcommonsettings.h"
#include "../vpatterndb/floatItemData/floatitemdef.h"
#include "vpiecegrainline.h"
#include "vplayoutliterals.h"
#include <QFont>
#include <QXmlStreamAttributes>
#include <Qt>
#include <ciso646>
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
@ -99,7 +100,7 @@ auto StringToPath(const QString &path) -> QVector<QPointF>
QStringList points = path.split(ML::pointsSep); QStringList points = path.split(ML::pointsSep);
p.reserve(points.size()); p.reserve(points.size());
for (const auto& point : points) for (const auto &point : points)
{ {
p.append(StringToPoint(point)); p.append(StringToPoint(point));
} }
@ -188,7 +189,7 @@ auto StringToLines(const QString &string) -> QVector<QLineF>
QVector<QLineF> path; QVector<QLineF> path;
path.reserve(lines.size()); path.reserve(lines.size());
for (const auto& line : lines) for (const auto &line : lines)
{ {
QLineF l = StringToLine(line); QLineF l = StringToLine(line);
if (not l.isNull()) if (not l.isNull())
@ -225,7 +226,7 @@ auto VPLayoutFileReader::ReadFile(const VPLayoutPtr &layout, QFile *file) -> boo
ReadLayout(layout); ReadLayout(layout);
} }
} }
catch(const VException &e) catch (const VException &e)
{ {
raiseError(e.ErrorMessage()); raiseError(e.ErrorMessage());
} }
@ -238,8 +239,7 @@ void VPLayoutFileReader::ReadLayout(const VPLayoutPtr &layout)
{ {
AssertRootTag(ML::TagLayout); AssertRootTag(ML::TagLayout);
const QStringList tags const QStringList tags{
{
ML::TagProperties, // 0 ML::TagProperties, // 0
ML::TagUnplacedPieces, // 1 ML::TagUnplacedPieces, // 1
ML::TagSheets // 2 ML::TagSheets // 2
@ -271,8 +271,7 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout)
{ {
AssertRootTag(ML::TagProperties); AssertRootTag(ML::TagProperties);
const QStringList tags const QStringList tags{
{
ML::TagUnit, // 0 ML::TagUnit, // 0
ML::TagTitle, // 1 ML::TagTitle, // 1
ML::TagDescription, // 2 ML::TagDescription, // 2
@ -288,15 +287,15 @@ void VPLayoutFileReader::ReadProperties(const VPLayoutPtr &layout)
switch (tags.indexOf(name().toString())) switch (tags.indexOf(name().toString()))
{ {
case 0:// unit case 0: // unit
qDebug("read unit"); qDebug("read unit");
layout->LayoutSettings().SetUnit(StrToUnits(readElementText())); layout->LayoutSettings().SetUnit(StrToUnits(readElementText()));
break; break;
case 1:// title case 1: // title
qDebug("read title"); qDebug("read title");
layout->LayoutSettings().SetTitle(readElementText()); layout->LayoutSettings().SetTitle(readElementText());
break; break;
case 2:// description case 2: // description
qDebug("read description"); qDebug("read description");
layout->LayoutSettings().SetDescription(readElementText()); layout->LayoutSettings().SetDescription(readElementText());
break; break;
@ -357,10 +356,9 @@ void VPLayoutFileReader::ReadTiles(const VPLayoutPtr &layout)
layout->LayoutSettings().SetShowTiles(ReadAttributeBool(attribs, ML::AttrVisible, falseStr)); layout->LayoutSettings().SetShowTiles(ReadAttributeBool(attribs, ML::AttrVisible, falseStr));
layout->LayoutSettings().SetPrintTilesScheme(ReadAttributeBool(attribs, ML::AttrPrintScheme, falseStr)); layout->LayoutSettings().SetPrintTilesScheme(ReadAttributeBool(attribs, ML::AttrPrintScheme, falseStr));
layout->LayoutSettings().SetShowTileNumber(ReadAttributeBool(attribs, ML::AttrTileNumber, falseStr)); layout->LayoutSettings().SetShowTileNumber(ReadAttributeBool(attribs, ML::AttrTileNumber, falseStr));
// attribs.value(ML::AttrMatchingMarks); // TODO // attribs.value(ML::AttrMatchingMarks); // TODO
const QStringList tags const QStringList tags{
{
ML::TagSize, // 0 ML::TagSize, // 0
ML::TagMargin // 1 ML::TagMargin // 1
}; };
@ -426,8 +424,7 @@ void VPLayoutFileReader::ReadSheet(const VPLayoutPtr &layout)
QXmlStreamAttributes attribs = attributes(); QXmlStreamAttributes attribs = attributes();
sheet->SetGrainlineType(StrToGrainlineType(ReadAttributeEmptyString(attribs, ML::AttrGrainlineType))); sheet->SetGrainlineType(StrToGrainlineType(ReadAttributeEmptyString(attribs, ML::AttrGrainlineType)));
const QStringList tags const QStringList tags{
{
ML::TagName, // 0 ML::TagName, // 0
ML::TagSize, // 1 ML::TagSize, // 1
ML::TagMargin, // 2 ML::TagMargin, // 2
@ -462,7 +459,6 @@ void VPLayoutFileReader::ReadSheet(const VPLayoutPtr &layout)
layout->AddSheet(sheet); layout->AddSheet(sheet);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadPieces(const VPLayoutPtr &layout, const VPSheetPtr &sheet) void VPLayoutFileReader::ReadPieces(const VPLayoutPtr &layout, const VPSheetPtr &sheet)
{ {
@ -513,8 +509,7 @@ void VPLayoutFileReader::ReadPiece(const VPPiecePtr &piece)
piece->SetSewLineOnDrawing(ReadAttributeBool(attribs, ML::AttrSewLineOnDrawing, falseStr)); piece->SetSewLineOnDrawing(ReadAttributeBool(attribs, ML::AttrSewLineOnDrawing, falseStr));
piece->SetMatrix(StringToTransfrom(ReadAttributeEmptyString(attribs, ML::AttrTransform))); piece->SetMatrix(StringToTransfrom(ReadAttributeEmptyString(attribs, ML::AttrTransform)));
const QStringList tags const QStringList tags{
{
ML::TagSeamLine, // 0 ML::TagSeamLine, // 0
ML::TagSeamAllowance, // 1 ML::TagSeamAllowance, // 1
ML::TagGrainline, // 2 ML::TagGrainline, // 2
@ -905,7 +900,8 @@ auto VPLayoutFileReader::ReadLabelLine() -> TextLine
QXmlStreamAttributes attribs = attributes(); QXmlStreamAttributes attribs = attributes();
line.m_iFontSize = ReadAttributeInt(attribs, ML::AttrFontSize, QString::number(MIN_FONT_SIZE)); line.m_iFontSize =
ReadAttributeInt(attribs, ML::AttrFontSize, QString::number(VCommonSettings::MinPieceLabelFontPointSize()));
line.m_bold = ReadAttributeBool(attribs, ML::AttrBold, falseStr); line.m_bold = ReadAttributeBool(attribs, ML::AttrBold, falseStr);
line.m_italic = ReadAttributeBool(attribs, ML::AttrItalic, falseStr); line.m_italic = ReadAttributeBool(attribs, ML::AttrItalic, falseStr);
int alignment = ReadAttributeInt(attribs, ML::AttrAlignment, QString::number(static_cast<int>(Qt::AlignCenter))); int alignment = ReadAttributeInt(attribs, ML::AttrAlignment, QString::number(static_cast<int>(Qt::AlignCenter)));
@ -976,7 +972,7 @@ auto VPLayoutFileReader::ReadSize() -> QSizeF
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::AssertRootTag(const QString &tag) const void VPLayoutFileReader::AssertRootTag(const QString &tag) const
{ {
if (not (isStartElement() && name() == tag)) if (not(isStartElement() && name() == tag))
{ {
throw VException(tr("Unexpected tag %1 in line %2").arg(name().toString()).arg(lineNumber())); throw VException(tr("Unexpected tag %1 in line %2").arg(name().toString()).arg(lineNumber()));
} }
@ -1016,7 +1012,7 @@ auto VPLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs,
{ {
parametr = ReadAttributeString(attribs, name, defValue); parametr = ReadAttributeString(attribs, name, defValue);
const QStringList bools {trueStr, falseStr, QChar('1'), QChar('0')}; const QStringList bools{trueStr, falseStr, QChar('1'), QChar('0')};
switch (bools.indexOf(parametr)) switch (bools.indexOf(parametr))
{ {
case 0: // true case 0: // true
@ -1027,7 +1023,7 @@ auto VPLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs,
case 3: // 0 case 3: // 0
val = false; val = false;
break; break;
default:// others default: // others
throw VExceptionConversionError(message, name); throw VExceptionConversionError(message, name);
} }
} }

View file

@ -27,19 +27,19 @@
*************************************************************************/ *************************************************************************/
#include "preferencespatternpage.h" #include "preferencespatternpage.h"
#include "ui_preferencespatternpage.h"
#include "../dialogdatetimeformats.h" #include "../dialogdatetimeformats.h"
#include "../dialogknownmaterials.h" #include "../dialogknownmaterials.h"
#include "../vmisc/vvalentinasettings.h"
#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vabstractvalapplication.h"
#include "../vmisc/vvalentinasettings.h"
#include "ui_preferencespatternpage.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vmisc/backport/qoverload.h" #include "../vmisc/backport/qoverload.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vwidgets/vmaingraphicsview.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vwidgets/vmaingraphicsview.h"
#include <QMessageBox>
#include <QDate> #include <QDate>
#include <QMessageBox>
#include <QTime> #include <QTime>
namespace namespace
@ -85,15 +85,16 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent)
ui->comboBoxLineWidthUnit->setCurrentIndex(indexUnit); ui->comboBoxLineWidthUnit->setCurrentIndex(indexUnit);
} }
connect(ui->comboBoxLineWidthUnit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]() connect(ui->comboBoxLineWidthUnit, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this]()
{ {
const Unit lineUnit = static_cast<Unit>(ui->comboBoxLineWidthUnit->currentData().toInt()); const Unit lineUnit = static_cast<Unit>(ui->comboBoxLineWidthUnit->currentData().toInt());
const qreal value = UnitConvertor(ui->doubleSpinBoxLineWidth->value(), m_oldLineUnit, lineUnit); const qreal value = UnitConvertor(ui->doubleSpinBoxLineWidth->value(), m_oldLineUnit, lineUnit);
ui->doubleSpinBoxLineWidth->setDecimals(lineUnit == Unit::Mm ? 1 : 6); ui->doubleSpinBoxLineWidth->setDecimals(lineUnit == Unit::Mm ? 1 : 6);
ui->doubleSpinBoxLineWidth->setMinimum(UnitConvertor(ui->doubleSpinBoxLineWidth->minimum(), m_oldLineUnit, ui->doubleSpinBoxLineWidth->setMinimum(
lineUnit)); UnitConvertor(ui->doubleSpinBoxLineWidth->minimum(), m_oldLineUnit, lineUnit));
ui->doubleSpinBoxLineWidth->setMaximum(UnitConvertor(ui->doubleSpinBoxLineWidth->maximum(), m_oldLineUnit, ui->doubleSpinBoxLineWidth->setMaximum(
lineUnit)); UnitConvertor(ui->doubleSpinBoxLineWidth->maximum(), m_oldLineUnit, lineUnit));
ui->doubleSpinBoxLineWidth->setValue(value); ui->doubleSpinBoxLineWidth->setValue(value);
m_oldLineUnit = lineUnit; m_oldLineUnit = lineUnit;
}); });
@ -111,7 +112,19 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent)
ui->checkBoxSewLineOnDrawing->setChecked(settings->GetSewLineOnDrawing()); ui->checkBoxSewLineOnDrawing->setChecked(settings->GetSewLineOnDrawing());
ui->doublePassmarkCheck->setChecked(settings->IsDoublePassmark()); ui->doublePassmarkCheck->setChecked(settings->IsDoublePassmark());
ui->checkBoxHideMainPath->setChecked(settings->IsHideMainPath()); ui->checkBoxHideMainPath->setChecked(settings->IsHideMainPath());
ui->fontComboBoxLabelFont->setCurrentFont(settings->GetLabelFont());
QFont labelFont = settings->GetLabelFont();
int pointSize = settings->GetPieceLabelFontPointSize();
labelFont.setPointSize(pointSize);
ui->fontComboBoxLabelFont->setCurrentFont(labelFont);
InitLabelFontSizes();
const qint32 indexSize = ui->comboBoxLabelFontSize->findData(pointSize);
if (indexSize != -1)
{
ui->comboBoxLabelFontSize->setCurrentIndex(indexSize);
}
ui->checkBoxRemeberPatternMaterials->setChecked(settings->IsRememberPatternMaterials()); ui->checkBoxRemeberPatternMaterials->setChecked(settings->IsRememberPatternMaterials());
m_knownMaterials = settings->GetKnownMaterials(); m_knownMaterials = settings->GetKnownMaterials();
@ -166,6 +179,7 @@ auto PreferencesPatternPage::Apply() -> QStringList
settings->SetSewLineOnDrawing(ui->checkBoxSewLineOnDrawing->isChecked()); settings->SetSewLineOnDrawing(ui->checkBoxSewLineOnDrawing->isChecked());
settings->SetHideMainPath(ui->checkBoxHideMainPath->isChecked()); settings->SetHideMainPath(ui->checkBoxHideMainPath->isChecked());
settings->SetLabelFont(ui->fontComboBoxLabelFont->currentFont()); settings->SetLabelFont(ui->fontComboBoxLabelFont->currentFont());
settings->SetPieceLabelFontPointSize(ui->comboBoxLabelFontSize->currentData().toInt());
if (settings->IsDoublePassmark() != ui->doublePassmarkCheck->isChecked()) if (settings->IsDoublePassmark() != ui->doublePassmarkCheck->isChecked())
{ {
@ -254,6 +268,21 @@ void PreferencesPatternPage::InitLabelDateTimeFormats()
connect(ui->pushButtonEditTimeFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats); connect(ui->pushButtonEditTimeFormats, &QPushButton::clicked, this, &PreferencesPatternPage::EditDateTimeFormats);
} }
//---------------------------------------------------------------------------------------------------------------------
void PreferencesPatternPage::InitLabelFontSizes()
{
ui->comboBoxLabelFontSize->clear();
// Get the available font sizes
for (auto size : QFontDatabase::standardSizes())
{
if (size >= VCommonSettings::MinPieceLabelFontPointSize())
{
ui->comboBoxLabelFontSize->addItem(QString::number(size), size);
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PreferencesPatternPage::InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat) void PreferencesPatternPage::InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat)
{ {

View file

@ -29,12 +29,12 @@
#ifndef PREFERENCESPATTERNPAGE_H #ifndef PREFERENCESPATTERNPAGE_H
#define PREFERENCESPATTERNPAGE_H #define PREFERENCESPATTERNPAGE_H
#include <QWidget>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include <QWidget>
namespace Ui namespace Ui
{ {
class PreferencesPatternPage; class PreferencesPatternPage;
} }
class QComboBox; class QComboBox;
@ -51,7 +51,7 @@ public:
void InitDefaultSeamAllowance(); void InitDefaultSeamAllowance();
protected: protected:
void changeEvent(QEvent* event) override; void changeEvent(QEvent *event) override;
private slots: private slots:
void EditDateTimeFormats(); void EditDateTimeFormats();
@ -65,6 +65,7 @@ private:
Unit m_oldLineUnit{Unit::Mm}; Unit m_oldLineUnit{Unit::Mm};
void InitLabelDateTimeFormats(); void InitLabelDateTimeFormats();
void InitLabelFontSizes();
static void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat); static void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString &currentFormat);
void InitUnits(); void InitUnits();
void RetranslateUi(); void RetranslateUi();

View file

@ -238,6 +238,29 @@ This option will take an affect after restart.</string>
<item> <item>
<widget class="QFontComboBox" name="fontComboBoxLabelFont"/> <widget class="QFontComboBox" name="fontComboBoxLabelFont"/>
</item> </item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxLabelFontSize"/>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View file

@ -2975,7 +2975,7 @@ void MainWindow::ToolBarTools()
connect(ui->actionIncreaseLabelFont, &QAction::triggered, this, [this]() connect(ui->actionIncreaseLabelFont, &QAction::triggered, this, [this]()
{ {
VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings();
settings->SetLabelFontSize(settings->GetLabelFontSize() + 1); settings->SetPatternLabelFontSize(settings->GetPatternLabelFontSize() + 1);
if (m_sceneDraw) if (m_sceneDraw)
{ {
m_sceneDraw->update(); m_sceneDraw->update();
@ -2996,7 +2996,7 @@ void MainWindow::ToolBarTools()
connect(ui->actionDecreaseLabelFont, &QAction::triggered, this, [this]() connect(ui->actionDecreaseLabelFont, &QAction::triggered, this, [this]()
{ {
VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings();
settings->SetLabelFontSize(settings->GetLabelFontSize() - 1); settings->SetPatternLabelFontSize(settings->GetPatternLabelFontSize() - 1);
if (m_sceneDraw) if (m_sceneDraw)
{ {
m_sceneDraw->update(); m_sceneDraw->update();
@ -3017,7 +3017,7 @@ void MainWindow::ToolBarTools()
connect(ui->actionOriginalLabelFont, &QAction::triggered, this, [this]() connect(ui->actionOriginalLabelFont, &QAction::triggered, this, [this]()
{ {
VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings();
settings->SetLabelFontSize(VCommonSettings::GetDefLabelFontSize()); settings->SetPatternLabelFontSize(VCommonSettings::GetDefPatternLabelFontSize());
if (m_sceneDraw) if (m_sceneDraw)
{ {
m_sceneDraw->update(); m_sceneDraw->update();

File diff suppressed because it is too large Load diff

View file

@ -33,7 +33,6 @@
#include <QFont> #include <QFont>
#include <QFontMetrics> #include <QFontMetrics>
#include <QFuture> #include <QFuture>
#include <QtConcurrent/QtConcurrentRun>
#include <QGraphicsPathItem> #include <QGraphicsPathItem>
#include <QList> #include <QList>
#include <QMessageLogger> #include <QMessageLogger>
@ -41,9 +40,10 @@
#include <QPoint> #include <QPoint>
#include <QPolygonF> #include <QPolygonF>
#include <QTransform> #include <QTransform>
#include <Qt>
#include <QtDebug>
#include <QUuid> #include <QUuid>
#include <Qt>
#include <QtConcurrent/QtConcurrentRun>
#include <QtDebug>
#include <QtMath> #include <QtMath>
#include "../vgeometry/vlayoutplacelabel.h" #include "../vgeometry/vlayoutplacelabel.h"
@ -106,7 +106,7 @@ auto FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat
Calculator cal1; Calculator cal1;
rotationAngle = cal1.EvalFormula(pattern->DataVariables(), labelData.GetRotation()); rotationAngle = cal1.EvalFormula(pattern->DataVariables(), labelData.GetRotation());
} }
catch(qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
return false; return false;
@ -122,8 +122,8 @@ auto FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat
const auto topLeftPinPoint = pattern->GeometricObject<VPointF>(topLeftPin); const auto topLeftPinPoint = pattern->GeometricObject<VPointF>(topLeftPin);
const auto bottomRightPinPoint = pattern->GeometricObject<VPointF>(bottomRightPin); const auto bottomRightPinPoint = pattern->GeometricObject<VPointF>(bottomRightPin);
const QRectF labelRect = QRectF(static_cast<QPointF>(*topLeftPinPoint), const QRectF labelRect =
static_cast<QPointF>(*bottomRightPinPoint)); QRectF(static_cast<QPointF>(*topLeftPinPoint), static_cast<QPointF>(*bottomRightPinPoint));
labelWidth = qAbs(labelRect.width()); labelWidth = qAbs(labelRect.width());
labelHeight = qAbs(labelRect.height()); labelHeight = qAbs(labelRect.height());
@ -131,7 +131,7 @@ auto FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat
return true; return true;
} }
catch(const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
// do nothing. // do nothing.
} }
@ -147,7 +147,7 @@ auto FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat
labelHeight = cal2.EvalFormula(pattern->DataVariables(), labelData.GetLabelHeight()); labelHeight = cal2.EvalFormula(pattern->DataVariables(), labelData.GetLabelHeight());
labelHeight = ToPixel(labelHeight, *pattern->GetPatternUnit()); labelHeight = ToPixel(labelHeight, *pattern->GetPatternUnit());
} }
catch(qmu::QmuParserError &e) catch (qmu::QmuParserError &e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
return false; return false;
@ -161,7 +161,7 @@ auto FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat
const auto centerPinPoint = pattern->GeometricObject<VPointF>(centerPin); const auto centerPinPoint = pattern->GeometricObject<VPointF>(centerPin);
pos = static_cast<QPointF>(*centerPinPoint) - QRectF(0, 0, labelWidth, labelHeight).center(); pos = static_cast<QPointF>(*centerPinPoint) - QRectF(0, 0, labelWidth, labelHeight).center();
} }
catch(const VExceptionBadId &) catch (const VExceptionBadId &)
{ {
pos = labelData.GetPos(); pos = labelData.GetPos();
} }
@ -182,12 +182,12 @@ auto FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat
* @param dAng angle of rotation * @param dAng angle of rotation
* @return position of point pt after rotating it around the center for dAng radians * @return position of point pt after rotating it around the center for dAng radians
*/ */
auto RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) -> QPointF auto RotatePoint(const QPointF &ptCenter, const QPointF &pt, qreal dAng) -> QPointF
{ {
QPointF ptDest; QPointF ptDest;
QPointF ptRel = pt - ptCenter; QPointF ptRel = pt - ptCenter;
ptDest.setX(cos(dAng)*ptRel.x() - sin(dAng)*ptRel.y()); ptDest.setX(cos(dAng) * ptRel.x() - sin(dAng) * ptRel.y());
ptDest.setY(sin(dAng)*ptRel.x() + cos(dAng)*ptRel.y()); ptDest.setY(sin(dAng) * ptRel.x() + cos(dAng) * ptRel.y());
return ptDest + ptCenter; return ptDest + ptCenter;
} }
@ -214,7 +214,7 @@ auto ConvertPlaceLabels(const VPiece &piece, const VContainer *pattern) -> QVect
QVector<VLayoutPlaceLabel> labels; QVector<VLayoutPlaceLabel> labels;
const auto placeLabels = piece.GetPlaceLabels(); const auto placeLabels = piece.GetPlaceLabels();
labels.reserve(placeLabels.size()); labels.reserve(placeLabels.size());
for(const auto &placeLabel : placeLabels) for (const auto &placeLabel : placeLabels)
{ {
const auto label = pattern->GeometricObject<VPlaceLabelItem>(placeLabel); const auto label = pattern->GeometricObject<VPlaceLabelItem>(placeLabel);
if (label->IsVisible()) if (label->IsVisible())
@ -232,75 +232,7 @@ auto ConvertPlaceLabels(const VPiece &piece, const VContainer *pattern) -> QVect
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto PrepareSAPassmark(const VPiece &piece, const VContainer *pattern, const VPassmark &passmark, auto PrepareSAPassmark(const VPiece &piece, const VContainer *pattern, const VPassmark &passmark, PassmarkSide side,
PassmarkSide side, bool &ok) -> VLayoutPassmark
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wnoexcept")
// noexcept-expression evaluates to 'false' because of a call to 'constexpr QPointF::QPointF()'
VLayoutPassmark layoutPassmark;
QT_WARNING_POP
VPiecePassmarkData pData = passmark.Data();
const QVector<VPieceNode> path = piece.GetUnitedPath(pattern);
const int nodeIndex = VPiecePath::indexOfNode(path, pData.id);
if (nodeIndex == -1)
{
const QString errorMsg =
QObject::tr("Passmark '%1' is not part of piece '%2'.")
.arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false;
return {};
}
QVector<QLineF> baseLines = passmark.SAPassmarkBaseLine(piece, pattern, static_cast<PassmarkSide>(side));
if (baseLines.isEmpty())
{
const QString errorMsg =
QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark base line is empty.")
.arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false;
return {};
}
if (side == PassmarkSide::All || side == PassmarkSide::Right)
{
layoutPassmark.baseLine = ConstFirst(baseLines);
}
else if (side == PassmarkSide::Right)
{
layoutPassmark.baseLine = ConstLast(baseLines);
}
const QVector<QLineF> lines = passmark.SAPassmark(piece, pattern, side);
if (lines.isEmpty())
{
const QString errorMsg =
QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark is empty.")
.arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false;
return {};
}
layoutPassmark.lines = lines;
layoutPassmark.type = pData.passmarkLineType;
layoutPassmark.isBuiltIn = false;
layoutPassmark.isClockwiseOpening = pData.passmarkSAPoint.IsPassmarkClockwiseOpening();
ok = true;
return layoutPassmark;
}
//---------------------------------------------------------------------------------------------------------------------
auto PreapreBuiltInSAPassmark(const VPiece &piece, const VContainer *pattern, const VPassmark &passmark,
bool &ok) -> VLayoutPassmark bool &ok) -> VLayoutPassmark
{ {
QT_WARNING_PUSH QT_WARNING_PUSH
@ -317,10 +249,79 @@ auto PreapreBuiltInSAPassmark(const VPiece &piece, const VContainer *pattern, co
if (nodeIndex == -1) if (nodeIndex == -1)
{ {
const QString errorMsg = const QString errorMsg =
QObject::tr("Passmark '%1' is not part of piece '%2'.") QObject::tr("Passmark '%1' is not part of piece '%2'.").arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false;
return {};
}
QVector<QLineF> baseLines = passmark.SAPassmarkBaseLine(piece, pattern, static_cast<PassmarkSide>(side));
if (baseLines.isEmpty())
{
const QString errorMsg =
QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark base line is empty.")
.arg(pData.nodeName, piece.GetName()); .arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false;
return {};
}
if (side == PassmarkSide::All || side == PassmarkSide::Right)
{
layoutPassmark.baseLine = ConstFirst(baseLines);
}
else if (side == PassmarkSide::Right)
{
layoutPassmark.baseLine = ConstLast(baseLines);
}
const QVector<QLineF> lines = passmark.SAPassmark(piece, pattern, side);
if (lines.isEmpty())
{
const QString errorMsg = QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark is empty.")
.arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false;
return {};
}
layoutPassmark.lines = lines;
layoutPassmark.type = pData.passmarkLineType;
layoutPassmark.isBuiltIn = false;
layoutPassmark.isClockwiseOpening = pData.passmarkSAPoint.IsPassmarkClockwiseOpening();
ok = true;
return layoutPassmark;
}
//---------------------------------------------------------------------------------------------------------------------
auto PreapreBuiltInSAPassmark(const VPiece &piece, const VContainer *pattern, const VPassmark &passmark, bool &ok)
-> VLayoutPassmark
{
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wnoexcept")
// noexcept-expression evaluates to 'false' because of a call to 'constexpr QPointF::QPointF()'
VLayoutPassmark layoutPassmark;
QT_WARNING_POP
VPiecePassmarkData pData = passmark.Data();
const QVector<VPieceNode> path = piece.GetUnitedPath(pattern);
const int nodeIndex = VPiecePath::indexOfNode(path, pData.id);
if (nodeIndex == -1)
{
const QString errorMsg =
QObject::tr("Passmark '%1' is not part of piece '%2'.").arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false; ok = false;
return {}; return {};
} }
@ -328,11 +329,11 @@ auto PreapreBuiltInSAPassmark(const VPiece &piece, const VContainer *pattern, co
const QVector<QLineF> lines = passmark.BuiltInSAPassmark(piece, pattern); const QVector<QLineF> lines = passmark.BuiltInSAPassmark(piece, pattern);
if (lines.isEmpty()) if (lines.isEmpty())
{ {
const QString errorMsg = const QString errorMsg = QObject::tr("Cannot prepare builtin passmark '%1' for piece '%2'. Passmark is empty.")
QObject::tr("Cannot prepare builtin passmark '%1' for piece '%2'. Passmark is empty.")
.arg(pData.nodeName, piece.GetName()); .arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false; ok = false;
return {}; return {};
} }
@ -346,13 +347,14 @@ auto PreapreBuiltInSAPassmark(const VPiece &piece, const VContainer *pattern, co
QObject::tr("Cannot prepare builtin passmark '%1' for piece '%2'. Passmark base line is " QObject::tr("Cannot prepare builtin passmark '%1' for piece '%2'. Passmark base line is "
"empty.") "empty.")
.arg(pData.nodeName, piece.GetName()); .arg(pData.nodeName, piece.GetName());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : VAbstractApplication::VApp()->IsPedantic()
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; ? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
ok = false; ok = false;
return {}; return {};
} }
layoutPassmark.baseLine = ConstFirst (baseLines); layoutPassmark.baseLine = ConstFirst(baseLines);
layoutPassmark.type = pData.passmarkLineType; layoutPassmark.type = pData.passmarkLineType;
layoutPassmark.isBuiltIn = true; layoutPassmark.isBuiltIn = true;
layoutPassmark.isClockwiseOpening = pData.passmarkSAPoint.IsPassmarkClockwiseOpening(); layoutPassmark.isClockwiseOpening = pData.passmarkSAPoint.IsPassmarkClockwiseOpening();
@ -368,7 +370,7 @@ auto ConvertPassmarks(const VPiece &piece, const VContainer *pattern) -> QVector
QVector<VLayoutPassmark> layoutPassmarks; QVector<VLayoutPassmark> layoutPassmarks;
layoutPassmarks.reserve(passmarks.size()); layoutPassmarks.reserve(passmarks.size());
for(const auto &passmark : passmarks) for (const auto &passmark : passmarks)
{ {
if (passmark.IsNull()) if (passmark.IsNull())
{ {
@ -403,7 +405,7 @@ auto ConvertPassmarks(const VPiece &piece, const VContainer *pattern) -> QVector
VPiecePassmarkData pData = passmark.Data(); VPiecePassmarkData pData = passmark.Data();
switch(pData.passmarkAngleType) switch (pData.passmarkAngleType)
{ {
case PassmarkAngleType::Straightforward: case PassmarkAngleType::Straightforward:
case PassmarkAngleType::Bisector: case PassmarkAngleType::Bisector:
@ -426,17 +428,14 @@ auto ConvertPassmarks(const VPiece &piece, const VContainer *pattern) -> QVector
break; break;
} }
if (VAbstractApplication::VApp()->Settings()->IsDoublePassmark() if (VAbstractApplication::VApp()->Settings()->IsDoublePassmark() &&
&& (VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() || (VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() || not piece.IsHideMainPath()) &&
not piece.IsHideMainPath()) pData.isMainPathNode && pData.passmarkAngleType != PassmarkAngleType::Intersection &&
&& pData.isMainPathNode pData.passmarkAngleType != PassmarkAngleType::IntersectionOnlyLeft &&
&& pData.passmarkAngleType != PassmarkAngleType::Intersection pData.passmarkAngleType != PassmarkAngleType::IntersectionOnlyRight &&
&& pData.passmarkAngleType != PassmarkAngleType::IntersectionOnlyLeft pData.passmarkAngleType != PassmarkAngleType::Intersection2 &&
&& pData.passmarkAngleType != PassmarkAngleType::IntersectionOnlyRight pData.passmarkAngleType != PassmarkAngleType::Intersection2OnlyLeft &&
&& pData.passmarkAngleType != PassmarkAngleType::Intersection2 pData.passmarkAngleType != PassmarkAngleType::Intersection2OnlyRight && pData.isShowSecondPassmark)
&& pData.passmarkAngleType != PassmarkAngleType::Intersection2OnlyLeft
&& pData.passmarkAngleType != PassmarkAngleType::Intersection2OnlyRight
&& pData.isShowSecondPassmark)
{ {
AddBuiltInPassmark(); AddBuiltInPassmark();
} }
@ -487,7 +486,7 @@ auto PrepareGradationPlaceholders(const VContainer *data) -> QMap<QString, QStri
} }
{ {
const QMap<QString, QSharedPointer<VMeasurement> > measurements = data->DataMeasurements(); const QMap<QString, QSharedPointer<VMeasurement>> measurements = data->DataMeasurements();
auto i = measurements.constBegin(); auto i = measurements.constBegin();
while (i != measurements.constEnd()) while (i != measurements.constEnd())
{ {
@ -506,7 +505,7 @@ auto ReplacePlaceholders(const QMap<QString, QString> &placeholders, QString lin
auto TestDimension = [per, placeholders, line](const QString &placeholder, const QString &errorMsg) auto TestDimension = [per, placeholders, line](const QString &placeholder, const QString &errorMsg)
{ {
if (line.contains(per+placeholder+per) && placeholders.value(placeholder) == QChar('0')) if (line.contains(per + placeholder + per) && placeholders.value(placeholder) == QChar('0'))
{ {
VAbstractApplication::VApp()->IsPedantic() VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg) ? throw VException(errorMsg)
@ -527,7 +526,7 @@ auto ReplacePlaceholders(const QMap<QString, QString> &placeholders, QString lin
auto i = placeholders.constBegin(); auto i = placeholders.constBegin();
while (i != placeholders.constEnd()) while (i != placeholders.constEnd())
{ {
line.replace(per+i.key()+per, i.value()); line.replace(per + i.key() + per, i.value());
++i; ++i;
} }
return line; return line;
@ -586,18 +585,21 @@ auto operator>>(QDataStream &dataStream, VLayoutPiece &piece) -> QDataStream &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutPiece::VLayoutPiece() VLayoutPiece::VLayoutPiece()
:d(new VLayoutPieceData) : d(new VLayoutPieceData)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutPiece::VLayoutPiece(const VLayoutPiece &detail) // NOLINT(modernize-use-equals-default) VLayoutPiece::VLayoutPiece(const VLayoutPiece &detail) // NOLINT(modernize-use-equals-default)
:VAbstractPiece(detail), d(detail.d) : VAbstractPiece(detail),
{} d(detail.d)
{
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::operator=(const VLayoutPiece &detail) -> VLayoutPiece & auto VLayoutPiece::operator=(const VLayoutPiece &detail) -> VLayoutPiece &
{ {
if ( &detail == this ) if (&detail == this)
{ {
return *this; return *this;
} }
@ -608,12 +610,13 @@ auto VLayoutPiece::operator=(const VLayoutPiece &detail) -> VLayoutPiece &
#ifdef Q_COMPILER_RVALUE_REFS #ifdef Q_COMPILER_RVALUE_REFS
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutPiece::VLayoutPiece(VLayoutPiece &&detail) Q_DECL_NOTHROW VLayoutPiece::VLayoutPiece(VLayoutPiece &&detail) Q_DECL_NOTHROW : VAbstractPiece(std::move(detail)),
:VAbstractPiece(std::move(detail)), d(std::move(detail.d)) d(std::move(detail.d))
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::operator=(VLayoutPiece &&detail) Q_DECL_NOTHROW -> VLayoutPiece & auto VLayoutPiece::operator=(VLayoutPiece &&detail) Q_DECL_NOTHROW->VLayoutPiece &
{ {
VAbstractPiece::operator=(detail); VAbstractPiece::operator=(detail);
std::swap(d, detail.d); std::swap(d, detail.d);
@ -622,21 +625,22 @@ auto VLayoutPiece::operator=(VLayoutPiece &&detail) Q_DECL_NOTHROW -> VLayoutPie
#endif #endif
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutPiece::~VLayoutPiece() //NOLINT(modernize-use-equals-default) VLayoutPiece::~VLayoutPiece() // NOLINT(modernize-use-equals-default)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContainer *pattern) -> VLayoutPiece auto VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContainer *pattern) -> VLayoutPiece
{ {
QFuture<QVector<VLayoutPoint> > futureSeamAllowance = QFuture<QVector<VLayoutPoint>> futureSeamAllowance =
QtConcurrent::run([piece, pattern](){return piece.SeamAllowancePoints(pattern);}); QtConcurrent::run([piece, pattern]() { return piece.SeamAllowancePoints(pattern); });
QFuture<bool> futureSeamAllowanceValid = QFuture<bool> futureSeamAllowanceValid =
QtConcurrent::run([piece, pattern](){return piece.IsSeamAllowanceValid(pattern);}); QtConcurrent::run([piece, pattern]() { return piece.IsSeamAllowanceValid(pattern); });
QFuture<QVector<VLayoutPoint> > futureMainPath = QFuture<QVector<VLayoutPoint>> futureMainPath =
QtConcurrent::run([piece, pattern](){return piece.MainPathPoints(pattern);}); QtConcurrent::run([piece, pattern]() { return piece.MainPathPoints(pattern); });
QFuture<QVector<VLayoutPiecePath> > futureInternalPaths = QtConcurrent::run(ConvertInternalPaths, piece, pattern); QFuture<QVector<VLayoutPiecePath>> futureInternalPaths = QtConcurrent::run(ConvertInternalPaths, piece, pattern);
QFuture<QVector<VLayoutPassmark> > futurePassmarks = QtConcurrent::run(ConvertPassmarks, piece, pattern); QFuture<QVector<VLayoutPassmark>> futurePassmarks = QtConcurrent::run(ConvertPassmarks, piece, pattern);
QFuture<QVector<VLayoutPlaceLabel> > futurePlaceLabels = QtConcurrent::run(ConvertPlaceLabels, piece, pattern); QFuture<QVector<VLayoutPlaceLabel>> futurePlaceLabels = QtConcurrent::run(ConvertPlaceLabels, piece, pattern);
VLayoutPiece det; VLayoutPiece det;
@ -655,14 +659,14 @@ auto VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContainer *pat
if (not futureSeamAllowanceValid.result()) if (not futureSeamAllowanceValid.result())
{ {
const QString errorMsg = QObject::tr("Piece '%1'. Seam allowance is not valid.") const QString errorMsg = QObject::tr("Piece '%1'. Seam allowance is not valid.").arg(piece.GetName());
.arg(piece.GetName()); VAbstractApplication::VApp()->IsPedantic()
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : ? throw VException(errorMsg)
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
} }
det.SetContourPoints(futureMainPath.result(), det.SetContourPoints(futureMainPath.result(), VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath()
VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() ? false ? false
: piece.IsHideMainPath()); : piece.IsHideMainPath());
det.SetSeamAllowancePoints(futureSeamAllowance.result(), piece.IsSeamAllowance(), piece.IsSeamAllowanceBuiltIn()); det.SetSeamAllowancePoints(futureSeamAllowance.result(), piece.IsSeamAllowance(), piece.IsSeamAllowanceBuiltIn());
det.SetInternalPaths(futureInternalPaths.result()); det.SetInternalPaths(futureInternalPaths.result());
@ -673,24 +677,24 @@ auto VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContainer *pat
// Very important to set main path first! // Very important to set main path first!
if (det.MappedContourPath().isEmpty()) if (det.MappedContourPath().isEmpty())
{ {
throw VException (tr("Piece %1 doesn't have shape.").arg(piece.GetName())); throw VException(tr("Piece %1 doesn't have shape.").arg(piece.GetName()));
} }
const VPieceLabelData& data = piece.GetPieceLabelData(); const VPieceLabelData &data = piece.GetPieceLabelData();
det.SetQuantity(data.GetQuantity()); det.SetQuantity(data.GetQuantity());
if (data.IsVisible()) if (data.IsVisible())
{ {
det.SetPieceText(piece.GetName(), data, VAbstractApplication::VApp()->Settings()->GetLabelFont(), pattern); det.SetPieceText(piece.GetName(), data, VAbstractApplication::VApp()->Settings()->GetLabelFont(), pattern);
} }
const VPatternLabelData& geom = piece.GetPatternLabelData(); const VPatternLabelData &geom = piece.GetPatternLabelData();
if (geom.IsVisible()) if (geom.IsVisible())
{ {
VAbstractPattern* pDoc = VAbstractValApplication::VApp()->getCurrentDocument(); VAbstractPattern *pDoc = VAbstractValApplication::VApp()->getCurrentDocument();
det.SetPatternInfo(pDoc, geom, VAbstractApplication::VApp()->Settings()->GetLabelFont(), pattern); det.SetPatternInfo(pDoc, geom, VAbstractApplication::VApp()->Settings()->GetLabelFont(), pattern);
} }
const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry(); const VGrainlineData &grainlineGeom = piece.GetGrainlineGeometry();
if (grainlineGeom.IsVisible()) if (grainlineGeom.IsVisible())
{ {
det.SetGrainline(grainlineGeom, pattern); det.SetGrainline(grainlineGeom, pattern);
@ -713,8 +717,7 @@ auto VLayoutPiece::GetUniqueID() const -> QString
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <class T> template <class T> auto VLayoutPiece::Map(QVector<T> points) const -> QVector<T>
auto VLayoutPiece::Map(QVector<T> points) const -> QVector<T>
{ {
std::transform(points.begin(), points.end(), points.begin(), std::transform(points.begin(), points.end(), points.begin(),
[this](const T &point) { return d->m_matrix.map(point); }); [this](const T &point) { return d->m_matrix.map(point); });
@ -729,7 +732,7 @@ auto VLayoutPiece::Map(QVector<T> points) const -> QVector<T>
template <> // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) template <> // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name)
auto VLayoutPiece::Map<VLayoutPassmark>(QVector<VLayoutPassmark> passmarks) const -> QVector<VLayoutPassmark> auto VLayoutPiece::Map<VLayoutPassmark>(QVector<VLayoutPassmark> passmarks) const -> QVector<VLayoutPassmark>
{ {
for (auto & passmark : passmarks) for (auto &passmark : passmarks)
{ {
passmark.lines = Map(passmark.lines); passmark.lines = Map(passmark.lines);
passmark.baseLine = d->m_matrix.map(passmark.baseLine); passmark.baseLine = d->m_matrix.map(passmark.baseLine);
@ -739,10 +742,10 @@ auto VLayoutPiece::Map<VLayoutPassmark>(QVector<VLayoutPassmark> passmarks) cons
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <> template <> auto VLayoutPiece::Map<VLayoutPoint>(QVector<VLayoutPoint> points) const -> QVector<VLayoutPoint>
auto VLayoutPiece::Map<VLayoutPoint>(QVector<VLayoutPoint> points) const -> QVector<VLayoutPoint>
{ {
std::transform(points.begin(), points.end(), points.begin(), [this](VLayoutPoint point) std::transform(points.begin(), points.end(), points.begin(),
[this](VLayoutPoint point)
{ {
auto p = static_cast<QPointF>(point); // NOLINT(cppcoreguidelines-slicing) auto p = static_cast<QPointF>(point); // NOLINT(cppcoreguidelines-slicing)
p = d->m_matrix.map(p); p = d->m_matrix.map(p);
@ -818,7 +821,7 @@ void VLayoutPiece::SetSeamAllowancePoints(const QVector<VLayoutPoint> &points, b
} }
else if (not IsSeamAllowanceBuiltIn()) else if (not IsSeamAllowanceBuiltIn())
{ {
qWarning()<<"Seam allowance is empty."; qWarning() << "Seam allowance is empty.";
SetSeamAllowance(false); SetSeamAllowance(false);
} }
} }
@ -854,7 +857,7 @@ auto VLayoutPiece::GetPieceText() const -> QStringList
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::SetPieceText(const QString& qsName, const VPieceLabelData& data, const QFont &font, void VLayoutPiece::SetPieceText(const QString &qsName, const VPieceLabelData &data, const QFont &font,
const VContainer *pattern) const VContainer *pattern)
{ {
QPointF ptPos; QPointF ptPos;
@ -866,14 +869,12 @@ void VLayoutPiece::SetPieceText(const QString& qsName, const VPieceLabelData& da
return; return;
} }
QVector<QPointF> v; QVector<QPointF> v{ptPos, QPointF(ptPos.x() + labelWidth, ptPos.y()),
v << ptPos QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight),
<< QPointF(ptPos.x() + labelWidth, ptPos.y()) QPointF(ptPos.x(), ptPos.y() + labelHeight)};
<< QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight)
<< QPointF(ptPos.x(), ptPos.y() + labelHeight);
const qreal dAng = qDegreesToRadians(-labelAngle); const qreal dAng = qDegreesToRadians(-labelAngle);
const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); const QPointF ptCenter(ptPos.x() + labelWidth / 2, ptPos.y() + labelHeight / 2);
for (int i = 0; i < v.count(); ++i) for (int i = 0; i < v.count(); ++i)
{ {
@ -885,11 +886,15 @@ void VLayoutPiece::SetPieceText(const QString& qsName, const VPieceLabelData& da
// generate text // generate text
d->m_tmDetail.SetFont(font); d->m_tmDetail.SetFont(font);
d->m_tmDetail.SetFontSize(data.GetFontSize());
int fntSize = data.GetFontSize();
if (fntSize == 0)
{
fntSize = VAbstractApplication::VApp()->Settings()->GetPieceLabelFontPointSize();
}
d->m_tmDetail.SetFontSize(fntSize);
d->m_tmDetail.Update(qsName, data, pattern); d->m_tmDetail.Update(qsName, data, pattern);
// this will generate the lines of text
d->m_tmDetail.SetFontSize(data.GetFontSize());
d->m_tmDetail.FitFontSize(labelWidth, labelHeight);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -934,7 +939,7 @@ auto VLayoutPiece::GetPatternText() const -> QStringList
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::SetPatternInfo(VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font, void VLayoutPiece::SetPatternInfo(VAbstractPattern *pDoc, const VPatternLabelData &geom, const QFont &font,
const VContainer *pattern) const VContainer *pattern)
{ {
QPointF ptPos; QPointF ptPos;
@ -946,14 +951,12 @@ void VLayoutPiece::SetPatternInfo(VAbstractPattern* pDoc, const VPatternLabelDat
return; return;
} }
QVector<QPointF> v; QVector<QPointF> v{ptPos, QPointF(ptPos.x() + labelWidth, ptPos.y()),
v << ptPos QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight),
<< QPointF(ptPos.x() + labelWidth, ptPos.y()) QPointF(ptPos.x(), ptPos.y() + labelHeight)};
<< QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight)
<< QPointF(ptPos.x(), ptPos.y() + labelHeight);
const qreal dAng = qDegreesToRadians(-labelAngle); const qreal dAng = qDegreesToRadians(-labelAngle);
const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); const QPointF ptCenter(ptPos.x() + labelWidth / 2, ptPos.y() + labelHeight / 2);
for (int i = 0; i < v.count(); ++i) for (int i = 0; i < v.count(); ++i)
{ {
v[i] = RotatePoint(ptCenter, v.at(i), dAng); v[i] = RotatePoint(ptCenter, v.at(i), dAng);
@ -963,13 +966,15 @@ void VLayoutPiece::SetPatternInfo(VAbstractPattern* pDoc, const VPatternLabelDat
// Generate text // Generate text
d->m_tmPattern.SetFont(font); d->m_tmPattern.SetFont(font);
d->m_tmPattern.SetFontSize(geom.GetFontSize());
int fntSize = geom.GetFontSize();
if (fntSize == 0)
{
fntSize = VAbstractApplication::VApp()->Settings()->GetPieceLabelFontPointSize();
}
d->m_tmPattern.SetFontSize(fntSize);
d->m_tmPattern.Update(pDoc, pattern); d->m_tmPattern.Update(pDoc, pattern);
// generate lines of text
d->m_tmPattern.SetFontSize(geom.GetFontSize());
d->m_tmPattern.FitFontSize(labelWidth, labelHeight);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1003,7 +1008,7 @@ void VLayoutPiece::SetGrainline(const VPieceGrainline &grainline)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer* pattern) void VLayoutPiece::SetGrainline(const VGrainlineData &geom, const VContainer *pattern)
{ {
QScopedPointer<QGraphicsItem> item(GetMainPathItem()); QScopedPointer<QGraphicsItem> item(GetMainPathItem());
@ -1154,13 +1159,13 @@ void VLayoutPiece::Mirror(const QLineF &edge)
m.reset(); m.reset();
m.translate(p2.x(), p2.y()); m.translate(p2.x(), p2.y());
m.scale(m.m11(), m.m22()*-1); m.scale(m.m11(), m.m22() * -1);
m.translate(-p2.x(), -p2.y()); m.translate(-p2.x(), -p2.y());
d->m_matrix *= m; d->m_matrix *= m;
m.reset(); m.reset();
m.translate(p2.x(), p2.y()); m.translate(p2.x(), p2.y());
m.rotate(-(360-angle)); m.rotate(-(360 - angle));
m.translate(-p2.x(), -p2.y()); m.translate(-p2.x(), -p2.y());
d->m_matrix *= m; d->m_matrix *= m;
@ -1235,7 +1240,7 @@ auto VLayoutPiece::isNull() const -> bool
{ {
if (not d->m_contour.isEmpty() && d->m_layoutWidth > 0) if (not d->m_contour.isEmpty() && d->m_layoutWidth > 0)
{ {
return not (IsSeamAllowance() && not IsSeamAllowanceBuiltIn() && not d->m_seamAllowance.isEmpty()); return not(IsSeamAllowance() && not IsSeamAllowanceBuiltIn() && not d->m_seamAllowance.isEmpty());
} }
return true; return true;
} }
@ -1264,7 +1269,7 @@ void VLayoutPiece::SetLayoutAllowancePoints()
QVector<QPointF> points; QVector<QPointF> points;
CastTo(GetSeamAllowancePoints(), points); CastTo(GetSeamAllowancePoints(), points);
d->m_square = qFloor(qAbs(SumTrapezoids(points)/2.0)); d->m_square = qFloor(qAbs(SumTrapezoids(points) / 2.0));
} }
} }
else else
@ -1278,7 +1283,7 @@ void VLayoutPiece::SetLayoutAllowancePoints()
QVector<QPointF> points; QVector<QPointF> points;
CastTo(GetContourPoints(), points); CastTo(GetContourPoints(), points);
d->m_square = qFloor(qAbs(SumTrapezoids(points)/2.0)); d->m_square = qFloor(qAbs(SumTrapezoids(points) / 2.0));
} }
} }
} }
@ -1291,15 +1296,14 @@ void VLayoutPiece::SetLayoutAllowancePoints()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::GetMappedExternalContourPoints() const -> QVector<VLayoutPoint> auto VLayoutPiece::GetMappedExternalContourPoints() const -> QVector<VLayoutPoint>
{ {
return IsSeamAllowance() && not IsSeamAllowanceBuiltIn() ? GetMappedSeamAllowancePoints() : return IsSeamAllowance() && not IsSeamAllowanceBuiltIn() ? GetMappedSeamAllowancePoints()
GetMappedContourPoints(); : GetMappedContourPoints();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::GetExternalContourPoints() const -> QVector<VLayoutPoint> auto VLayoutPiece::GetExternalContourPoints() const -> QVector<VLayoutPoint>
{ {
return IsSeamAllowance() && not IsSeamAllowanceBuiltIn() ? GetSeamAllowancePoints() : return IsSeamAllowance() && not IsSeamAllowanceBuiltIn() ? GetSeamAllowancePoints() : GetContourPoints();
GetContourPoints();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1336,9 +1340,9 @@ void VLayoutPiece::SetPlaceLabels(const QVector<VLayoutPlaceLabel> &labels)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::MappedInternalPathsForCut(bool cut) const -> QVector<QVector<VLayoutPoint> > auto VLayoutPiece::MappedInternalPathsForCut(bool cut) const -> QVector<QVector<VLayoutPoint>>
{ {
QVector<QVector<VLayoutPoint> > paths; QVector<QVector<VLayoutPoint>> paths;
paths.reserve(d->m_internalPaths.size()); paths.reserve(d->m_internalPaths.size());
for (const auto &path : d->m_internalPaths) for (const auto &path : d->m_internalPaths)
@ -1391,7 +1395,7 @@ auto VLayoutPiece::ContourPath() const -> QPainterPath
if (ConstLast(points).toPoint() != ConstFirst(points).toPoint()) if (ConstLast(points).toPoint() != ConstFirst(points).toPoint())
{ {
points.append(points.at(0));// Should be always closed points.append(points.at(0)); // Should be always closed
} }
QPainterPath ekv; QPainterPath ekv;
@ -1407,7 +1411,7 @@ auto VLayoutPiece::ContourPath() const -> QPainterPath
// Draw passmarks // Draw passmarks
QPainterPath passmaksPath; QPainterPath passmaksPath;
const QVector<VLayoutPassmark> passmarks = GetPassmarks(); const QVector<VLayoutPassmark> passmarks = GetPassmarks();
for(const auto &passmark : passmarks) for (const auto &passmark : passmarks)
{ {
for (const auto &line : passmark.lines) for (const auto &line : passmark.lines)
{ {
@ -1462,7 +1466,7 @@ auto VLayoutPiece::GetItem(bool textAsPaths) const -> QGraphicsItem *
for (const auto &path : d->m_internalPaths) for (const auto &path : d->m_internalPaths)
{ {
auto* pathItem = new QGraphicsPathItem(item); auto *pathItem = new QGraphicsPathItem(item);
pathItem->setPath(d->m_matrix.map(path.GetPainterPath())); pathItem->setPath(d->m_matrix.map(path.GetPainterPath()));
QPen pen = pathItem->pen(); QPen pen = pathItem->pen();
@ -1473,7 +1477,7 @@ auto VLayoutPiece::GetItem(bool textAsPaths) const -> QGraphicsItem *
for (const auto &label : d->m_placeLabels) for (const auto &label : d->m_placeLabels)
{ {
auto* pathItem = new QGraphicsPathItem(item); auto *pathItem = new QGraphicsPathItem(item);
QPen pen = pathItem->pen(); QPen pen = pathItem->pen();
pen.setWidthF(VAbstractApplication::VApp()->Settings()->WidthHairLine()); pen.setWidthF(VAbstractApplication::VApp()->Settings()->WidthHairLine());
pathItem->setPen(pen); pathItem->setPen(pen);
@ -1490,8 +1494,8 @@ auto VLayoutPiece::GetItem(bool textAsPaths) const -> QGraphicsItem *
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::IsLayoutAllowanceValid() const -> bool auto VLayoutPiece::IsLayoutAllowanceValid() const -> bool
{ {
QVector<VLayoutPoint> base = (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) ? QVector<VLayoutPoint> base =
d->m_seamAllowance : d->m_contour; (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) ? d->m_seamAllowance : d->m_contour;
QVector<QPointF> points; QVector<QPointF> points;
CastTo(base, points); CastTo(base, points);
return VAbstractPiece::IsAllowanceValid(points, d->m_layoutAllowance); return VAbstractPiece::IsAllowanceValid(points, d->m_layoutAllowance);
@ -1519,11 +1523,10 @@ auto VLayoutPiece::BiggestEdge() const -> qreal
return edge; return edge;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VLayoutPiece::MapPlaceLabelShape(PlaceLabelImg shape) const -> PlaceLabelImg auto VLayoutPiece::MapPlaceLabelShape(PlaceLabelImg shape) const -> PlaceLabelImg
{ {
for (auto & i : shape) for (auto &i : shape)
{ {
i = Map(i); i = Map(i);
} }
@ -1556,8 +1559,8 @@ auto VLayoutPiece::GrainlinePath(const GrainlineShape &shape) -> QPainterPath
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPointF> &labelShape, void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPointF> &labelShape, const VTextManager &tm,
const VTextManager &tm, bool textAsPaths) const bool textAsPaths) const
{ {
SCASSERT(parent != nullptr) SCASSERT(parent != nullptr)
@ -1568,14 +1571,15 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPoin
const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length(); const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length();
const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length(); const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length();
const qreal angle = - QLineF(labelShape.at(0), labelShape.at(1)).angle(); const qreal angle = -QLineF(labelShape.at(0), labelShape.at(1)).angle();
qreal dY = 0; qreal dY = 0;
for (int i = 0; i < tm.GetSourceLinesCount(); ++i) const QVector<TextLine> labelLines = tm.GetLabelSourceLines(qFloor(dW), tm.GetFont());
for (const auto &tl : labelLines)
{ {
const TextLine& tl = tm.GetSourceLine(i);
QFont fnt = tm.GetFont(); QFont fnt = tm.GetFont();
fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize); fnt.setPointSize(tm.GetFont().pointSize() + tl.m_iFontSize);
fnt.setBold(tl.m_bold); fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);
@ -1584,19 +1588,21 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPoin
if (textAsPaths) if (textAsPaths)
{ {
dY += fm.height(); dY += fm.height();
}
if (dY > dH) if (dY > dH)
{ {
break; break;
} }
}
QString qsText = tl.m_qsText; else
if (TextWidth(fm, qsText) > dW)
{ {
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW)); if (dY + fm.height() > dH)
{
break;
}
} }
QString qsText = tl.m_qsText;
qreal dX = 0; qreal dX = 0;
if (tl.m_eAlign == 0 || (tl.m_eAlign & Qt::AlignLeft) > 0) if (tl.m_eAlign == 0 || (tl.m_eAlign & Qt::AlignLeft) > 0)
{ {
@ -1604,7 +1610,7 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPoin
} }
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
{ {
dX = (dW - TextWidth(fm, qsText))/2; dX = (dW - TextWidth(fm, qsText)) / 2;
} }
else if ((tl.m_eAlign & Qt::AlignRight) > 0) else if ((tl.m_eAlign & Qt::AlignRight) > 0)
{ {
@ -1632,9 +1638,9 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPoin
if (textAsPaths) if (textAsPaths)
{ {
QPainterPath path; QPainterPath path;
path.addText(0, - static_cast<qreal>(fm.ascent())/6., fnt, qsText); path.addText(0, -static_cast<qreal>(fm.ascent()) / 6., fnt, qsText);
auto* item = new QGraphicsPathItem(parent); auto *item = new QGraphicsPathItem(parent);
item->setPath(path); item->setPath(path);
item->setBrush(QBrush(Qt::black)); item->setBrush(QBrush(Qt::black));
item->setTransform(labelMatrix); item->setTransform(labelMatrix);
@ -1643,7 +1649,7 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPoin
} }
else else
{ {
auto* item = new QGraphicsSimpleTextItem(parent); auto *item = new QGraphicsSimpleTextItem(parent);
item->setFont(fnt); item->setFont(fnt);
item->setText(qsText); item->setText(qsText);
item->setTransform(labelMatrix); item->setTransform(labelMatrix);
@ -1772,12 +1778,12 @@ auto VLayoutPiece::Edge(const QVector<QPointF> &path, int i) const -> QLineF
vsizetype i1, i2; vsizetype i1, i2;
if (i < path.count()) if (i < path.count())
{ {
i1 = i-1; i1 = i - 1;
i2 = i; i2 = i;
} }
else else
{ {
i1 = path.count()-1; i1 = path.count() - 1;
i2 = 0; i2 = 0;
} }
@ -1799,7 +1805,7 @@ auto VLayoutPiece::EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1)
const QVector<QPointF> points = Map(path); const QVector<QPointF> points = Map(path);
auto posIter = std::find_if(points.cbegin(), points.cend(), auto posIter = std::find_if(points.cbegin(), points.cend(),
[&p1](const QPointF &point){ return VFuzzyComparePoints(point, p1); }); [&p1](const QPointF &point) { return VFuzzyComparePoints(point, p1); });
if (posIter != points.cend()) if (posIter != points.cend())
{ {
return static_cast<int>(posIter - points.cbegin() + 1); return static_cast<int>(posIter - points.cbegin() + 1);

View file

@ -38,7 +38,9 @@
#include <QtMath> #include <QtMath>
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vmisc/compatibility.h"
#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vabstractvalapplication.h"
#include "../vmisc/vcommonsettings.h"
#include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vpatterndb/floatItemData/vpiecelabeldata.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
@ -50,6 +52,49 @@
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "vtextmanager.h" #include "vtextmanager.h"
namespace
{
auto SplitTextByWidth(const QString &text, const QFont &font, int maxWidth) -> QStringList
{
QFontMetrics fontMetrics(font);
if (TextWidth(fontMetrics, text) <= maxWidth)
{
return {text};
}
QStringList substrings;
substrings.reserve(2);
const int textLength = static_cast<int>(text.length());
int lineWidth = 0;
for (int endIndex = 0; endIndex < textLength; ++endIndex)
{
QChar currentChar = text.at(endIndex);
const int charWidth = TextWidth(fontMetrics, currentChar);
if (lineWidth + charWidth > maxWidth)
{
if (endIndex > 0)
{
substrings.append(text.mid(0, endIndex));
}
if (endIndex < textLength)
{
substrings.append(text.mid(endIndex));
}
break;
}
lineWidth += charWidth;
}
return substrings;
}
} // namespace
const quint32 TextLine::streamHeader = 0xA3881E49; // CRC-32Q string "TextLine" const quint32 TextLine::streamHeader = 0xA3881E49; // CRC-32Q string "TextLine"
const quint16 TextLine::classVersion = 1; const quint16 TextLine::classVersion = 1;
@ -117,7 +162,7 @@ const quint16 VTextManager::classVersion = 1;
namespace namespace
{ {
Q_GLOBAL_STATIC(QVector<TextLine>, m_patternLabelLines) // NOLINT Q_GLOBAL_STATIC(QVector<TextLine>, m_patternLabelLinesCache) // NOLINT
} }
// Friend functions // Friend functions
@ -487,7 +532,9 @@ auto VTextManager::GetFont() const -> const QFont &
*/ */
void VTextManager::SetFontSize(int iFS) void VTextManager::SetFontSize(int iFS)
{ {
iFS < MIN_FONT_SIZE ? m_font.setPixelSize(MIN_FONT_SIZE) : m_font.setPixelSize(iFS); iFS < VCommonSettings::MinPieceLabelFontPointSize()
? m_font.setPointSize(VCommonSettings::MinPieceLabelFontPointSize())
: m_font.setPointSize(iFS);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -525,6 +572,40 @@ auto VTextManager::GetSourceLine(vsizetype i) const -> const TextLine &
return m_liLines.at(i); return m_liLines.at(i);
} }
//---------------------------------------------------------------------------------------------------------------------
auto VTextManager::GetLabelSourceLines(int width, const QFont &font) const -> QVector<TextLine>
{
QVector<TextLine> lines;
lines.reserve(m_liLines.size());
QFont fnt = font;
int fSize = m_font.pointSize();
for (const auto &tl : m_liLines)
{
fnt.setPointSize(fSize + tl.m_iFontSize);
fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic);
QString qsText = tl.m_qsText;
QFontMetrics fm(fnt);
if (TextWidth(fm, qsText) > width)
{
const QStringList brokeLines = BreakTextIntoLines(qsText, fnt, width);
for (const auto &lineText : brokeLines)
{
TextLine line = tl;
line.m_qsText = lineText;
lines.append(line);
}
}
else
{
lines.append(tl);
}
}
return lines;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VTextManager::MaxLineWidth(int width) const -> int auto VTextManager::MaxLineWidth(int width) const -> int
{ {
@ -534,7 +615,7 @@ auto VTextManager::MaxLineWidth(int width) const -> int
const TextLine &tl = m_liLines.at(i); const TextLine &tl = m_liLines.at(i);
QFont fnt = m_font; QFont fnt = m_font;
fnt.setPixelSize(fnt.pixelSize() + tl.m_iFontSize); fnt.setPointSize(fnt.pointSize() + tl.m_iFontSize);
fnt.setBold(tl.m_bold); fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic); fnt.setItalic(tl.m_italic);
@ -553,64 +634,6 @@ auto VTextManager::MaxLineWidth(int width) const -> int
return maxWidth; return maxWidth;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VTextManager::FitFontSize sets the font size just big enough, so that the text fits into rectangle of
* size (fW, fH)
* @param fW rectangle width
* @param fH rectangle height
*/
void VTextManager::FitFontSize(qreal fW, qreal fH)
{
int iFS = 0;
if (GetSourceLinesCount() > 0)
{ // division by zero
iFS = 3 * qFloor(fH / static_cast<int>(GetSourceLinesCount())) / 4;
}
if (iFS < MIN_FONT_SIZE)
{
iFS = MIN_FONT_SIZE;
}
// get ratio between char width and height
int iMaxLen = 0;
TextLine maxLine;
QFont fnt;
for (vsizetype i = 0; i < GetSourceLinesCount(); ++i)
{
const TextLine &tl = GetSourceLine(i);
fnt = m_font;
fnt.setPixelSize(iFS + tl.m_iFontSize);
fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic);
QFontMetrics fm(fnt);
const int iTW = TextWidth(fm, tl.m_qsText);
if (iTW > iMaxLen)
{
iMaxLen = iTW;
maxLine = tl;
}
}
if (iMaxLen > fW)
{
QFont fnt = m_font;
fnt.setBold(maxLine.m_bold);
fnt.setItalic(maxLine.m_italic);
int lineLength = 0;
do
{
--iFS;
fnt.setPixelSize(iFS + maxLine.m_iFontSize);
QFontMetrics fm(fnt);
lineLength = TextWidth(fm, maxLine.m_qsText);
} while (lineLength > fW && iFS > MIN_FONT_SIZE);
}
SetFontSize(iFS);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VTextManager::Update updates the text lines with detail data * @brief VTextManager::Update updates the text lines with detail data
@ -644,10 +667,10 @@ void VTextManager::Update(VAbstractPattern *pDoc, const VContainer *pattern)
{ {
m_liLines.clear(); m_liLines.clear();
if (m_patternLabelLines->isEmpty() || pDoc->GetPatternWasChanged()) if (m_patternLabelLinesCache->isEmpty() || pDoc->GetPatternWasChanged())
{ {
QVector<VLabelTemplateLine> lines = pDoc->GetPatternLabelTemplate(); QVector<VLabelTemplateLine> lines = pDoc->GetPatternLabelTemplate();
if (lines.isEmpty() && m_patternLabelLines->isEmpty()) if (lines.isEmpty() && m_patternLabelLinesCache->isEmpty())
{ {
return; // Nothing to parse return; // Nothing to parse
} }
@ -660,8 +683,98 @@ void VTextManager::Update(VAbstractPattern *pDoc, const VContainer *pattern)
} }
pDoc->SetPatternWasChanged(false); pDoc->SetPatternWasChanged(false);
*m_patternLabelLines = PrepareLines(lines); *m_patternLabelLinesCache = PrepareLines(lines);
} }
m_liLines = *m_patternLabelLines; m_liLines = *m_patternLabelLinesCache;
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextManager::BreakTextIntoLines(const QString &text, const QFont &font, int maxWidth) const -> QStringList
{
QFontMetrics fontMetrics(font);
QStringList words = text.split(' ');
QString currentLine;
int currentLineWidth = 0;
const int spaceWidth = TextWidth(fontMetrics, QChar(' '));
const float tolerance = 0.3F;
QStringList lines;
lines.reserve(words.size());
QMutableListIterator<QString> iterator(words);
auto AppendWord = [&currentLine, &currentLineWidth](const QString &word, int totalWidth)
{
if (!currentLine.isEmpty())
{
currentLine += QChar(' ');
}
currentLine += word;
currentLineWidth = totalWidth;
};
while (iterator.hasNext())
{
const QString &word = iterator.next();
int wordWidth = TextWidth(fontMetrics, word);
int totalWidth = !currentLine.isEmpty() ? currentLineWidth + spaceWidth + wordWidth : wordWidth;
if (totalWidth <= maxWidth)
{
// Append the word to the current line
AppendWord(word, totalWidth);
}
else if ((maxWidth - currentLineWidth) <= qRound(static_cast<float>(maxWidth) * tolerance) &&
maxWidth >= wordWidth)
{
// Start a new line with the word if it doesn't exceed the tolerance
lines.append(currentLine);
currentLine = word;
currentLineWidth = wordWidth;
}
else
{
// Word is too long, force line break
if (currentLineWidth + spaceWidth + TextWidth(fontMetrics, word.at(0)) > maxWidth)
{
lines.append(currentLine);
currentLine.clear();
currentLineWidth = 0;
}
const int subWordWidth = !currentLine.isEmpty() ? maxWidth - (currentLineWidth + spaceWidth) : maxWidth;
const QStringList subWords = SplitTextByWidth(word, font, subWordWidth);
if (subWords.isEmpty() || subWords.size() > 2)
{
AppendWord(word, totalWidth);
}
else
{
const int width = TextWidth(fontMetrics, ConstFirst(subWords));
const int tWidth = !currentLine.isEmpty() ? currentLineWidth + spaceWidth + width : width;
AppendWord(ConstFirst(subWords), tWidth);
lines.append(currentLine);
if (subWords.size() == 2)
{
currentLine.clear();
currentLineWidth = 0;
// Insert the item after the current item
iterator.insert(ConstLast(subWords));
iterator.previous();
}
}
}
}
// Add the last line
if (!currentLine.isEmpty())
{
lines.append(currentLine);
}
return lines;
} }

View file

@ -45,16 +45,13 @@ class VPieceLabelData;
class VAbstractPattern; class VAbstractPattern;
class VContainer; class VContainer;
#define MIN_FONT_SIZE 5
#define MAX_FONT_SIZE 128
/** /**
* @brief The TextLine struct holds the information about one text line * @brief The TextLine struct holds the information about one text line
*/ */
struct TextLine struct TextLine
{ {
QString m_qsText{}; QString m_qsText{};
int m_iFontSize{MIN_FONT_SIZE}; // 0 means default int m_iFontSize{0}; // 0 means default
bool m_bold{false}; bool m_bold{false};
bool m_italic{false}; bool m_italic{false};
Qt::Alignment m_eAlign{Qt::AlignCenter}; Qt::Alignment m_eAlign{Qt::AlignCenter};
@ -92,13 +89,14 @@ public:
void SetFont(const QFont &font); void SetFont(const QFont &font);
auto GetFont() const -> const QFont &; auto GetFont() const -> const QFont &;
void SetFontSize(int iFS); void SetFontSize(int iFS);
void FitFontSize(qreal fW, qreal fH);
auto GetAllSourceLines() const -> QVector<TextLine>; auto GetAllSourceLines() const -> QVector<TextLine>;
void SetAllSourceLines(const QVector<TextLine> &lines); void SetAllSourceLines(const QVector<TextLine> &lines);
auto GetSourceLinesCount() const -> vsizetype; auto GetSourceLinesCount() const -> vsizetype;
auto GetSourceLine(vsizetype i) const -> const TextLine &; auto GetSourceLine(vsizetype i) const -> const TextLine &;
auto GetLabelSourceLines(int width, const QFont &font) const -> QVector<TextLine>;
auto MaxLineWidth(int width) const -> int; auto MaxLineWidth(int width) const -> int;
void Update(const QString &qsName, const VPieceLabelData &data, const VContainer *pattern); void Update(const QString &qsName, const VPieceLabelData &data, const VContainer *pattern);
@ -113,6 +111,8 @@ private:
static const quint32 streamHeader; static const quint32 streamHeader;
static const quint16 classVersion; static const quint16 classVersion;
auto BreakTextIntoLines(const QString &text, const QFont &font, int maxWidth) const -> QStringList;
}; };
#endif // VTEXTMANAGER_H #endif // VTEXTMANAGER_H

View file

@ -129,6 +129,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDoublePassmark, (QLatin1String("
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternDefaultSeamAllowance, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternDefaultSeamAllowance,
(QLatin1String("pattern/defaultSeamAllowance"))) // NOLINT (QLatin1String("pattern/defaultSeamAllowance"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFont, (QLatin1String("pattern/labelFont"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLabelFont, (QLatin1String("pattern/labelFont"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPieceLabelFontPointSize, // NOLINT
(QLatin1String("pattern/pieceLabelFontPointSize")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLineWidth, (QLatin1String("pattern/lineWidth"))) // NOLINT Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternLineWidth, (QLatin1String("pattern/lineWidth"))) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternCurveApproximationScale, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternCurveApproximationScale,
(QLatin1String("pattern/curveApproximationScale"))) // NOLINT (QLatin1String("pattern/curveApproximationScale"))) // NOLINT
@ -1188,15 +1190,49 @@ void VCommonSettings::SetLabelFont(const QFont &f)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetLabelFontSize() const -> int auto VCommonSettings::GetPieceLabelFontPointSize() const -> int
{
bool ok = false;
int val = value(*settingPieceLabelFontPointSize, VCommonSettings::MinPieceLabelFontPointSize()).toInt(&ok);
if (not ok)
{
qDebug() << "Could not convert value"
<< value(*settingPieceLabelFontPointSize, VCommonSettings::MinPieceLabelFontPointSize())
<< "to int. Return default value for label font size.";
val = 12;
}
else
{
if (val < VCommonSettings::MinPieceLabelFontPointSize())
{
return VCommonSettings::MinPieceLabelFontPointSize();
}
}
return val;
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetPieceLabelFontPointSize(int size)
{
setValue(*settingPieceLabelFontPointSize, size);
}
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::MinPieceLabelFontPointSize() -> int
{
return 5;
}
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetPatternLabelFontSize() const -> int
{ {
if (labelFontSizeCached <= 0) if (labelFontSizeCached <= 0)
{ {
bool ok = false; bool ok = false;
labelFontSizeCached = value(*settingPatternLabelFontSize, GetDefLabelFontSize()).toInt(&ok); labelFontSizeCached = value(*settingPatternLabelFontSize, GetDefPatternLabelFontSize()).toInt(&ok);
if (not ok) if (not ok)
{ {
labelFontSizeCached = GetDefLabelFontSize(); labelFontSizeCached = GetDefPatternLabelFontSize();
} }
labelFontSizeCached = qBound(minLabelFontSize, labelFontSizeCached, maxLabelFontSize); labelFontSizeCached = qBound(minLabelFontSize, labelFontSizeCached, maxLabelFontSize);
} }
@ -1204,7 +1240,7 @@ auto VCommonSettings::GetLabelFontSize() const -> int
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetLabelFontSize(int size) void VCommonSettings::SetPatternLabelFontSize(int size)
{ {
size = qBound(minLabelFontSize, size, maxLabelFontSize); size = qBound(minLabelFontSize, size, maxLabelFontSize);
setValue(*settingPatternLabelFontSize, size); setValue(*settingPatternLabelFontSize, size);
@ -1212,7 +1248,7 @@ void VCommonSettings::SetLabelFontSize(int size)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetDefLabelFontSize() -> int auto VCommonSettings::GetDefPatternLabelFontSize() -> int
{ {
return 32; return 32;
} }

View file

@ -46,8 +46,10 @@ class QMarginsF;
class VCommonSettings : public QSettings class VCommonSettings : public QSettings
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public : VCommonSettings(Format format, Scope scope, const QString &organization,
const QString &application = QString(), QObject *parent = nullptr); public:
VCommonSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(),
QObject *parent = nullptr);
VCommonSettings(const QString &fileName, Format format, QObject *parent = nullptr); VCommonSettings(const QString &fileName, Format format, QObject *parent = nullptr);
~VCommonSettings() override = default; ~VCommonSettings() override = default;
@ -211,9 +213,13 @@ class VCommonSettings : public QSettings
auto GetLabelFont() const -> QFont; auto GetLabelFont() const -> QFont;
void SetLabelFont(const QFont &f); void SetLabelFont(const QFont &f);
auto GetLabelFontSize() const -> int; auto GetPieceLabelFontPointSize() const -> int;
void SetLabelFontSize(int size); void SetPieceLabelFontPointSize(int size);
static auto GetDefLabelFontSize() -> int; static auto MinPieceLabelFontPointSize() -> int;
auto GetPatternLabelFontSize() const -> int;
void SetPatternLabelFontSize(int size);
static auto GetDefPatternLabelFontSize() -> int;
auto GetHideLabels() const -> bool; auto GetHideLabels() const -> bool;
void SetHideLabels(bool value); void SetHideLabels(bool value);

View file

@ -33,8 +33,8 @@
#include <QSharedData> #include <QSharedData>
#include <QString> #include <QString>
#include "../vmisc/typedef.h"
#include "../vmisc/defglobal.h" #include "../vmisc/defglobal.h"
#include "../vmisc/typedef.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
@ -46,43 +46,24 @@ QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
class VPatternLabelDataPrivate : public QSharedData class VPatternLabelDataPrivate : public QSharedData
{ {
public: public:
VPatternLabelDataPrivate() VPatternLabelDataPrivate() = default;
: m_dLabelWidth(), VPatternLabelDataPrivate(const VPatternLabelDataPrivate &data) = default;
m_dLabelHeight(),
m_dLabelAngle(),
m_iFontSize(0),
m_centerPin(NULL_ID),
m_topLeftPin(NULL_ID),
m_bottomRightPin(NULL_ID)
{}
VPatternLabelDataPrivate(const VPatternLabelDataPrivate &data)
: QSharedData(data),
m_dLabelWidth(data.m_dLabelWidth),
m_dLabelHeight(data.m_dLabelHeight),
m_dLabelAngle(data.m_dLabelAngle),
m_iFontSize(data.m_iFontSize),
m_centerPin(data.m_centerPin),
m_topLeftPin(data.m_topLeftPin),
m_bottomRightPin(data.m_bottomRightPin)
{}
~VPatternLabelDataPrivate() = default; ~VPatternLabelDataPrivate() = default;
/** @brief m_dLabelWidth formula to calculate the width of label */ /** @brief m_dLabelWidth formula to calculate the width of label */
QString m_dLabelWidth; QString m_dLabelWidth{}; // NOLINT(misc-non-private-member-variables-in-classes)
/** @brief m_dLabelHeight formula to calculate the height of label */ /** @brief m_dLabelHeight formula to calculate the height of label */
QString m_dLabelHeight; QString m_dLabelHeight{}; // NOLINT(misc-non-private-member-variables-in-classes)
/** @brief m_dLabelAngle formula to calculate the rotation angle of label */ /** @brief m_dLabelAngle formula to calculate the rotation angle of label */
QString m_dLabelAngle; QString m_dLabelAngle{}; // NOLINT(misc-non-private-member-variables-in-classes)
/** @brief m_iFontSize label text base font size */ /** @brief m_iFontSize label text base font size */
int m_iFontSize; int m_iFontSize{0}; // NOLINT(misc-non-private-member-variables-in-classes)
/** @brief m_centerPin center pin id */ /** @brief m_centerPin center pin id */
quint32 m_centerPin; quint32 m_centerPin{NULL_ID}; // NOLINT(misc-non-private-member-variables-in-classes)
/** @brief m_topLeftPin top left corner pin id */ /** @brief m_topLeftPin top left corner pin id */
quint32 m_topLeftPin; quint32 m_topLeftPin{NULL_ID}; // NOLINT(misc-non-private-member-variables-in-classes)
/** @brief m_bottomRightPin bottom right corner pin id */ /** @brief m_bottomRightPin bottom right corner pin id */
quint32 m_bottomRightPin; quint32 m_bottomRightPin{NULL_ID}; // NOLINT(misc-non-private-member-variables-in-classes)
private: private:
Q_DISABLE_ASSIGN_MOVE(VPatternLabelDataPrivate) // NOLINT Q_DISABLE_ASSIGN_MOVE(VPatternLabelDataPrivate) // NOLINT
@ -91,4 +72,3 @@ private:
QT_WARNING_POP QT_WARNING_POP
#endif // VPATTERNLABELDATA_P_H #endif // VPATTERNLABELDATA_P_H

View file

@ -76,7 +76,16 @@
#include <array> #include <array>
#include <cstddef> #include <cstddef>
enum TabOrder {Paths=0, Pins=1, Labels=2, Grainline=3, Passmarks=4, PlaceLabels=5, Count=6}; enum TabOrder
{
Paths = 0,
Pins = 1,
Labels = 2,
Grainline = 3,
Passmarks = 4,
PlaceLabels = 5,
Count = 6
};
namespace namespace
{ {
@ -120,8 +129,7 @@ void InitComboBoxFormats(QComboBox *box, const QStringList &items, const QString
} // namespace } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, VAbstractPattern *doc, quint32 toolId, DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, VAbstractPattern *doc, quint32 toolId, QWidget *parent)
QWidget *parent)
: DialogSeamAllowance(data, toolId, parent) : DialogSeamAllowance(data, toolId, parent)
{ {
SCASSERT(doc != nullptr) SCASSERT(doc != nullptr)
@ -177,7 +185,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, quint32 toolId,
ChangeColor(uiTabPaths->labelEditName, OkColor(this)); ChangeColor(uiTabPaths->labelEditName, OkColor(this));
flagMainPathIsValid = MainPathIsValid(); flagMainPathIsValid = MainPathIsValid();
m_ftb->SetCurrentIndex(TabOrder::Paths);// Show always first tab active on start. m_ftb->SetCurrentIndex(TabOrder::Paths); // Show always first tab active on start.
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -256,7 +264,7 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
item->setFont(NodeFont(item->font())); item->setFont(NodeFont(item->font()));
item->setData(Qt::UserRole, QVariant::fromValue(record)); item->setData(Qt::UserRole, QVariant::fromValue(record));
uiTabPaths->listWidgetCustomSA->addItem(item); uiTabPaths->listWidgetCustomSA->addItem(item);
uiTabPaths->listWidgetCustomSA->setCurrentRow(uiTabPaths->listWidgetCustomSA->count()-1); uiTabPaths->listWidgetCustomSA->setCurrentRow(uiTabPaths->listWidgetCustomSA->count() - 1);
} }
} }
uiTabPaths->listWidgetCustomSA->blockSignals(false); uiTabPaths->listWidgetCustomSA->blockSignals(false);
@ -273,7 +281,7 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
item->setFont(NodeFont(item->font())); item->setFont(NodeFont(item->font()));
item->setData(Qt::UserRole, QVariant::fromValue(path)); item->setData(Qt::UserRole, QVariant::fromValue(path));
uiTabPaths->listWidgetInternalPaths->addItem(item); uiTabPaths->listWidgetInternalPaths->addItem(item);
uiTabPaths->listWidgetInternalPaths->setCurrentRow(uiTabPaths->listWidgetInternalPaths->count()-1); uiTabPaths->listWidgetInternalPaths->setCurrentRow(uiTabPaths->listWidgetInternalPaths->count() - 1);
} }
} }
@ -289,7 +297,7 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
item->setFont(NodeFont(item->font())); item->setFont(NodeFont(item->font()));
item->setData(Qt::UserRole, QVariant::fromValue(point)); item->setData(Qt::UserRole, QVariant::fromValue(point));
listWidget->addItem(item); listWidget->addItem(item);
listWidget->setCurrentRow(uiTabPins->listWidgetPins->count()-1); listWidget->setCurrentRow(uiTabPins->listWidgetPins->count() - 1);
} }
catch (const VExceptionBadId &e) catch (const VExceptionBadId &e)
{ {
@ -340,9 +348,8 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
uiTabPaths->lineEditGradationLabel->setText(piece.GetGradationLabel()); uiTabPaths->lineEditGradationLabel->setText(piece.GetGradationLabel());
uiTabPaths->spinBoxPriority->setValue(static_cast<int>(piece.GetPriority())); uiTabPaths->spinBoxPriority->setValue(static_cast<int>(piece.GetPriority()));
uiTabPaths->plainTextEditFormulaWidth->setPlainText( uiTabPaths->plainTextEditFormulaWidth->setPlainText(VAbstractApplication::VApp()->TrVars()->FormulaToUser(
VAbstractApplication::VApp()->TrVars() piece.GetFormulaSAWidth(), VAbstractApplication::VApp()->Settings()->GetOsSeparator()));
->FormulaToUser(piece.GetFormulaSAWidth(), VAbstractApplication::VApp()->Settings()->GetOsSeparator()));
m_saWidth = piece.GetSAWidth(); m_saWidth = piece.GetSAWidth();
const VPieceLabelData &ppData = piece.GetPieceLabelData(); const VPieceLabelData &ppData = piece.GetPieceLabelData();
@ -356,6 +363,11 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
uiTabLabels->checkBoxFold->setChecked(ppData.IsOnFold()); uiTabLabels->checkBoxFold->setChecked(ppData.IsOnFold());
m_templateLines = ppData.GetLabelTemplate(); m_templateLines = ppData.GetLabelTemplate();
{
const int piceFontSizeIndex = uiTabLabels->comboBoxPieceLabelSize->findData(ppData.GetFontSize());
uiTabLabels->comboBoxPieceLabelSize->setCurrentIndex(piceFontSizeIndex != -1 ? piceFontSizeIndex : 0);
}
uiTabLabels->groupBoxDetailLabel->setEnabled(not m_templateLines.isEmpty()); uiTabLabels->groupBoxDetailLabel->setEnabled(not m_templateLines.isEmpty());
int index = uiTabGrainline->comboBoxArrow->findData(static_cast<int>(piece.GetGrainlineGeometry().GetArrowType())); int index = uiTabGrainline->comboBoxArrow->findData(static_cast<int>(piece.GetGrainlineGeometry().GetArrowType()));
@ -383,6 +395,11 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
SetPLHeight(patternInfo.GetLabelHeight()); SetPLHeight(patternInfo.GetLabelHeight());
SetPLAngle(patternInfo.GetRotation()); SetPLAngle(patternInfo.GetRotation());
{
const int patternFontSizeIndex = uiTabLabels->comboBoxPatternLabelSize->findData(patternInfo.GetFontSize());
uiTabLabels->comboBoxPatternLabelSize->setCurrentIndex(patternFontSizeIndex != -1 ? patternFontSizeIndex : 0);
}
const VGrainlineData &grainlineGeometry = piece.GetGrainlineGeometry(); const VGrainlineData &grainlineGeometry = piece.GetGrainlineGeometry();
uiTabGrainline->groupBoxGrainline->setChecked(grainlineGeometry.IsVisible()); uiTabGrainline->groupBoxGrainline->setChecked(grainlineGeometry.IsVisible());
ChangeCurrentData(uiTabGrainline->comboBoxGrainlineCenterPin, grainlineGeometry.CenterPin()); ChangeCurrentData(uiTabGrainline->comboBoxGrainlineCenterPin, grainlineGeometry.CenterPin());
@ -525,7 +542,7 @@ void DialogSeamAllowance::CheckState()
SCASSERT(bOk != nullptr); SCASSERT(bOk != nullptr);
bOk->setEnabled(IsValid()); bOk->setEnabled(IsValid());
// In case dialog hasn't apply button // In case dialog hasn't apply button
if ( bApply != nullptr && applyAllowed) if (bApply != nullptr && applyAllowed)
{ {
bApply->setEnabled(bOk->isEnabled()); bApply->setEnabled(bOk->isEnabled());
} }
@ -557,8 +574,8 @@ void DialogSeamAllowance::CheckState()
if (not applyAllowed) if (not applyAllowed)
{ {
tooltip = tooltip + QStringLiteral(" <b>") + tooltip = tooltip + QStringLiteral(" <b>") +
tr("To open all detail's features complete creating the main path. Please, press OK.") tr("To open all detail's features complete creating the main path. Please, press OK.") +
+ QStringLiteral("</b>"); QStringLiteral("</b>");
} }
uiTabPaths->helpLabel->setText(tooltip); uiTabPaths->helpLabel->setText(tooltip);
uiTabPaths->tabWidget->setTabIcon(uiTabPaths->tabWidget->indexOf(uiTabPaths->tabMainPath), QIcon()); uiTabPaths->tabWidget->setTabIcon(uiTabPaths->tabWidget->indexOf(uiTabPaths->tabMainPath), QIcon());
@ -664,7 +681,7 @@ void DialogSeamAllowance::showEvent(QShowEvent *event)
resize(sz); resize(sz);
} }
isInitialized = true;//first show windows are held isInitialized = true; // first show windows are held
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -878,8 +895,8 @@ void DialogSeamAllowance::ShowCustomSAContextMenu(const QPoint &pos)
void DialogSeamAllowance::ShowInternalPathsContextMenu(const QPoint &pos) void DialogSeamAllowance::ShowInternalPathsContextMenu(const QPoint &pos)
{ {
const int row = uiTabPaths->listWidgetInternalPaths->currentRow(); const int row = uiTabPaths->listWidgetInternalPaths->currentRow();
if (uiTabPaths->listWidgetInternalPaths->count() == 0 || row == -1 if (uiTabPaths->listWidgetInternalPaths->count() == 0 || row == -1 ||
|| row >= uiTabPaths->listWidgetInternalPaths->count()) row >= uiTabPaths->listWidgetInternalPaths->count())
{ {
return; return;
} }
@ -935,9 +952,8 @@ void DialogSeamAllowance::ShowPinsContextMenu(const QPoint &pos)
void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos) void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos)
{ {
const int row = uiTabPlaceLabels->listWidgetPlaceLabels->currentRow(); const int row = uiTabPlaceLabels->listWidgetPlaceLabels->currentRow();
if (uiTabPlaceLabels->listWidgetPlaceLabels->count() == 0 if (uiTabPlaceLabels->listWidgetPlaceLabels->count() == 0 || row == -1 ||
|| row == -1 row >= uiTabPlaceLabels->listWidgetPlaceLabels->count())
|| row >= uiTabPlaceLabels->listWidgetPlaceLabels->count())
{ {
return; return;
} }
@ -963,9 +979,8 @@ void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos)
newLabel.SetLabelType(type); newLabel.SetLabelType(type);
m_newPlaceLabels.insert(labelId, newLabel); m_newPlaceLabels.insert(labelId, newLabel);
QPointer<VUndoCommand> saveCommand = QPointer<VUndoCommand> saveCommand = new SavePlaceLabelOptions(
new SavePlaceLabelOptions(toolId, currentLabel, newLabel, toolId, currentLabel, newLabel, VAbstractValApplication::VApp()->getCurrentDocument(),
VAbstractValApplication::VApp()->getCurrentDocument(),
const_cast<VContainer *>(data), labelId); const_cast<VContainer *>(data), labelId);
m_undoStack.append(saveCommand); m_undoStack.append(saveCommand);
UpdateCurrentPlaceLabelRecords(); UpdateCurrentPlaceLabelRecords();
@ -1096,9 +1111,9 @@ void DialogSeamAllowance::NodeChanged(int index)
QString w1Formula = node.GetFormulaSABefore(); QString w1Formula = node.GetFormulaSABefore();
EnableDefButton(uiTabPaths->pushButtonDefBefore, w1Formula); EnableDefButton(uiTabPaths->pushButtonDefBefore, w1Formula);
w1Formula = VAbstractApplication::VApp()->TrVars() w1Formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(w1Formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); w1Formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
if (w1Formula.length() > 80)// increase height if needed. if (w1Formula.length() > 80) // increase height if needed.
{ {
this->DeployWidthBeforeFormulaTextEdit(); this->DeployWidthBeforeFormulaTextEdit();
} }
@ -1111,9 +1126,9 @@ void DialogSeamAllowance::NodeChanged(int index)
QString w2Formula = node.GetFormulaSAAfter(); QString w2Formula = node.GetFormulaSAAfter();
EnableDefButton(uiTabPaths->pushButtonDefAfter, w2Formula); EnableDefButton(uiTabPaths->pushButtonDefAfter, w2Formula);
w2Formula = VAbstractApplication::VApp()->TrVars() w2Formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(w2Formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); w2Formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
if (w2Formula.length() > 80)// increase height if needed. if (w2Formula.length() > 80) // increase height if needed.
{ {
this->DeployWidthAfterFormulaTextEdit(); this->DeployWidthAfterFormulaTextEdit();
} }
@ -1288,8 +1303,8 @@ void DialogSeamAllowance::NodeAngleChanged(int index)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::ReturnDefBefore() void DialogSeamAllowance::ReturnDefBefore()
{ {
const QString def = VAbstractApplication::VApp()->TrVars() const QString def = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(currentSeamAllowance, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); currentSeamAllowance, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
uiTabPaths->plainTextEditFormulaWidthBefore->setPlainText(def); uiTabPaths->plainTextEditFormulaWidthBefore->setPlainText(def);
if (auto *button = qobject_cast<QPushButton *>(sender())) if (auto *button = qobject_cast<QPushButton *>(sender()))
{ {
@ -1300,8 +1315,8 @@ void DialogSeamAllowance::ReturnDefBefore()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::ReturnDefAfter() void DialogSeamAllowance::ReturnDefAfter()
{ {
const QString def = VAbstractApplication::VApp()->TrVars() const QString def = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(currentSeamAllowance, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); currentSeamAllowance, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
uiTabPaths->plainTextEditFormulaWidthAfter->setPlainText(def); uiTabPaths->plainTextEditFormulaWidthAfter->setPlainText(def);
if (auto *button = qobject_cast<QPushButton *>(sender())) if (auto *button = qobject_cast<QPushButton *>(sender()))
{ {
@ -1328,7 +1343,7 @@ void DialogSeamAllowance::CustomSAChanged(int row)
return; return;
} }
const QListWidgetItem *item = uiTabPaths->listWidgetCustomSA->item( row ); const QListWidgetItem *item = uiTabPaths->listWidgetCustomSA->item(row);
SCASSERT(item != nullptr); SCASSERT(item != nullptr);
const auto record = qvariant_cast<CustomSARecord>(item->data(Qt::UserRole)); const auto record = qvariant_cast<CustomSARecord>(item->data(Qt::UserRole));
@ -1380,9 +1395,8 @@ void DialogSeamAllowance::PathDialogClosed(int result)
VPiecePath newPath = dialogTool->GetPiecePath(); VPiecePath newPath = dialogTool->GetPiecePath();
m_newPaths.insert(dialogTool->GetToolId(), newPath); m_newPaths.insert(dialogTool->GetToolId(), newPath);
QPointer<VUndoCommand> saveCommand = QPointer<VUndoCommand> saveCommand = new SavePiecePathOptions(
new SavePiecePathOptions(toolId, currentPath, newPath, toolId, currentPath, newPath, VAbstractValApplication::VApp()->getCurrentDocument(),
VAbstractValApplication::VApp()->getCurrentDocument(),
const_cast<VContainer *>(data), dialogTool->GetToolId()); const_cast<VContainer *>(data), dialogTool->GetToolId());
m_undoStack.append(saveCommand); m_undoStack.append(saveCommand);
UpdateCurrentCustomSARecord(); UpdateCurrentCustomSARecord();
@ -1409,7 +1423,7 @@ void DialogSeamAllowance::PlaceLabelDialogClosed(int result)
{ {
VPlaceLabelItem currentLabel = CurrentPlaceLabel(dialogTool->GetToolId()); VPlaceLabelItem currentLabel = CurrentPlaceLabel(dialogTool->GetToolId());
const QHash<QString, QSharedPointer<VInternalVariable> > *vars = data->DataVariables(); const QHash<QString, QSharedPointer<VInternalVariable>> *vars = data->DataVariables();
const qreal w = qAbs(Visualization::FindLengthFromUser(dialogTool->GetWidth(), vars, false)); const qreal w = qAbs(Visualization::FindLengthFromUser(dialogTool->GetWidth(), vars, false));
const qreal h = qAbs(Visualization::FindLengthFromUser(dialogTool->GetHeight(), vars, false)); const qreal h = qAbs(Visualization::FindLengthFromUser(dialogTool->GetHeight(), vars, false));
@ -1433,9 +1447,8 @@ void DialogSeamAllowance::PlaceLabelDialogClosed(int result)
m_newPlaceLabels.insert(dialogTool->GetToolId(), newLabel); m_newPlaceLabels.insert(dialogTool->GetToolId(), newLabel);
QPointer<VUndoCommand> saveCommand = QPointer<VUndoCommand> saveCommand = new SavePlaceLabelOptions(
new SavePlaceLabelOptions(toolId, currentLabel, newLabel, toolId, currentLabel, newLabel, VAbstractValApplication::VApp()->getCurrentDocument(),
VAbstractValApplication::VApp()->getCurrentDocument(),
const_cast<VContainer *>(data), dialogTool->GetToolId()); const_cast<VContainer *>(data), dialogTool->GetToolId());
m_undoStack.append(saveCommand); m_undoStack.append(saveCommand);
UpdateCurrentPlaceLabelRecords(); UpdateCurrentPlaceLabelRecords();
@ -1466,7 +1479,7 @@ void DialogSeamAllowance::FancyTabChanged(int index)
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default") QT_WARNING_DISABLE_GCC("-Wswitch-default")
switch(index) switch (index)
{ {
case TabOrder::Paths: case TabOrder::Paths:
m_tabPaths->show(); m_tabPaths->show();
@ -1683,8 +1696,8 @@ void DialogSeamAllowance::UpdateGrainlineValues()
for (std::size_t i = 0; i < 2; ++i) for (std::size_t i = 0; i < 2; ++i)
{ {
QLabel* plbVal; QLabel *plbVal;
QLabel* plbText; QLabel *plbText;
QString qsUnit; QString qsUnit;
if (i == 0) if (i == 0)
{ {
@ -1705,8 +1718,8 @@ void DialogSeamAllowance::UpdateGrainlineValues()
QString qsVal; QString qsVal;
try try
{ {
qsFormula = VAbstractApplication::VApp()->TrVars() qsFormula = VAbstractApplication::VApp()->TrVars()->FormulaFromUser(
->FormulaFromUser(qsFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); qsFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
Calculator cal; Calculator cal;
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula); qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
if (qIsInf(dVal) || qIsNaN(dVal)) if (qIsInf(dVal) || qIsNaN(dVal))
@ -1757,8 +1770,8 @@ void DialogSeamAllowance::UpdateDetailLabelValues()
for (std::size_t i = 0; i < 3; ++i) for (std::size_t i = 0; i < 3; ++i)
{ {
QLabel* plbVal; QLabel *plbVal;
QLabel* plbText; QLabel *plbText;
QString qsUnit; QString qsUnit;
if (i == 0) if (i == 0)
{ {
@ -1786,8 +1799,8 @@ void DialogSeamAllowance::UpdateDetailLabelValues()
try try
{ {
qsFormula = VAbstractApplication::VApp()->TrVars() qsFormula = VAbstractApplication::VApp()->TrVars()->FormulaFromUser(
->FormulaFromUser(qsFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); qsFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
Calculator cal; Calculator cal;
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula); qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
if (qIsInf(dVal) || qIsNaN(dVal)) if (qIsInf(dVal) || qIsNaN(dVal))
@ -1819,7 +1832,7 @@ void DialogSeamAllowance::UpdateDetailLabelValues()
flagDLAngle = bFormulasOK[2]; flagDLAngle = bFormulasOK[2];
flagDLFormulas = bFormulasOK[0] && bFormulasOK[1]; flagDLFormulas = bFormulasOK[0] && bFormulasOK[1];
if (not flagDLAngle || not (flagDLFormulas || flagDPin) || not flagPLAngle || not (flagPLFormulas || flagPPin)) if (not flagDLAngle || not(flagDLFormulas || flagDPin) || not flagPLAngle || not(flagPLFormulas || flagPPin))
{ {
m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*'); m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*');
const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"), const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"),
@ -1842,8 +1855,8 @@ void DialogSeamAllowance::UpdatePatternLabelValues()
for (std::size_t i = 0; i < 3; ++i) for (std::size_t i = 0; i < 3; ++i)
{ {
QLabel* plbVal; QLabel *plbVal;
QLabel* plbText; QLabel *plbText;
QString qsUnit; QString qsUnit;
if (i == 0) if (i == 0)
{ {
@ -1870,8 +1883,8 @@ void DialogSeamAllowance::UpdatePatternLabelValues()
QString qsVal; QString qsVal;
try try
{ {
qsFormula = VAbstractApplication::VApp()->TrVars() qsFormula = VAbstractApplication::VApp()->TrVars()->FormulaFromUser(
->FormulaFromUser(qsFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); qsFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
Calculator cal; Calculator cal;
qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula); qreal dVal = cal.EvalFormula(data->DataVariables(), qsFormula);
if (qIsInf(dVal) || qIsNaN(dVal)) if (qIsInf(dVal) || qIsNaN(dVal))
@ -1903,7 +1916,7 @@ void DialogSeamAllowance::UpdatePatternLabelValues()
flagPLAngle = bFormulasOK[2]; flagPLAngle = bFormulasOK[2];
flagPLFormulas = bFormulasOK[0] && bFormulasOK[1]; flagPLFormulas = bFormulasOK[0] && bFormulasOK[1];
if (not flagDLAngle || not (flagDLFormulas || flagDPin) || not flagPLAngle || not (flagPLFormulas || flagPPin)) if (not flagDLAngle || not(flagDLFormulas || flagDPin) || not flagPLAngle || not(flagPLFormulas || flagPPin))
{ {
m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*'); m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*');
const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"), const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"),
@ -2041,7 +2054,7 @@ void DialogSeamAllowance::EnabledManualPassmarkAngle()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::EditGrainlineFormula() void DialogSeamAllowance::EditGrainlineFormula()
{ {
QPlainTextEdit* pleFormula; QPlainTextEdit *pleFormula;
bool bCheckZero; bool bCheckZero;
QString title; QString title;
@ -2092,7 +2105,7 @@ void DialogSeamAllowance::EditGrainlineFormula()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::EditDLFormula() void DialogSeamAllowance::EditDLFormula()
{ {
QPlainTextEdit* pleFormula; QPlainTextEdit *pleFormula;
bool bCheckZero; bool bCheckZero;
QString title; QString title;
@ -2152,7 +2165,7 @@ void DialogSeamAllowance::EditDLFormula()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::EditPLFormula() void DialogSeamAllowance::EditPLFormula()
{ {
QPlainTextEdit* pleFormula; QPlainTextEdit *pleFormula;
bool bCheckZero; bool bCheckZero;
QString title; QString title;
@ -2218,7 +2231,7 @@ void DialogSeamAllowance::DeployGrainlineRotation()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployGrainlineLength() void DialogSeamAllowance::DeployGrainlineLength()
{ {
DeployFormula(this,uiTabGrainline->lineEditLenFormula, uiTabGrainline->pushButtonShowLen, m_iLenBaseHeight); DeployFormula(this, uiTabGrainline->lineEditLenFormula, uiTabGrainline->pushButtonShowLen, m_iLenBaseHeight);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2594,7 +2607,7 @@ void DialogSeamAllowance::GrainlinePinPointChanged()
else else
{ {
flagGPin = false; flagGPin = false;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor; topPinId == NULL_ID &&bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor;
if (not flagGFormulas && not flagGPin) if (not flagGFormulas && not flagGPin)
{ {
@ -2628,7 +2641,7 @@ void DialogSeamAllowance::DetailPinPointChanged()
else else
{ {
flagDPin = false; flagDPin = false;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor; topPinId == NULL_ID &&bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor;
m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*'); m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*');
const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"), const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"),
@ -2662,7 +2675,7 @@ void DialogSeamAllowance::PatternPinPointChanged()
else else
{ {
flagPPin = false; flagPPin = false;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor; topPinId == NULL_ID &&bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor;
m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*'); m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*');
const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"), const QIcon icon = QIcon::fromTheme(QStringLiteral("dialog-warning"),
@ -2722,6 +2735,7 @@ auto DialogSeamAllowance::CreatePiece() const -> VPiece
piece.GetPieceLabelData().SetLabelTemplate(m_templateLines); piece.GetPieceLabelData().SetLabelTemplate(m_templateLines);
piece.GetPieceLabelData().SetRotation(GetFormulaFromUser(uiTabLabels->lineEditDLAngleFormula)); piece.GetPieceLabelData().SetRotation(GetFormulaFromUser(uiTabLabels->lineEditDLAngleFormula));
piece.GetPieceLabelData().SetVisible(uiTabLabels->groupBoxDetailLabel->isChecked()); piece.GetPieceLabelData().SetVisible(uiTabLabels->groupBoxDetailLabel->isChecked());
piece.GetPieceLabelData().SetFontSize(uiTabLabels->comboBoxPieceLabelSize->currentData().toInt());
if (not flagDPin) if (not flagDPin)
{ {
@ -2742,6 +2756,7 @@ auto DialogSeamAllowance::CreatePiece() const -> VPiece
piece.GetPatternLabelData().SetVisible(uiTabLabels->groupBoxPatternLabel->isChecked()); piece.GetPatternLabelData().SetVisible(uiTabLabels->groupBoxPatternLabel->isChecked());
piece.GetPatternLabelData().SetRotation(GetFormulaFromUser(uiTabLabels->lineEditPLAngleFormula)); piece.GetPatternLabelData().SetRotation(GetFormulaFromUser(uiTabLabels->lineEditPLAngleFormula));
piece.GetPatternLabelData().SetFontSize(uiTabLabels->comboBoxPatternLabelSize->currentData().toInt());
if (not flagPPin) if (not flagPPin)
{ {
@ -2811,13 +2826,13 @@ auto DialogSeamAllowance::GetPathName(quint32 path, bool reverse) const -> QStri
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto DialogSeamAllowance::MainPathIsValid() const -> bool auto DialogSeamAllowance::MainPathIsValid() const -> bool
{ {
if(CreatePiece().MainPathPoints(data).count() < 3) if (CreatePiece().MainPathPoints(data).count() < 3)
{ {
uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("You need more points!")); uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("You need more points!"));
return false; return false;
} }
if(not MainPathIsClockwise()) if (not MainPathIsClockwise())
{ {
uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("You have to choose points in a clockwise direction!")); uiTabPaths->helpLabel->setText(DialogWarningIcon() + tr("You have to choose points in a clockwise direction!"));
return false; return false;
@ -2877,7 +2892,7 @@ auto DialogSeamAllowance::MainPathIsClockwise() const -> bool
QVector<QPointF> points; QVector<QPointF> points;
CastTo(CreatePiece().MainPathPoints(data), points); CastTo(CreatePiece().MainPathPoints(data), points);
if(points.count() < 3) if (points.count() < 3)
{ {
return false; return false;
} }
@ -2911,7 +2926,7 @@ void DialogSeamAllowance::InitNodesList()
if (index != -1) if (index != -1)
{ {
uiTabPaths->comboBoxNodes->setCurrentIndex(index); uiTabPaths->comboBoxNodes->setCurrentIndex(index);
NodeChanged(index);// Need in case combox index was not changed NodeChanged(index); // Need in case combox index was not changed
} }
else else
{ {
@ -2944,7 +2959,7 @@ void DialogSeamAllowance::InitPassmarksList()
if (index != -1) if (index != -1)
{ {
uiTabPassmarks->comboBoxPassmarks->setCurrentIndex(index); uiTabPassmarks->comboBoxPassmarks->setCurrentIndex(index);
PassmarkChanged(index);// Need in case combox index was not changed PassmarkChanged(index); // Need in case combox index was not changed
} }
else else
{ {
@ -2974,7 +2989,7 @@ auto DialogSeamAllowance::GetLastId() const -> quint32
const int count = uiTabPaths->listWidgetMainPath->count(); const int count = uiTabPaths->listWidgetMainPath->count();
if (count > 0) if (count > 0)
{ {
QListWidgetItem *item = uiTabPaths->listWidgetMainPath->item(count-1); QListWidgetItem *item = uiTabPaths->listWidgetMainPath->item(count - 1);
const auto node = qvariant_cast<VPieceNode>(item->data(Qt::UserRole)); const auto node = qvariant_cast<VPieceNode>(item->data(Qt::UserRole));
return node.GetId(); return node.GetId();
} }
@ -3131,27 +3146,29 @@ void DialogSeamAllowance::InitMainPathTab()
connect(uiTabPaths->listWidgetMainPath, &QListWidget::itemSelectionChanged, this, connect(uiTabPaths->listWidgetMainPath, &QListWidget::itemSelectionChanged, this,
&DialogSeamAllowance::SetMoveControls); &DialogSeamAllowance::SetMoveControls);
connect(uiTabPaths->listWidgetMainPath->model(), &QAbstractItemModel::rowsMoved, this, [this]() connect(uiTabPaths->listWidgetMainPath->model(), &QAbstractItemModel::rowsMoved, this,
{ [this]() { ValidObjects(MainPathIsValid()); });
ValidObjects(MainPathIsValid());
});
connect(uiTabPaths->toolButtonTop, &QToolButton::clicked, this, [this]() connect(uiTabPaths->toolButtonTop, &QToolButton::clicked, this,
[this]()
{ {
MoveListRowTop(uiTabPaths->listWidgetMainPath); MoveListRowTop(uiTabPaths->listWidgetMainPath);
ValidObjects(MainPathIsValid()); ValidObjects(MainPathIsValid());
}); });
connect(uiTabPaths->toolButtonUp, &QToolButton::clicked, this, [this]() connect(uiTabPaths->toolButtonUp, &QToolButton::clicked, this,
[this]()
{ {
MoveListRowUp(uiTabPaths->listWidgetMainPath); MoveListRowUp(uiTabPaths->listWidgetMainPath);
ValidObjects(MainPathIsValid()); ValidObjects(MainPathIsValid());
}); });
connect(uiTabPaths->toolButtonDown, &QToolButton::clicked, this, [this]() connect(uiTabPaths->toolButtonDown, &QToolButton::clicked, this,
[this]()
{ {
MoveListRowDown(uiTabPaths->listWidgetMainPath); MoveListRowDown(uiTabPaths->listWidgetMainPath);
ValidObjects(MainPathIsValid()); ValidObjects(MainPathIsValid());
}); });
connect(uiTabPaths->toolButtonBottom, &QToolButton::clicked, this, [this]() connect(uiTabPaths->toolButtonBottom, &QToolButton::clicked, this,
[this]()
{ {
MoveListRowBottom(uiTabPaths->listWidgetMainPath); MoveListRowBottom(uiTabPaths->listWidgetMainPath);
ValidObjects(MainPathIsValid()); ValidObjects(MainPathIsValid());
@ -3169,7 +3186,8 @@ void DialogSeamAllowance::InitPieceTab()
uiTabPaths->lineEditName->setClearButtonEnabled(true); uiTabPaths->lineEditName->setClearButtonEnabled(true);
uiTabPaths->lineEditName->setText(GetDefaultPieceName()); uiTabPaths->lineEditName->setText(GetDefaultPieceName());
connect(uiTabPaths->checkBoxForbidFlipping, &QCheckBox::stateChanged, this, [this](int state) connect(uiTabPaths->checkBoxForbidFlipping, &QCheckBox::stateChanged, this,
[this](int state)
{ {
if (state == Qt::Checked) if (state == Qt::Checked)
{ {
@ -3177,7 +3195,8 @@ void DialogSeamAllowance::InitPieceTab()
} }
}); });
connect(uiTabPaths->checkBoxForceFlipping, &QCheckBox::stateChanged, this, [this](int state) connect(uiTabPaths->checkBoxForceFlipping, &QCheckBox::stateChanged, this,
[this](int state)
{ {
if (state == Qt::Checked) if (state == Qt::Checked)
{ {
@ -3219,7 +3238,8 @@ void DialogSeamAllowance::InitSeamAllowanceTab()
m_timerWidthAfter->setSingleShot(true); m_timerWidthAfter->setSingleShot(true);
connect(m_timerWidthAfter, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidthAfter); connect(m_timerWidthAfter, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidthAfter);
connect(uiTabPaths->checkBoxSeams, &QCheckBox::toggled, this, [this](bool enable) connect(uiTabPaths->checkBoxSeams, &QCheckBox::toggled, this,
[this](bool enable)
{ {
uiTabPaths->checkBoxBuiltIn->setEnabled(enable); uiTabPaths->checkBoxBuiltIn->setEnabled(enable);
@ -3234,7 +3254,8 @@ void DialogSeamAllowance::InitSeamAllowanceTab()
} }
}); });
connect(uiTabPaths->checkBoxBuiltIn, &QCheckBox::toggled, this, [this](bool enable) connect(uiTabPaths->checkBoxBuiltIn, &QCheckBox::toggled, this,
[this](bool enable)
{ {
uiTabPaths->groupBoxAutomatic->setEnabled(not enable); uiTabPaths->groupBoxAutomatic->setEnabled(not enable);
uiTabPaths->groupBoxCustom->setEnabled(not enable); uiTabPaths->groupBoxCustom->setEnabled(not enable);
@ -3268,36 +3289,30 @@ void DialogSeamAllowance::InitSeamAllowanceTab()
&DialogSeamAllowance::ShowCustomSAContextMenu); &DialogSeamAllowance::ShowCustomSAContextMenu);
connect(uiTabPaths->listWidgetCustomSA, &QListWidget::currentRowChanged, this, connect(uiTabPaths->listWidgetCustomSA, &QListWidget::currentRowChanged, this,
&DialogSeamAllowance::CustomSAChanged); &DialogSeamAllowance::CustomSAChanged);
connect(uiTabPaths->comboBoxStartPoint, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(uiTabPaths->comboBoxStartPoint, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
this, &DialogSeamAllowance::CSAStartPointChanged); &DialogSeamAllowance::CSAStartPointChanged);
connect(uiTabPaths->comboBoxEndPoint, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(uiTabPaths->comboBoxEndPoint, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&DialogSeamAllowance::CSAEndPointChanged); &DialogSeamAllowance::CSAEndPointChanged);
connect(uiTabPaths->comboBoxIncludeType, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(uiTabPaths->comboBoxIncludeType, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
this, &DialogSeamAllowance::CSAIncludeTypeChanged); &DialogSeamAllowance::CSAIncludeTypeChanged);
connect(uiTabPaths->toolButtonExprWidth, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidth); connect(uiTabPaths->toolButtonExprWidth, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidth);
connect(uiTabPaths->toolButtonExprBefore, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthBefore); connect(uiTabPaths->toolButtonExprBefore, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthBefore);
connect(uiTabPaths->toolButtonExprAfter, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthAfter); connect(uiTabPaths->toolButtonExprAfter, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthAfter);
connect(uiTabPaths->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, [this]() connect(uiTabPaths->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this,
{ [this]() { m_timerWidth->start(formulaTimerTimeout); });
m_timerWidth->start(formulaTimerTimeout);
});
connect(uiTabPaths->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this, [this]() connect(uiTabPaths->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this,
{ [this]() { m_timerWidthBefore->start(formulaTimerTimeout); });
m_timerWidthBefore->start(formulaTimerTimeout);
});
connect(uiTabPaths->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this, [this]() connect(uiTabPaths->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this,
{ [this]() { m_timerWidthAfter->start(formulaTimerTimeout); });
m_timerWidthAfter->start(formulaTimerTimeout);
});
connect(uiTabPaths->pushButtonGrowWidth, &QPushButton::clicked, this, connect(uiTabPaths->pushButtonGrowWidth, &QPushButton::clicked, this,
&DialogSeamAllowance::DeployWidthFormulaTextEdit); &DialogSeamAllowance::DeployWidthFormulaTextEdit);
connect(uiTabPaths->pushButtonGrowWidthBefore, &QPushButton::clicked, connect(uiTabPaths->pushButtonGrowWidthBefore, &QPushButton::clicked, this,
this, &DialogSeamAllowance::DeployWidthBeforeFormulaTextEdit); &DialogSeamAllowance::DeployWidthBeforeFormulaTextEdit);
connect(uiTabPaths->pushButtonGrowWidthAfter, &QPushButton::clicked, this, connect(uiTabPaths->pushButtonGrowWidthAfter, &QPushButton::clicked, this,
&DialogSeamAllowance::DeployWidthAfterFormulaTextEdit); &DialogSeamAllowance::DeployWidthAfterFormulaTextEdit);
} }
@ -3384,6 +3399,9 @@ void DialogSeamAllowance::InitPatternPieceDataTab()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::InitLabelsTab() void DialogSeamAllowance::InitLabelsTab()
{ {
InitLabelFontSize(uiTabLabels->comboBoxPatternLabelSize);
InitLabelFontSize(uiTabLabels->comboBoxPieceLabelSize);
uiTabLabels->lineEditDLWidthFormula->setPlainText(m_defLabelValue); uiTabLabels->lineEditDLWidthFormula->setPlainText(m_defLabelValue);
uiTabLabels->lineEditDLHeightFormula->setPlainText(m_defLabelValue); uiTabLabels->lineEditDLHeightFormula->setPlainText(m_defLabelValue);
uiTabLabels->lineEditPLWidthFormula->setPlainText(m_defLabelValue); uiTabLabels->lineEditPLWidthFormula->setPlainText(m_defLabelValue);
@ -3398,10 +3416,10 @@ void DialogSeamAllowance::InitLabelsTab()
InitPinPoint(uiTabLabels->comboBoxDLTopLeftPin); InitPinPoint(uiTabLabels->comboBoxDLTopLeftPin);
InitPinPoint(uiTabLabels->comboBoxDLBottomRightPin); InitPinPoint(uiTabLabels->comboBoxDLBottomRightPin);
connect(uiTabLabels->comboBoxDLTopLeftPin, &QComboBox::currentTextChanged, connect(uiTabLabels->comboBoxDLTopLeftPin, &QComboBox::currentTextChanged, this,
this, &DialogSeamAllowance::DetailPinPointChanged); &DialogSeamAllowance::DetailPinPointChanged);
connect(uiTabLabels->comboBoxDLBottomRightPin, &QComboBox::currentTextChanged, connect(uiTabLabels->comboBoxDLBottomRightPin, &QComboBox::currentTextChanged, this,
this, &DialogSeamAllowance::DetailPinPointChanged); &DialogSeamAllowance::DetailPinPointChanged);
connect(uiTabLabels->pushButtonDLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); connect(uiTabLabels->pushButtonDLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula);
connect(uiTabLabels->pushButtonDLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); connect(uiTabLabels->pushButtonDLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula);
@ -3429,10 +3447,10 @@ void DialogSeamAllowance::InitLabelsTab()
InitPinPoint(uiTabLabels->comboBoxPLTopLeftPin); InitPinPoint(uiTabLabels->comboBoxPLTopLeftPin);
InitPinPoint(uiTabLabels->comboBoxPLBottomRightPin); InitPinPoint(uiTabLabels->comboBoxPLBottomRightPin);
connect(uiTabLabels->comboBoxPLTopLeftPin, &QComboBox::currentTextChanged, connect(uiTabLabels->comboBoxPLTopLeftPin, &QComboBox::currentTextChanged, this,
this, &DialogSeamAllowance::PatternPinPointChanged); &DialogSeamAllowance::PatternPinPointChanged);
connect(uiTabLabels->comboBoxPLBottomRightPin, &QComboBox::currentTextChanged, connect(uiTabLabels->comboBoxPLBottomRightPin, &QComboBox::currentTextChanged, this,
this, &DialogSeamAllowance::PatternPinPointChanged); &DialogSeamAllowance::PatternPinPointChanged);
connect(uiTabLabels->pushButtonPLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); connect(uiTabLabels->pushButtonPLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula);
connect(uiTabLabels->pushButtonPLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); connect(uiTabLabels->pushButtonPLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula);
@ -3488,10 +3506,10 @@ void DialogSeamAllowance::InitLabelsTab()
connect(uiTabLabels->pushButtonPatternMaterials, &QPushButton::clicked, this, connect(uiTabLabels->pushButtonPatternMaterials, &QPushButton::clicked, this,
&DialogSeamAllowance::ManagePatternMaterials); &DialogSeamAllowance::ManagePatternMaterials);
connect(uiTabLabels->comboBoxDateFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(uiTabLabels->comboBoxDateFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
this, &DialogSeamAllowance::PatternLabelDataChanged); &DialogSeamAllowance::PatternLabelDataChanged);
connect(uiTabLabels->comboBoxTimeFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(uiTabLabels->comboBoxTimeFormat, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
this, &DialogSeamAllowance::PatternLabelDataChanged); &DialogSeamAllowance::PatternLabelDataChanged);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -3547,10 +3565,10 @@ void DialogSeamAllowance::InitGrainlineTab()
InitPinPoint(uiTabGrainline->comboBoxGrainlineTopPin); InitPinPoint(uiTabGrainline->comboBoxGrainlineTopPin);
InitPinPoint(uiTabGrainline->comboBoxGrainlineBottomPin); InitPinPoint(uiTabGrainline->comboBoxGrainlineBottomPin);
connect(uiTabGrainline->comboBoxGrainlineTopPin, &QComboBox::currentTextChanged, connect(uiTabGrainline->comboBoxGrainlineTopPin, &QComboBox::currentTextChanged, this,
this, &DialogSeamAllowance::GrainlinePinPointChanged); &DialogSeamAllowance::GrainlinePinPointChanged);
connect(uiTabGrainline->comboBoxGrainlineBottomPin, &QComboBox::currentTextChanged, connect(uiTabGrainline->comboBoxGrainlineBottomPin, &QComboBox::currentTextChanged, this,
this, &DialogSeamAllowance::GrainlinePinPointChanged); &DialogSeamAllowance::GrainlinePinPointChanged);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -3608,19 +3626,19 @@ void DialogSeamAllowance::InitPassmarksTab()
// notch list // notch list
InitPassmarksList(); InitPassmarksList();
connect(uiTabPassmarks->comboBoxPassmarks, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(uiTabPassmarks->comboBoxPassmarks, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
this, &DialogSeamAllowance::PassmarkChanged); &DialogSeamAllowance::PassmarkChanged);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
connect(uiTabPassmarks->buttonGroupLineType, QOverload<int>::of(&QButtonGroup::buttonClicked), connect(uiTabPassmarks->buttonGroupLineType, QOverload<int>::of(&QButtonGroup::buttonClicked), this,
this, &DialogSeamAllowance::PassmarkLineTypeChanged); &DialogSeamAllowance::PassmarkLineTypeChanged);
connect(uiTabPassmarks->buttonGroupAngleType, QOverload<int>::of(&QButtonGroup::buttonClicked), connect(uiTabPassmarks->buttonGroupAngleType, QOverload<int>::of(&QButtonGroup::buttonClicked), this,
this, &DialogSeamAllowance::PassmarkAngleTypeChanged); &DialogSeamAllowance::PassmarkAngleTypeChanged);
#else #else
connect(uiTabPassmarks->buttonGroupLineType, &QButtonGroup::idClicked, connect(uiTabPassmarks->buttonGroupLineType, &QButtonGroup::idClicked, this,
this, &DialogSeamAllowance::PassmarkLineTypeChanged); &DialogSeamAllowance::PassmarkLineTypeChanged);
connect(uiTabPassmarks->buttonGroupAngleType, &QButtonGroup::idClicked, connect(uiTabPassmarks->buttonGroupAngleType, &QButtonGroup::idClicked, this,
this, &DialogSeamAllowance::PassmarkAngleTypeChanged); &DialogSeamAllowance::PassmarkAngleTypeChanged);
#endif #endif
connect(uiTabPassmarks->checkBoxShowSecondPassmark, &QCheckBox::stateChanged, this, connect(uiTabPassmarks->checkBoxShowSecondPassmark, &QCheckBox::stateChanged, this,
&DialogSeamAllowance::PassmarkShowSecondChanged); &DialogSeamAllowance::PassmarkShowSecondChanged);
@ -3632,7 +3650,8 @@ void DialogSeamAllowance::InitPassmarksTab()
void DialogSeamAllowance::InitPlaceLabelsTab() void DialogSeamAllowance::InitPlaceLabelsTab()
{ {
uiTabPlaceLabels->listWidgetPlaceLabels->setContextMenuPolicy(Qt::CustomContextMenu); uiTabPlaceLabels->listWidgetPlaceLabels->setContextMenuPolicy(Qt::CustomContextMenu);
connect(uiTabPlaceLabels->listWidgetPlaceLabels, &QListWidget::currentRowChanged, this, [this]() connect(uiTabPlaceLabels->listWidgetPlaceLabels, &QListWidget::currentRowChanged, this,
[this]()
{ {
if (not m_visSpecialPoints.isNull()) if (not m_visSpecialPoints.isNull())
{ {
@ -3661,6 +3680,23 @@ void DialogSeamAllowance::InitAllPinComboboxes()
InitPinPoint(uiTabLabels->comboBoxPLBottomRightPin); InitPinPoint(uiTabLabels->comboBoxPLBottomRightPin);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::InitLabelFontSize(QComboBox *box)
{
SCASSERT(box != nullptr);
box->clear();
box->addItem(tr("Default"), 0);
// Get the available font sizes
for (auto size : QFontDatabase::standardSizes())
{
if (size >= VCommonSettings::MinPieceLabelFontPointSize())
{
box->addItem(QString::number(size), size);
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto DialogSeamAllowance::GetFormulaSAWidth() const -> QString auto DialogSeamAllowance::GetFormulaSAWidth() const -> QString
{ {
@ -3677,8 +3713,8 @@ auto DialogSeamAllowance::UndoStack() -> QVector<QPointer<VUndoCommand>> &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::SetFormulaSAWidth(const QString &formula) void DialogSeamAllowance::SetFormulaSAWidth(const QString &formula)
{ {
const QString width = VAbstractApplication::VApp()->TrVars() const QString width = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (width.length() > 80) if (width.length() > 80)
{ {
@ -3700,8 +3736,8 @@ void DialogSeamAllowance::SetFormulaSAWidth(const QString &formula)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::SetFormulaPassmarkLength(const QString &formula) void DialogSeamAllowance::SetFormulaPassmarkLength(const QString &formula)
{ {
const QString width = VAbstractApplication::VApp()->TrVars() const QString width = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (width.length() > 80) if (width.length() > 80)
{ {
@ -3795,8 +3831,8 @@ void DialogSeamAllowance::SetGrainlineAngle(QString angleFormula)
angleFormula = '0'; angleFormula = '0';
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(angleFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); angleFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3815,8 +3851,8 @@ void DialogSeamAllowance::SetGrainlineLength(QString lengthFormula)
lengthFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit())); lengthFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit()));
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(lengthFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); lengthFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3836,8 +3872,8 @@ void DialogSeamAllowance::SetDLWidth(QString widthFormula)
widthFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit())); widthFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit()));
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(widthFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); widthFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3857,8 +3893,8 @@ void DialogSeamAllowance::SetDLHeight(QString heightFormula)
heightFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit())); heightFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit()));
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(heightFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); heightFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3878,8 +3914,8 @@ void DialogSeamAllowance::SetDLAngle(QString angleFormula)
angleFormula = '0'; angleFormula = '0';
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(angleFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); angleFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3899,8 +3935,8 @@ void DialogSeamAllowance::SetPLWidth(QString widthFormula)
widthFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit())); widthFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit()));
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(widthFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); widthFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3920,8 +3956,8 @@ void DialogSeamAllowance::SetPLHeight(QString heightFormula)
heightFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit())); heightFormula = QString().setNum(UnitConvertor(10, Unit::Cm, *data->GetPatternUnit()));
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(heightFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); heightFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3941,8 +3977,8 @@ void DialogSeamAllowance::SetPLAngle(QString angleFormula)
angleFormula = '0'; angleFormula = '0';
} }
const QString formula = VAbstractApplication::VApp()->TrVars() const QString formula = VAbstractApplication::VApp()->TrVars()->FormulaToUser(
->FormulaToUser(angleFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator()); angleFormula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
// increase height if needed. // increase height if needed.
if (formula.length() > 80) if (formula.length() > 80)
{ {
@ -3961,8 +3997,8 @@ auto DialogSeamAllowance::CurrentRect() const -> QRectF
if (QListWidgetItem *item = uiTabPlaceLabels->listWidgetPlaceLabels->currentItem()) if (QListWidgetItem *item = uiTabPlaceLabels->listWidgetPlaceLabels->currentItem())
{ {
VPlaceLabelItem label = CurrentPlaceLabel(qvariant_cast<quint32>(item->data(Qt::UserRole))); VPlaceLabelItem label = CurrentPlaceLabel(qvariant_cast<quint32>(item->data(Qt::UserRole)));
rect = QRectF(QPointF(label.x() - label.GetWidth()/2.0, label.y() - label.GetHeight()/2.0), rect = QRectF(QPointF(label.x() - label.GetWidth() / 2.0, label.y() - label.GetHeight() / 2.0),
QPointF(label.x() + label.GetWidth()/2.0, label.y() + label.GetHeight()/2.0)); QPointF(label.x() + label.GetWidth() / 2.0, label.y() + label.GetHeight() / 2.0));
} }
return rect; return rect;
} }
@ -4021,7 +4057,7 @@ auto DialogSeamAllowance::GetDefaultPieceName() const -> QString
QString name = defName; QString name = defName;
int i = 0; int i = 0;
while(names.contains(name)) while (names.contains(name))
{ {
name = defName + QStringLiteral("_%1").arg(++i); name = defName + QStringLiteral("_%1").arg(++i);
} }
@ -4149,39 +4185,39 @@ void DialogSeamAllowance::InitGradationPlaceholders()
{ {
QString label = VAbstractValApplication::VApp()->GetDimensionHeightLabel(); QString label = VAbstractValApplication::VApp()->GetDimensionHeightLabel();
m_gradationPlaceholders.insert(pl_heightLabel, qMakePair(tr("Height label", "dimension"), m_gradationPlaceholders.insert(
not label.isEmpty() ? label : heightValue)); pl_heightLabel, qMakePair(tr("Height label", "dimension"), not label.isEmpty() ? label : heightValue));
m_gradationPlaceholders.insert(pl_dimensionXLabel, qMakePair(tr("Dimension X label", "dimension"), m_gradationPlaceholders.insert(pl_dimensionXLabel, qMakePair(tr("Dimension X label", "dimension"),
not label.isEmpty() ? label : heightValue)); not label.isEmpty() ? label : heightValue));
label = VAbstractValApplication::VApp()->GetDimensionSizeLabel(); label = VAbstractValApplication::VApp()->GetDimensionSizeLabel();
m_gradationPlaceholders.insert(pl_sizeLabel, qMakePair(tr("Size label", "dimension"), m_gradationPlaceholders.insert(
not label.isEmpty() ? label : sizeValue)); pl_sizeLabel, qMakePair(tr("Size label", "dimension"), not label.isEmpty() ? label : sizeValue));
m_gradationPlaceholders.insert(pl_dimensionYLabel, qMakePair(tr("Dimension Y label", "dimension"), m_gradationPlaceholders.insert(pl_dimensionYLabel, qMakePair(tr("Dimension Y label", "dimension"),
not label.isEmpty() ? label : sizeValue)); not label.isEmpty() ? label : sizeValue));
label = VAbstractValApplication::VApp()->GetDimensionHipLabel(); label = VAbstractValApplication::VApp()->GetDimensionHipLabel();
m_gradationPlaceholders.insert(pl_hipLabel, qMakePair(tr("Hip label", "dimension"), m_gradationPlaceholders.insert(pl_hipLabel,
not label.isEmpty() ? label : hipValue)); qMakePair(tr("Hip label", "dimension"), not label.isEmpty() ? label : hipValue));
m_gradationPlaceholders.insert(pl_dimensionZLabel, qMakePair(tr("Dimension Z label", "dimension"), m_gradationPlaceholders.insert(pl_dimensionZLabel, qMakePair(tr("Dimension Z label", "dimension"),
not label.isEmpty() ? label : hipValue)); not label.isEmpty() ? label : hipValue));
label = VAbstractValApplication::VApp()->GetDimensionWaistLabel(); label = VAbstractValApplication::VApp()->GetDimensionWaistLabel();
m_gradationPlaceholders.insert(pl_waistLabel, qMakePair(tr("Waist label", "dimension"), m_gradationPlaceholders.insert(
not label.isEmpty() ? label : waistValue)); pl_waistLabel, qMakePair(tr("Waist label", "dimension"), not label.isEmpty() ? label : waistValue));
m_gradationPlaceholders.insert(pl_dimensionWLabel, qMakePair(tr("Dimension W label", "dimension"), m_gradationPlaceholders.insert(pl_dimensionWLabel, qMakePair(tr("Dimension W label", "dimension"),
not label.isEmpty() ? label : waistValue)); not label.isEmpty() ? label : waistValue));
} }
{ {
const QMap<QString, QSharedPointer<VMeasurement> > measurements = data->DataMeasurements(); const QMap<QString, QSharedPointer<VMeasurement>> measurements = data->DataMeasurements();
auto i = measurements.constBegin(); auto i = measurements.constBegin();
while (i != measurements.constEnd()) while (i != measurements.constEnd())
{ {
QString description = i.value()->GetGuiText().isEmpty() ? i.key() : i.value()->GetGuiText(); QString description = i.value()->GetGuiText().isEmpty() ? i.key() : i.value()->GetGuiText();
m_gradationPlaceholders.insert(pl_measurement + i.key(), m_gradationPlaceholders.insert(
qMakePair(tr("Measurement: %1").arg(description), pl_measurement + i.key(),
QString::number(*i.value()->GetValue()))); qMakePair(tr("Measurement: %1").arg(description), QString::number(*i.value()->GetValue())));
++i; ++i;
} }
} }
@ -4421,7 +4457,7 @@ void DialogSeamAllowance::SetMoveControls()
uiTabPaths->toolButtonDown->setEnabled(true); uiTabPaths->toolButtonDown->setEnabled(true);
uiTabPaths->toolButtonBottom->setEnabled(true); uiTabPaths->toolButtonBottom->setEnabled(true);
} }
else if (uiTabPaths->listWidgetMainPath->currentRow() == uiTabPaths->listWidgetMainPath->count()-1) else if (uiTabPaths->listWidgetMainPath->currentRow() == uiTabPaths->listWidgetMainPath->count() - 1)
{ {
uiTabPaths->toolButtonTop->setEnabled(true); uiTabPaths->toolButtonTop->setEnabled(true);
uiTabPaths->toolButtonUp->setEnabled(true); uiTabPaths->toolButtonUp->setEnabled(true);
@ -4448,9 +4484,10 @@ void DialogSeamAllowance::EditPatternLabel()
{ {
if (m_patternLabelDataChanged && m_askSavePatternLabelData) if (m_patternLabelDataChanged && m_askSavePatternLabelData)
{ {
QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Save label data."), QMessageBox::StandardButton answer = QMessageBox::question(
this, tr("Save label data."),
tr("Label data were changed. Do you want to save them before editing label template?"), tr("Label data were changed. Do you want to save them before editing label template?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (answer == QMessageBox::Yes) if (answer == QMessageBox::Yes)
{ {

View file

@ -36,14 +36,14 @@
namespace Ui namespace Ui
{ {
class DialogSeamAllowance; class DialogSeamAllowance;
class TabPaths; class TabPaths;
class TabLabels; class TabLabels;
class TabGrainline; class TabGrainline;
class TabPins; class TabPins;
class TabPassmarks; class TabPassmarks;
class TabPlaceLabels; class TabPlaceLabels;
} } // namespace Ui
class VisPieceSpecialPoints; class VisPieceSpecialPoints;
class FancyTabBar; class FancyTabBar;
@ -54,8 +54,7 @@ class DialogSeamAllowance : public DialogTool
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
DialogSeamAllowance(const VContainer *data, VAbstractPattern *doc, quint32 toolId, DialogSeamAllowance(const VContainer *data, VAbstractPattern *doc, quint32 toolId, QWidget *parent = nullptr);
QWidget *parent = nullptr);
DialogSeamAllowance(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); DialogSeamAllowance(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
~DialogSeamAllowance() override; ~DialogSeamAllowance() override;
@ -302,6 +301,7 @@ private:
void InitPassmarksTab(); void InitPassmarksTab();
void InitPlaceLabelsTab(); void InitPlaceLabelsTab();
void InitAllPinComboboxes(); void InitAllPinComboboxes();
void InitLabelFontSize(QComboBox *box);
void SetFormulaSAWidth(const QString &formula); void SetFormulaSAWidth(const QString &formula);
void SetFormulaPassmarkLength(const QString &formula); void SetFormulaPassmarkLength(const QString &formula);

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>628</width> <width>550</width>
<height>516</height> <height>534</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -28,8 +28,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>608</width> <width>530</width>
<height>496</height> <height>514</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -455,7 +455,28 @@
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_8"> <layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QFormLayout" name="formLayout_8">
<item row="0" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Font size:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxPieceLabelSize"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_18"> <layout class="QHBoxLayout" name="horizontalLayout_18">
<item alignment="Qt::AlignLeft"> <item alignment="Qt::AlignLeft">
@ -987,7 +1008,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item alignment="Qt::AlignRight"> <item>
<widget class="QLabel" name="labelDLAngle"> <widget class="QLabel" name="labelDLAngle">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
@ -1112,7 +1133,28 @@
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_14"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QFormLayout" name="formLayout_13">
<item row="0" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Font size:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxPatternLabelSize"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_25"> <layout class="QHBoxLayout" name="horizontalLayout_25">
<item alignment="Qt::AlignLeft"> <item alignment="Qt::AlignLeft">

View file

@ -505,7 +505,8 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement
doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrMy, data.GetPos().y());
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, data.GetFontSize()); doc->SetAttributeOrRemoveIf<int>(domData, AttrFont, data.GetFontSize(),
[](int size) noexcept { return size == 0; });
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, data.CenterPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, data.CenterPin(),
[](quint32 pin) noexcept { return pin == NULL_ID; }); [](quint32 pin) noexcept { return pin == NULL_ID; });
@ -528,7 +529,8 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE
doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y());
doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight()); doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttributeOrRemoveIf<int>(domData, AttrFont, geom.GetFontSize(),
[](int size) noexcept { return size == 0; });
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation());
doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, geom.CenterPin(), doc->SetAttributeOrRemoveIf<quint32>(domData, AttrCenterPin, geom.CenterPin(),
[](quint32 pin) noexcept { return pin <= NULL_ID; }); [](quint32 pin) noexcept { return pin <= NULL_ID; });
@ -767,6 +769,7 @@ void VToolSeamAllowance::UpdateDetailLabel()
if (PrepareLabelData(labelData, pins, m_dataLabel, pos, labelAngle)) if (PrepareLabelData(labelData, pins, m_dataLabel, pos, labelAngle))
{ {
m_dataLabel->SetPieceName(detail.GetName());
m_dataLabel->UpdateData(detail.GetName(), labelData, getData()); m_dataLabel->UpdateData(detail.GetName(), labelData, getData());
UpdateLabelItem(m_dataLabel, pos, labelAngle); UpdateLabelItem(m_dataLabel, pos, labelAngle);
} }
@ -794,6 +797,7 @@ void VToolSeamAllowance::UpdatePatternInfo()
if (PrepareLabelData(geom, pins, m_patternInfo, pos, labelAngle)) if (PrepareLabelData(geom, pins, m_patternInfo, pos, labelAngle))
{ {
m_patternInfo->SetPieceName(detail.GetName());
m_patternInfo->UpdateData(doc, getData()); m_patternInfo->UpdateData(doc, getData());
UpdateLabelItem(m_patternInfo, pos, labelAngle); UpdateLabelItem(m_patternInfo, pos, labelAngle);
} }
@ -872,7 +876,7 @@ void VToolSeamAllowance::SaveMoveDetail(const QPointF &ptPos)
/** /**
* @brief SaveResizeDetail saves the resize detail label operation to the undo stack * @brief SaveResizeDetail saves the resize detail label operation to the undo stack
*/ */
void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW, int iFontSize) void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW)
{ {
VPiece oldDet = VAbstractTool::data.GetPiece(m_id); VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
@ -881,7 +885,6 @@ void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW, int iFontSize)
newDet.GetPieceLabelData().SetLabelWidth(QString().setNum(dLabelW)); newDet.GetPieceLabelData().SetLabelWidth(QString().setNum(dLabelW));
const qreal height = FromPixel(m_dataLabel->boundingRect().height(), *VDataTool::data.GetPatternUnit()); const qreal height = FromPixel(m_dataLabel->boundingRect().height(), *VDataTool::data.GetPatternUnit());
newDet.GetPieceLabelData().SetLabelHeight(QString().setNum(height)); newDet.GetPieceLabelData().SetLabelHeight(QString().setNum(height));
newDet.GetPieceLabelData().SetFontSize(iFontSize);
auto *resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id); auto *resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
resizeCommand->setText(tr("resize pattern piece label")); resizeCommand->setText(tr("resize pattern piece label"));
@ -928,7 +931,7 @@ void VToolSeamAllowance::SaveMovePattern(const QPointF &ptPos)
/** /**
* @brief: SaveResizePattern saves the pattern label width and font size * @brief: SaveResizePattern saves the pattern label width and font size
*/ */
void VToolSeamAllowance::SaveResizePattern(qreal dLabelW, int iFontSize) void VToolSeamAllowance::SaveResizePattern(qreal dLabelW)
{ {
VPiece oldDet = VAbstractTool::data.GetPiece(m_id); VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet; VPiece newDet = oldDet;
@ -937,7 +940,6 @@ void VToolSeamAllowance::SaveResizePattern(qreal dLabelW, int iFontSize)
newDet.GetPatternLabelData().SetLabelWidth(QString().setNum(dLabelW)); newDet.GetPatternLabelData().SetLabelWidth(QString().setNum(dLabelW));
qreal height = FromPixel(m_patternInfo->boundingRect().height(), *VDataTool::data.GetPatternUnit()); qreal height = FromPixel(m_patternInfo->boundingRect().height(), *VDataTool::data.GetPatternUnit());
newDet.GetPatternLabelData().SetLabelHeight(QString().setNum(height)); newDet.GetPatternLabelData().SetLabelHeight(QString().setNum(height));
newDet.GetPatternLabelData().SetFontSize(iFontSize);
auto *resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id); auto *resizeCommand = new SavePieceOptions(oldDet, newDet, doc, m_id);
resizeCommand->setText(tr("resize pattern info label")); resizeCommand->setText(tr("resize pattern info label"));
@ -1372,8 +1374,8 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
m_sceneDetails(initData.scene), m_sceneDetails(initData.scene),
m_drawName(initData.drawName), m_drawName(initData.drawName),
m_seamAllowance(new VNoBrushScalePathItem(this)), m_seamAllowance(new VNoBrushScalePathItem(this)),
m_dataLabel(new VTextGraphicsItem(this)), m_dataLabel(new VTextGraphicsItem(VTextGraphicsItem::ItemType::PieceLabel, this)),
m_patternInfo(new VTextGraphicsItem(this)), m_patternInfo(new VTextGraphicsItem(VTextGraphicsItem::ItemType::PatternLabel, this)),
m_grainLine(new VGrainlineItem(this)), m_grainLine(new VGrainlineItem(this)),
m_passmarks(new QGraphicsPathItem(this)), m_passmarks(new QGraphicsPathItem(this)),
m_placeLabels(new QGraphicsPathItem(this)) m_placeLabels(new QGraphicsPathItem(this))
@ -2116,10 +2118,12 @@ auto VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, co
} }
labelItem->SetMoveType(type); labelItem->SetMoveType(type);
QFont fnt = VAbstractApplication::VApp()->Settings()->GetLabelFont(); VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
QFont fnt = settings->GetLabelFont();
{ {
const int iFS = labelData.GetFontSize(); const int iFS = labelData.GetFontSize();
iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS); iFS < VCommonSettings::MinPieceLabelFontPointSize() ? fnt.setPointSize(settings->GetPieceLabelFontPointSize())
: fnt.setPointSize(iFS);
} }
labelItem->SetFont(fnt); labelItem->SetFont(fnt);
labelItem->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()), labelItem->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()),

View file

@ -57,14 +57,11 @@ class VToolSeamAllowance : public VInteractiveTool, public QGraphicsPathItem
public: public:
~VToolSeamAllowance() override = default; ~VToolSeamAllowance() override = default;
static auto Create(const QPointer<DialogTool> &dialog, static auto Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VMainGraphicsScene *scene,
VAbstractPattern *doc,
VContainer *data) -> VToolSeamAllowance *; VContainer *data) -> VToolSeamAllowance *;
static auto Create(VToolSeamAllowanceInitData &initData) -> VToolSeamAllowance *; static auto Create(VToolSeamAllowanceInitData &initData) -> VToolSeamAllowance *;
static auto Duplicate(const QPointer<DialogTool> &dialog, static auto Duplicate(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc)
VMainGraphicsScene *scene, -> VToolSeamAllowance *;
VAbstractPattern *doc) -> VToolSeamAllowance *;
static auto Duplicate(VToolSeamAllowanceInitData &initData) -> VToolSeamAllowance *; static auto Duplicate(VToolSeamAllowanceInitData &initData) -> VToolSeamAllowance *;
static const quint8 pieceVersion; static const quint8 pieceVersion;
@ -89,32 +86,16 @@ public:
void RemoveWithConfirm(bool ask); void RemoveWithConfirm(bool ask);
static void InsertNodes(const QVector<VPieceNode> &nodes, static void InsertNodes(const QVector<VPieceNode> &nodes, quint32 pieceId, VMainGraphicsScene *scene,
quint32 pieceId, VContainer *data, VAbstractPattern *doc);
VMainGraphicsScene *scene,
VContainer *data,
VAbstractPattern *doc);
static void AddAttributes(VAbstractPattern *doc, static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece);
QDomElement &domElement,
quint32 id,
const VPiece &piece);
static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, CustomSARecord record); static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, CustomSARecord record);
static void AddCSARecords(VAbstractPattern *doc, static void AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, const QVector<CustomSARecord> &records);
QDomElement &domElement, static void AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &paths);
const QVector<CustomSARecord> &records); static void AddPins(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &pins);
static void AddInternalPaths(VAbstractPattern *doc, static void AddPlaceLabels(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &placeLabels);
QDomElement &domElement, static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
const QVector<quint32> &paths);
static void AddPins(VAbstractPattern *doc,
QDomElement &domElement,
const QVector<quint32> &pins);
static void AddPlaceLabels(VAbstractPattern *doc,
QDomElement &domElement,
const QVector<quint32> &placeLabels);
static void AddPatternPieceData(VAbstractPattern *doc,
QDomElement &domElement,
const VPiece &piece);
static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece); static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
@ -126,7 +107,10 @@ public:
void RefreshGeometry(bool updateChildren = true); void RefreshGeometry(bool updateChildren = true);
auto type() const -> int override { return Type; } auto type() const -> int override { return Type; }
enum { Type = UserType + static_cast<int>(Tool::Piece) }; enum
{
Type = UserType + static_cast<int>(Tool::Piece)
};
auto getTagName() const -> QString override; auto getTagName() const -> QString override;
void ShowVisualization(bool show) override; void ShowVisualization(bool show) override;
@ -152,10 +136,10 @@ public slots:
protected slots: protected slots:
void UpdateGrainline(); void UpdateGrainline();
void SaveMoveDetail(const QPointF &ptPos); void SaveMoveDetail(const QPointF &ptPos);
void SaveResizeDetail(qreal dLabelW, int iFontSize); void SaveResizeDetail(qreal dLabelW);
void SaveRotationDetail(qreal dRot); void SaveRotationDetail(qreal dRot);
void SaveMovePattern(const QPointF &ptPos); void SaveMovePattern(const QPointF &ptPos);
void SaveResizePattern(qreal dLabelW, int iFontSize); void SaveResizePattern(qreal dLabelW);
void SaveRotationPattern(qreal dRot); void SaveRotationPattern(qreal dRot);
void SaveMoveGrainline(const QPointF &ptPos); void SaveMoveGrainline(const QPointF &ptPos);
void SaveResizeGrainline(qreal dLength); void SaveResizeGrainline(qreal dLength);
@ -211,66 +195,45 @@ private:
/** @brief m_geometryIsReady is true when a piece's geometry is ready and checks for validity can be enabled. */ /** @brief m_geometryIsReady is true when a piece's geometry is ready and checks for validity can be enabled. */
bool m_geometryIsReady{false}; bool m_geometryIsReady{false};
explicit VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, explicit VToolSeamAllowance(const VToolSeamAllowanceInitData &initData, QGraphicsItem *parent = nullptr);
QGraphicsItem *parent = nullptr);
void UpdateExcludeState(); void UpdateExcludeState();
void UpdateInternalPaths(); void UpdateInternalPaths();
auto FindLabelGeometry(const VPatternLabelData &labelData, auto FindLabelGeometry(const VPatternLabelData &labelData, const QVector<quint32> &pins, qreal &rotationAngle,
const QVector<quint32> &pins, qreal &labelWidth, qreal &labelHeight, QPointF &pos) -> VPieceItem::MoveTypes;
qreal &rotationAngle, auto FindGrainlineGeometry(const VGrainlineData &geom, const QVector<quint32> &pins, qreal &length,
qreal &labelWidth, qreal &rotationAngle, QPointF &pos) -> VPieceItem::MoveTypes;
qreal &labelHeight,
QPointF &pos) -> VPieceItem::MoveTypes;
auto FindGrainlineGeometry(const VGrainlineData &geom,
const QVector<quint32> &pins,
qreal &length,
qreal &rotationAngle,
QPointF &pos) -> VPieceItem::MoveTypes;
void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); void InitNodes(const VPiece &detail, VMainGraphicsScene *scene);
static void InitNode(const VPieceNode &node, static void InitNode(const VPieceNode &node, VMainGraphicsScene *scene, VToolSeamAllowance *parent);
VMainGraphicsScene *scene,
VToolSeamAllowance *parent);
void InitCSAPaths(const VPiece &detail) const; void InitCSAPaths(const VPiece &detail) const;
void InitInternalPaths(const VPiece &detail); void InitInternalPaths(const VPiece &detail);
void InitSpecialPoints(const QVector<quint32> &points) const; void InitSpecialPoints(const QVector<quint32> &points) const;
auto PrepareLabelData(const VPatternLabelData &labelData, auto PrepareLabelData(const VPatternLabelData &labelData, const QVector<quint32> &pins,
const QVector<quint32> &pins, VTextGraphicsItem *labelItem, QPointF &pos, qreal &labelAngle) -> bool;
VTextGraphicsItem *labelItem,
QPointF &pos,
qreal &labelAngle) -> bool;
auto SelectedTools() const -> QList<VToolSeamAllowance *>; auto SelectedTools() const -> QList<VToolSeamAllowance *>;
auto IsGrainlinePositionValid() const -> bool; auto IsGrainlinePositionValid() const -> bool;
static void AddPointRecords(VAbstractPattern *doc, static void AddPointRecords(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &records,
QDomElement &domElement,
const QVector<quint32> &records,
const QString &tag); const QString &tag);
static auto DuplicateNodes(const VPiecePath &path, static auto DuplicateNodes(const VPiecePath &path, const VToolSeamAllowanceInitData &initData,
const VToolSeamAllowanceInitData &initData,
QMap<quint32, quint32> &replacements) -> QVector<VPieceNode>; QMap<quint32, quint32> &replacements) -> QVector<VPieceNode>;
static auto DuplicateNode(const VPieceNode &node, const VToolSeamAllowanceInitData &initData) static auto DuplicateNode(const VPieceNode &node, const VToolSeamAllowanceInitData &initData) -> quint32;
-> quint32;
static auto DuplicatePiecePath(quint32 id, const VToolSeamAllowanceInitData &initData) static auto DuplicatePiecePath(quint32 id, const VToolSeamAllowanceInitData &initData) -> quint32;
-> quint32;
static auto DuplicateCustomSARecords(const QVector<CustomSARecord> &records, static auto DuplicateCustomSARecords(const QVector<CustomSARecord> &records,
const VToolSeamAllowanceInitData &initData, const VToolSeamAllowanceInitData &initData,
const QMap<quint32, quint32> &replacements) const QMap<quint32, quint32> &replacements) -> QVector<CustomSARecord>;
-> QVector<CustomSARecord>;
static auto DuplicateInternalPaths(const QVector<quint32> &iPaths, static auto DuplicateInternalPaths(const QVector<quint32> &iPaths, const VToolSeamAllowanceInitData &initData)
const VToolSeamAllowanceInitData &initData)
-> QVector<quint32>; -> QVector<quint32>;
static auto DuplicatePlaceLabels(const QVector<quint32> &placeLabels, static auto DuplicatePlaceLabels(const QVector<quint32> &placeLabels, const VToolSeamAllowanceInitData &initData)
const VToolSeamAllowanceInitData &initData)
-> QVector<quint32>; -> QVector<quint32>;
}; };

View file

@ -85,16 +85,16 @@ void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic
{ {
auto UpdateLine = [this]() auto UpdateLine = [this]()
{ {
if (VScenePoint *parent = dynamic_cast<VScenePoint *>(parentItem())) if (auto *parent = dynamic_cast<VScenePoint *>(parentItem()))
{ {
parent->RefreshLine(); parent->RefreshLine();
} }
}; };
QFont font = this->font(); QFont font = this->font();
if (font.pointSize() != VAbstractApplication::VApp()->Settings()->GetLabelFontSize()) if (font.pointSize() != VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize())
{ {
font.setPointSize(VAbstractApplication::VApp()->Settings()->GetLabelFontSize()); font.setPointSize(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize());
setFont(font); setFont(font);
} }
@ -373,8 +373,8 @@ void VGraphicsSimpleTextItem::Init()
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
this->setAcceptHoverEvents(true); this->setAcceptHoverEvents(true);
QFont font = this->font(); QFont font = this->font();
font.setPointSize(VAbstractApplication::VApp()->Settings()->GetLabelFontSize()); font.setPointSize(VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize());
setFont(font); setFont(font);
m_oldScale = minVisibleFontSize / VAbstractApplication::VApp()->Settings()->GetLabelFontSize(); m_oldScale = minVisibleFontSize / VAbstractApplication::VApp()->Settings()->GetPatternLabelFontSize();
setScale(m_oldScale); setScale(m_oldScale);
} }

View file

@ -83,7 +83,7 @@ void VScenePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
painter->restore(); painter->restore();
} }
if (settings->GetLabelFontSize()*scale < minVisibleFontSize || settings->GetHideLabels()) if (settings->GetPatternLabelFontSize()*scale < minVisibleFontSize || settings->GetHideLabels())
{ {
m_namePoint->setVisible(false); m_namePoint->setVisible(false);
m_lineName->setVisible(false); m_lineName->setVisible(false);

View file

@ -27,6 +27,7 @@
*************************************************************************/ *************************************************************************/
#include <QColor> #include <QColor>
#include <QDebug>
#include <QFlags> #include <QFlags>
#include <QFont> #include <QFont>
#include <QGraphicsItem> #include <QGraphicsItem>
@ -37,24 +38,23 @@
#include <QPoint> #include <QPoint>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <Qt> #include <Qt>
#include <QDebug>
#include "../ifc/exception/vexception.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vmath.h"
#include "../vmisc/literals.h" #include "../vmisc/literals.h"
#include "../vmisc/compatibility.h" #include "../vmisc/vabstractvalapplication.h"
#include "vtextgraphicsitem.h" #include "vtextgraphicsitem.h"
const qreal resizeSquare = MmToPixel(3.);
const qreal rotateCircle = MmToPixel(2.);
#define ROTATE_RECT 60
#define ROTATE_ARC 50
const qreal minW = MmToPixel(4.) + resizeSquare;
const qreal minH = MmToPixel(4.) + resizeSquare;
#define ACTIVE_Z 10
namespace namespace
{ {
constexpr qreal resizeSquare = MmToPixel(3.);
constexpr qreal rotateCircle = MmToPixel(2.);
constexpr int rotateRect = 60;
constexpr int rotateArc = 50;
constexpr qreal minW = MmToPixel(4.) + resizeSquare;
constexpr qreal minH = MmToPixel(4.) + resizeSquare;
constexpr int activeZ = 10;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GetBoundingRect calculates the bounding box around rectBB rectangle, rotated around its center by dRot degrees * @brief GetBoundingRect calculates the bounding box around rectBB rectangle, rotated around its center by dRot degrees
@ -64,7 +64,7 @@ namespace
*/ */
auto GetBoundingRect(const QRectF &rectBB, qreal dRot) -> QRectF auto GetBoundingRect(const QRectF &rectBB, qreal dRot) -> QRectF
{ {
QPointF apt[4] = { rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight() }; std::array<QPointF, 4> apt = {rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight()};
QPointF ptCenter = rectBB.center(); QPointF ptCenter = rectBB.center();
qreal dX1 = 0; qreal dX1 = 0;
@ -73,11 +73,11 @@ auto GetBoundingRect(const QRectF &rectBB, qreal dRot) -> QRectF
qreal dY2 = 0; qreal dY2 = 0;
double dAng = qDegreesToRadians(dRot); double dAng = qDegreesToRadians(dRot);
for (int i = 0; i < 4; ++i) for (std::size_t i = 0; i < 4; ++i)
{ {
QPointF pt = apt[i] - ptCenter; QPointF pt = apt.at(i) - ptCenter;
qreal dX = pt.x()*cos(dAng) + pt.y()*sin(dAng); qreal dX = pt.x() * cos(dAng) + pt.y() * sin(dAng);
qreal dY = -pt.x()*sin(dAng) + pt.y()*cos(dAng); qreal dY = -pt.x() * sin(dAng) + pt.y() * cos(dAng);
if (i == 0) if (i == 0)
{ {
@ -110,22 +110,16 @@ auto GetBoundingRect(const QRectF &rectBB, qreal dRot) -> QRectF
rect.setHeight(dY2 - dY1); rect.setHeight(dY2 - dY1);
return rect; return rect;
} }
}//static functions } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VTextGraphicsItem::VTextGraphicsItem constructor * @brief VTextGraphicsItem::VTextGraphicsItem constructor
* @param pParent pointer to the parent item * @param pParent pointer to the parent item
*/ */
VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) VTextGraphicsItem::VTextGraphicsItem(ItemType type, QGraphicsItem *pParent)
: VPieceItem(pParent), : VPieceItem(pParent),
m_ptStartPos(), m_itemType(type)
m_ptStart(),
m_szStart(),
m_dRotation(0),
m_dAngle(0),
m_rectResize(),
m_tm()
{ {
m_inactiveZ = 2; m_inactiveZ = 2;
SetSize(minW, minH); SetSize(minW, minH);
@ -137,7 +131,7 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent)
* @brief VTextGraphicsItem::SetFont sets the item font * @brief VTextGraphicsItem::SetFont sets the item font
* @param fnt font to be used in item * @param fnt font to be used in item
*/ */
void VTextGraphicsItem::SetFont(const QFont& fnt) void VTextGraphicsItem::SetFont(const QFont &fnt)
{ {
m_tm.SetFont(fnt); m_tm.SetFont(fnt);
} }
@ -155,38 +149,9 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
Q_UNUSED(option) Q_UNUSED(option)
painter->fillRect(m_rectBoundingBox, QColor(251, 251, 175, 128 /*50% opacity*/)); painter->fillRect(m_rectBoundingBox, QColor(251, 251, 175, 128 /*50% opacity*/));
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter->setPen(Qt::black); painter->setPen(Qt::black);
QFont fnt = m_tm.GetFont();
int iW = qFloor(boundingRect().width());
// draw text lines
int iY = 0;
for (int i = 0; i < m_tm.GetSourceLinesCount(); ++i)
{
const TextLine& tl = m_tm.GetSourceLine(i);
fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize); PaintLabel(painter);
fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic);
QString qsText = tl.m_qsText;
QFontMetrics fm(fnt);
// check if the next line will go out of bounds
if (iY + fm.height() > boundingRect().height())
{
break;
}
if (TextWidth(fm, qsText) > iW)
{
qsText = fm.elidedText(qsText, Qt::ElideMiddle, iW);
}
painter->setFont(fnt);
painter->drawText(0, iY, iW, fm.height(), static_cast<int>(tl.m_eAlign), qsText);
iY += fm.height() + m_tm.GetSpacing();
}
// now draw the features specific to non-normal modes // now draw the features specific to non-normal modes
if (m_eMode != mNormal) if (m_eMode != mNormal)
@ -205,8 +170,8 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
if (m_eMode == mResize) if (m_eMode == mResize)
{ {
// draw the resize diagonal lines // draw the resize diagonal lines
painter->drawLine(1, 1, qFloor(m_rectBoundingBox.width())-1, qFloor(m_rectBoundingBox.height())-1); painter->drawLine(1, 1, qFloor(m_rectBoundingBox.width()) - 1, qFloor(m_rectBoundingBox.height()) - 1);
painter->drawLine(1, qFloor(m_rectBoundingBox.height())-1, qFloor(m_rectBoundingBox.width())-1, 1); painter->drawLine(1, qFloor(m_rectBoundingBox.height()) - 1, qFloor(m_rectBoundingBox.width()) - 1, 1);
} }
} }
else else
@ -214,24 +179,21 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
// in rotate mode, draw the circle in the middle // in rotate mode, draw the circle in the middle
painter->setPen(Qt::black); painter->setPen(Qt::black);
painter->setBrush(Qt::black); painter->setBrush(Qt::black);
painter->drawEllipse( painter->drawEllipse(QPointF(m_rectBoundingBox.width() / 2, m_rectBoundingBox.height() / 2), rotateCircle,
QPointF(m_rectBoundingBox.width()/2, m_rectBoundingBox.height()/2), rotateCircle);
rotateCircle, if (m_rectBoundingBox.width() > minW * 3 && m_rectBoundingBox.height() > minH * 3)
rotateCircle
);
if (m_rectBoundingBox.width() > minW*3 && m_rectBoundingBox.height() > minH*3)
{ {
painter->setPen(QPen(Qt::black, 3)); painter->setPen(QPen(Qt::black, 3));
painter->setBrush(Qt::NoBrush); painter->setBrush(Qt::NoBrush);
// and then draw the arc in each of the corners // and then draw the arc in each of the corners
int iTop = ROTATE_RECT - ROTATE_ARC; int iTop = rotateRect - rotateArc;
int iLeft = ROTATE_RECT - ROTATE_ARC; int iLeft = rotateRect - rotateArc;
int iRight = qRound(m_rectBoundingBox.width()) - ROTATE_RECT; int iRight = qRound(m_rectBoundingBox.width()) - rotateRect;
int iBottom = qRound(m_rectBoundingBox.height()) - ROTATE_RECT; int iBottom = qRound(m_rectBoundingBox.height()) - rotateRect;
painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16); painter->drawArc(iLeft, iTop, rotateArc, rotateArc, 180 * 16, -90 * 16);
painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16); painter->drawArc(iRight, iTop, rotateArc, rotateArc, 90 * 16, -90 * 16);
painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16); painter->drawArc(iLeft, iBottom, rotateArc, rotateArc, 270 * 16, -90 * 16);
painter->drawArc(iRight, iBottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16); painter->drawArc(iRight, iBottom, rotateArc, rotateArc, 0 * 16, -90 * 16);
} }
} }
} }
@ -284,7 +246,7 @@ auto VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal
dX = 0; dX = 0;
dY = 0; dY = 0;
if (rectParent.contains(rectBB) == false) if (not rectParent.contains(rectBB))
{ {
if (rectParent.left() - rectBB.left() > fabs(dX)) if (rectParent.left() - rectBB.left() > fabs(dX))
{ {
@ -325,7 +287,7 @@ void VTextGraphicsItem::UpdateData(const QString &qsName, const VPieceLabelData
* @brief VTextGraphicsItem::UpdateData Updates the pattern label * @brief VTextGraphicsItem::UpdateData Updates the pattern label
* @param pDoc pointer to the pattern object * @param pDoc pointer to the pattern object
*/ */
void VTextGraphicsItem::UpdateData(VAbstractPattern* pDoc, const VContainer *pattern) void VTextGraphicsItem::UpdateData(VAbstractPattern *pDoc, const VContainer *pattern)
{ {
m_tm.Update(pDoc, pattern); m_tm.Update(pDoc, pattern);
} }
@ -340,6 +302,12 @@ auto VTextGraphicsItem::GetTextLines() const -> vsizetype
return m_tm.GetSourceLinesCount(); return m_tm.GetSourceLinesCount();
} }
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::SetPieceName(const QString &name)
{
m_pieceName = name;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VTextGraphicsItem::GetFontSize returns the currently used text base font size * @brief VTextGraphicsItem::GetFontSize returns the currently used text base font size
@ -357,8 +325,8 @@ auto VTextGraphicsItem::GetFontSize() const -> int
*/ */
void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
{ {
if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick &&
&& (flags() & QGraphicsItem::ItemIsMovable)) (flags() & QGraphicsItem::ItemIsMovable))
{ {
if (m_moveType == NotMovable) if (m_moveType == NotMovable)
{ {
@ -378,10 +346,10 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
// in rotation mode, do not do any changes here, because user might want to // in rotation mode, do not do any changes here, because user might want to
// rotate the label more. // rotate the label more.
if ((m_moveType & AllModifications ) == AllModifications) if ((m_moveType & AllModifications) == AllModifications)
{ {
AllUserModifications(pME->pos()); AllUserModifications(pME->pos());
setZValue(ACTIVE_Z); setZValue(activeZ);
Update(); Update();
} }
else if (m_moveType & IsRotatable) else if (m_moveType & IsRotatable)
@ -399,7 +367,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
m_eMode = mRotate; m_eMode = mRotate;
SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
setZValue(ACTIVE_Z); setZValue(activeZ);
Update(); Update();
} }
else if (m_moveType & IsResizable) else if (m_moveType & IsResizable)
@ -412,7 +380,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
{ {
UserMoveAndResize(pME->pos()); UserMoveAndResize(pME->pos());
} }
setZValue(ACTIVE_Z); setZValue(activeZ);
Update(); Update();
} }
else if (m_moveType & IsMovable) else if (m_moveType & IsMovable)
@ -431,7 +399,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
setZValue(ACTIVE_Z); setZValue(activeZ);
Update(); Update();
} }
else else
@ -450,102 +418,19 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
* @brief VTextGraphicsItem::mouseMoveEvent handles mouse move events * @brief VTextGraphicsItem::mouseMoveEvent handles mouse move events
* @param pME pointer to QGraphicsSceneMouseEvent object * @param pME pointer to QGraphicsSceneMouseEvent object
*/ */
void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *pME)
{ {
qreal dX;
qreal dY;
QRectF rectBB;
if (m_eMode == mMove && m_moveType & IsMovable) if (m_eMode == mMove && m_moveType & IsMovable)
{ {
const QPointF ptDiff = pME->scenePos() - m_ptStart; MoveLabel(pME);
// in move mode move the label along the mouse move from the origin
QPointF pt = m_ptStartPos + ptDiff;
rectBB.setTopLeft(pt);
rectBB.setWidth(m_rectBoundingBox.width());
rectBB.setHeight(m_rectBoundingBox.height());
// before moving label to a new position, check if it will still be inside the parent item
if (IsContained(rectBB, rotation(), dX, dY) == false)
{
pt.setX(pt.x() + dX);
pt.setY(pt.y() + dY);
}
setPos(pt);
UpdateBox();
} }
else if (m_eMode == mResize && m_moveType & IsResizable) else if (m_eMode == mResize && m_moveType & IsResizable)
{ {
QLineF vectorDiff(m_ptStart, pME->scenePos()); ResizeLabel(pME);
vectorDiff.setAngle(vectorDiff.angle() + m_dRotation);
const QPointF ptDiff = vectorDiff.p2() - m_ptStart;
// in resize mode, resize the label along the mouse move from the origin
QPointF pt;
QSizeF sz;
if (m_moveType & IsMovable)
{
const qreal newWidth = m_szStart.width() + ptDiff.x();
const qreal newHeight = m_szStart.height() + ptDiff.y();
if (newWidth <= minW || newHeight <= minH)
{
return;
}
pt = m_ptStartPos;
sz = QSizeF(newWidth, newHeight);
}
else
{
const qreal newWidth = m_szStart.width() + ptDiff.x()*2.0;
const qreal newHeight = m_szStart.height() + ptDiff.y()*2.0;
if (newWidth <= minW || newHeight <= minH)
{
return;
}
pt = QPointF(m_ptRotCenter.x() - newWidth/2.0, m_ptRotCenter.y() - newHeight/2.0);
sz = QSizeF(m_szStart.width() + ptDiff.x()*2.0, m_szStart.height() + ptDiff.y()*2.0);
}
rectBB.setTopLeft(pt);
rectBB.setSize(sz);
// before resizing the label to a new size, check if it will still be inside the parent item
if (IsContained(rectBB, rotation(), dX, dY))
{
if (not (m_moveType & IsMovable))
{
setPos(pt);
}
}
else
{
return;
}
SetSize(sz.width(), sz.height());
Update();
emit SignalShrink();
} }
else if (m_eMode == mRotate && m_moveType & IsRotatable) else if (m_eMode == mRotate && m_moveType & IsRotatable)
{ {
// if the angle from the original position is small (0.5 degrees), just remeber the new angle RotateLabel(pME);
// new angle will be the starting angle for rotation
if (fabs(m_dAngle) < 0.01)
{
m_dAngle = GetAngle(mapToParent(pME->pos()));
return;
}
// calculate the angle difference from the starting angle
double dAng = qRadiansToDegrees(GetAngle(mapToParent(pME->pos())) - m_dAngle);
rectBB.setTopLeft(m_ptStartPos);
rectBB.setWidth(m_rectBoundingBox.width());
rectBB.setHeight(m_rectBoundingBox.height());
// check if the rotated label will be inside the parent item and then rotate it
if (IsContained(rectBB, m_dRotation + dAng, dX, dY) == true)
{
setRotation(m_dRotation + dAng);
Update();
}
} }
} }
@ -554,25 +439,30 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
* @brief VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events * @brief VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events
* @param pME pointer to QGraphicsSceneMouseEvent object * @param pME pointer to QGraphicsSceneMouseEvent object
*/ */
void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *pME)
{ {
if (pME->button() == Qt::LeftButton) if (pME->button() != Qt::LeftButton)
{ {
return;
}
// restore the cursor // restore the cursor
if ((m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize) && (flags() & QGraphicsItem::ItemIsMovable)) if ((m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize) && (flags() & QGraphicsItem::ItemIsMovable))
{ {
SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1);
} }
double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y());
// determine if this was just press/release (bShort == true) or user did some operation between press and release // determine if this was just press/release (bShort == true) or user did some operation between press and
// release
bool bShort = (dDist < 2); bool bShort = (dDist < 2);
if (m_eMode == mMove || m_eMode == mResize) if (m_eMode == mMove || m_eMode == mResize)
{ // if user just pressed and released the button, we must switch the mode to rotate { // if user just pressed and released the button, we must switch the mode to rotate
// but if user did some operation (move/resize), emit the proper signal and update the label // but if user did some operation (move/resize), emit the proper signal and update the label
if (bShort == true) if (bShort)
{ {
if (m_bReleased == true && m_moveType & IsRotatable) if (m_bReleased && m_moveType & IsRotatable)
{ {
m_eMode = mRotate; m_eMode = mRotate;
UpdateBox(); UpdateBox();
@ -585,13 +475,13 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
} }
else if (m_moveType & IsResizable) else if (m_moveType & IsResizable)
{ {
emit SignalResized(m_rectBoundingBox.width(), m_tm.GetFont().pixelSize()); emit SignalResized(m_rectBoundingBox.width());
Update(); Update();
} }
} }
else else
{ // in rotate mode, if user did just press/release, switch to move mode { // in rotate mode, if user did just press/release, switch to move mode
if (bShort == true && (m_moveType & IsMovable || m_moveType & IsResizable)) if (bShort && (m_moveType & IsMovable || m_moveType & IsResizable))
{ {
m_eMode = mMove; m_eMode = mMove;
} }
@ -603,7 +493,6 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
UpdateBox(); UpdateBox();
} }
m_bReleased = true; m_bReleased = true;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -611,11 +500,11 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME)
* @brief VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed * @brief VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed
* @param pHE pointer to the scene hover event * @param pHE pointer to the scene hover event
*/ */
void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent *pHE)
{ {
if (m_eMode == mResize && m_moveType & IsResizable) if (m_eMode == mResize && m_moveType & IsResizable)
{ {
if (m_rectResize.contains(pHE->pos()) == true) if (m_rectResize.contains(pHE->pos()))
{ {
setCursor(Qt::SizeFDiagCursor); setCursor(Qt::SizeFDiagCursor);
} }
@ -658,12 +547,11 @@ void VTextGraphicsItem::CorrectLabel()
QRectF rectBB; QRectF rectBB;
rectBB.setTopLeft(pos()); rectBB.setTopLeft(pos());
rectBB.setSize(m_rectBoundingBox.size()); rectBB.setSize(m_rectBoundingBox.size());
if (IsContained(rectBB, rotation(), dX, dY) == false) if (not IsContained(rectBB, rotation(), dX, dY))
{ {
// put the label inside the pattern // put the label inside the pattern
setPos(pos().x() + dX, pos().y() + dY); setPos(pos().x() + dX, pos().y() + dY);
} }
m_tm.FitFontSize(m_rectBoundingBox.width(), m_rectBoundingBox.height());
UpdateBox(); UpdateBox();
} }
@ -693,7 +581,7 @@ void VTextGraphicsItem::UserRotateAndMove()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::UserMoveAndResize(const QPointF &pos) void VTextGraphicsItem::UserMoveAndResize(const QPointF &pos)
{ {
if (m_rectResize.contains(pos) == true) if (m_rectResize.contains(pos))
{ {
m_eMode = mResize; m_eMode = mResize;
setCursor(Qt::SizeFDiagCursor); setCursor(Qt::SizeFDiagCursor);
@ -704,3 +592,169 @@ void VTextGraphicsItem::UserMoveAndResize(const QPointF &pos)
SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1); SetItemOverrideCursor(this, cursorArrowCloseHand, 1, 1);
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::MoveLabel(QGraphicsSceneMouseEvent *pME)
{
const QPointF ptDiff = pME->scenePos() - m_ptStart;
// in move mode move the label along the mouse move from the origin
QPointF pt = m_ptStartPos + ptDiff;
QRectF rectBB;
rectBB.setTopLeft(pt);
rectBB.setWidth(m_rectBoundingBox.width());
rectBB.setHeight(m_rectBoundingBox.height());
// before moving label to a new position, check if it will still be inside the parent item
qreal dX;
qreal dY;
if (not IsContained(rectBB, rotation(), dX, dY))
{
pt.setX(pt.x() + dX);
pt.setY(pt.y() + dY);
}
setPos(pt);
UpdateBox();
}
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::ResizeLabel(QGraphicsSceneMouseEvent *pME)
{
QLineF vectorDiff(m_ptStart, pME->scenePos());
vectorDiff.setAngle(vectorDiff.angle() + m_dRotation);
const QPointF ptDiff = vectorDiff.p2() - m_ptStart;
// in resize mode, resize the label along the mouse move from the origin
QPointF pt;
QSizeF sz;
if (m_moveType & IsMovable)
{
const qreal newWidth = m_szStart.width() + ptDiff.x();
const qreal newHeight = m_szStart.height() + ptDiff.y();
if (newWidth <= minW || newHeight <= minH)
{
return;
}
pt = m_ptStartPos;
sz = QSizeF(newWidth, newHeight);
}
else
{
const qreal newWidth = m_szStart.width() + ptDiff.x() * 2.0;
const qreal newHeight = m_szStart.height() + ptDiff.y() * 2.0;
if (newWidth <= minW || newHeight <= minH)
{
return;
}
pt = QPointF(m_ptRotCenter.x() - newWidth / 2.0, m_ptRotCenter.y() - newHeight / 2.0);
sz = QSizeF(m_szStart.width() + ptDiff.x() * 2.0, m_szStart.height() + ptDiff.y() * 2.0);
}
QRectF rectBB;
rectBB.setTopLeft(pt);
rectBB.setSize(sz);
// before resizing the label to a new size, check if it will still be inside the parent item
qreal dX;
qreal dY;
if (IsContained(rectBB, rotation(), dX, dY))
{
if (not(m_moveType & IsMovable))
{
setPos(pt);
}
}
else
{
return;
}
SetSize(sz.width(), sz.height());
Update();
emit SignalShrink();
}
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::RotateLabel(QGraphicsSceneMouseEvent *pME)
{
// if the angle from the original position is small (0.5 degrees), just remeber the new angle
// new angle will be the starting angle for rotation
if (fabs(m_dAngle) < 0.01)
{
m_dAngle = GetAngle(mapToParent(pME->pos()));
return;
}
QRectF rectBB;
rectBB.setTopLeft(m_ptStartPos);
rectBB.setWidth(m_rectBoundingBox.width());
rectBB.setHeight(m_rectBoundingBox.height());
// calculate the angle difference from the starting angle
double dAng = qRadiansToDegrees(GetAngle(mapToParent(pME->pos())) - m_dAngle);
// check if the rotated label will be inside the parent item and then rotate it
qreal dX;
qreal dY;
if (IsContained(rectBB, m_dRotation + dAng, dX, dY))
{
setRotation(m_dRotation + dAng);
Update();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::PaintLabel(QPainter *painter)
{
const QRectF boundingRect = this->boundingRect();
const int iW = qFloor(boundingRect.width());
QFont fnt = m_tm.GetFont();
const QVector<TextLine> labelLines = m_tm.GetLabelSourceLines(iW, fnt);
// draw text lines
int iY = 0;
for (const auto &tl : labelLines)
{
fnt.setPointSize(m_tm.GetFont().pointSize() + tl.m_iFontSize);
fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic);
QString qsText = tl.m_qsText;
QFontMetrics fm(fnt);
int lineHeight = fm.height();
if (iY + fm.height() > boundingRect.height())
{
lineHeight = qFloor(boundingRect.height()) - iY;
}
painter->setFont(fnt);
painter->drawText(0, iY, iW, lineHeight, static_cast<int>(tl.m_eAlign), qsText);
// check if the next line will go out of bounds
if (iY + fm.height() > boundingRect.height())
{
QString errorMsg;
switch (m_itemType)
{
case PatternLabel:
errorMsg = tr("Piece '%1'. Not enough space for pattern info label.").arg(m_pieceName);
break;
case PieceLabel:
errorMsg = tr("Piece '%1'. Not enough space for piece info label.").arg(m_pieceName);
break;
case Unknown:
default:
errorMsg = tr("Piece '%1'. Not enough space for label.").arg(m_pieceName);
break;
};
VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg)
: qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
break;
}
iY += fm.height() + m_tm.GetSpacing();
}
}

View file

@ -40,8 +40,8 @@
#include <QString> #include <QString>
#include <QtGlobal> #include <QtGlobal>
#include "vpieceitem.h"
#include "../vlayout/vtextmanager.h" #include "../vlayout/vtextmanager.h"
#include "vpieceitem.h"
/** /**
* @brief The VTextGraphicsItem class. This class implements text graphics item, * @brief The VTextGraphicsItem class. This class implements text graphics item,
@ -51,52 +51,72 @@
class VTextGraphicsItem final : public VPieceItem class VTextGraphicsItem final : public VPieceItem
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
explicit VTextGraphicsItem(QGraphicsItem* pParent = nullptr); enum ItemType
virtual ~VTextGraphicsItem() = default; {
PatternLabel,
PieceLabel,
Unknown
};
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; explicit VTextGraphicsItem(ItemType type, QGraphicsItem *pParent = nullptr);
virtual void Update() override; ~VTextGraphicsItem() override = default;
virtual auto type() const -> int override { return Type; } void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
enum { Type = UserType + static_cast<int>(Vis::TextGraphicsItem)}; void Update() override;
void SetFont(const QFont& fnt); auto type() const -> int override { return Type; }
enum
{
Type = UserType + static_cast<int>(Vis::TextGraphicsItem)
};
void SetFont(const QFont &fnt);
auto GetFontSize() const -> int; auto GetFontSize() const -> int;
void SetSize(qreal fW, qreal fH); void SetSize(qreal fW, qreal fH);
auto IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal &dY) const -> bool; auto IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal &dY) const -> bool;
void UpdateData(const QString& qsName, const VPieceLabelData& data, const VContainer *pattern); void UpdateData(const QString &qsName, const VPieceLabelData &data, const VContainer *pattern);
void UpdateData(VAbstractPattern* pDoc, const VContainer *pattern); void UpdateData(VAbstractPattern *pDoc, const VContainer *pattern);
auto GetTextLines() const -> vsizetype; auto GetTextLines() const -> vsizetype;
void SetPieceName(const QString &name);
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) override; void mousePressEvent(QGraphicsSceneMouseEvent *pME) override;
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *pME) override;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *pME) override;
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *pME) override; void hoverEnterEvent(QGraphicsSceneHoverEvent *pME) override;
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) override; void hoverMoveEvent(QGraphicsSceneHoverEvent *pHE) override;
void UpdateBox(); void UpdateBox();
void CorrectLabel(); void CorrectLabel();
signals: signals:
void SignalResized(qreal iTW, int iFontSize); void SignalResized(qreal iTW);
void SignalRotated(qreal dAng); void SignalRotated(qreal dAng);
void SignalShrink(); void SignalShrink();
private: private:
Q_DISABLE_COPY_MOVE(VTextGraphicsItem) // NOLINT Q_DISABLE_COPY_MOVE(VTextGraphicsItem) // NOLINT
QPointF m_ptStartPos; QPointF m_ptStartPos{};
QPointF m_ptStart; QPointF m_ptStart{};
QSizeF m_szStart; QSizeF m_szStart{};
double m_dRotation; double m_dRotation{0};
double m_dAngle; double m_dAngle{0};
QRectF m_rectResize; QRectF m_rectResize{};
VTextManager m_tm; VTextManager m_tm{};
QString m_pieceName{};
ItemType m_itemType{Unknown};
void AllUserModifications(const QPointF &pos); void AllUserModifications(const QPointF &pos);
void UserRotateAndMove(); void UserRotateAndMove();
void UserMoveAndResize(const QPointF &pos); void UserMoveAndResize(const QPointF &pos);
void MoveLabel(QGraphicsSceneMouseEvent *pME);
void ResizeLabel(QGraphicsSceneMouseEvent *pME);
void RotateLabel(QGraphicsSceneMouseEvent *pME);
void PaintLabel(QPainter *painter);
}; };
#endif // VTEXTGRAPHICSITEM_H #endif // VTEXTGRAPHICSITEM_H