Parse template and prepare pattern label.
--HG-- branch : feature
This commit is contained in:
parent
b80bd85dec
commit
b212d04d11
|
@ -195,6 +195,7 @@ const QString VAbstractPattern::NodeSplinePath = QStringLiteral("NodeSplinePath"
|
||||||
|
|
||||||
QHash<quint32, VDataTool*> VAbstractPattern::tools = QHash<quint32, VDataTool*>();
|
QHash<quint32, VDataTool*> VAbstractPattern::tools = QHash<quint32, VDataTool*>();
|
||||||
QVector<VLabelTemplateLine> VAbstractPattern::patternLabelLines = QVector<VLabelTemplateLine>();
|
QVector<VLabelTemplateLine> VAbstractPattern::patternLabelLines = QVector<VLabelTemplateLine>();
|
||||||
|
bool VAbstractPattern::patternLabelWasChanged = false;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -1383,6 +1384,7 @@ void VAbstractPattern::SetPatternLabelTemplate(const QVector<VLabelTemplateLine>
|
||||||
RemoveAllChildren(tag);
|
RemoveAllChildren(tag);
|
||||||
SetLabelTemplate(tag, lines);
|
SetLabelTemplate(tag, lines);
|
||||||
patternLabelLines = lines;
|
patternLabelLines = lines;
|
||||||
|
patternLabelWasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1402,6 +1404,18 @@ QVector<VLabelTemplateLine> VAbstractPattern::GetPatternLabelTemplate() const
|
||||||
return patternLabelLines;
|
return patternLabelLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VAbstractPattern::SetPatternWasChanged(bool changed)
|
||||||
|
{
|
||||||
|
patternLabelWasChanged = changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool VAbstractPattern::GetPatternWasChanged() const
|
||||||
|
{
|
||||||
|
return patternLabelWasChanged;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VAbstractPattern::GetImage() const
|
QString VAbstractPattern::GetImage() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -157,6 +157,9 @@ public:
|
||||||
void SetPatternLabelTemplate(const QVector<VLabelTemplateLine> &lines);
|
void SetPatternLabelTemplate(const QVector<VLabelTemplateLine> &lines);
|
||||||
QVector<VLabelTemplateLine> GetPatternLabelTemplate() const;
|
QVector<VLabelTemplateLine> GetPatternLabelTemplate() const;
|
||||||
|
|
||||||
|
void SetPatternWasChanged(bool changed);
|
||||||
|
bool GetPatternWasChanged() const;
|
||||||
|
|
||||||
QString GetImage() const;
|
QString GetImage() const;
|
||||||
QString GetImageExtension() const;
|
QString GetImageExtension() const;
|
||||||
void SetImage(const QString &text, const QString &extension);
|
void SetImage(const QString &text, const QString &extension);
|
||||||
|
@ -389,6 +392,7 @@ protected:
|
||||||
static QHash<quint32, VDataTool*> tools;
|
static QHash<quint32, VDataTool*> tools;
|
||||||
/** @brief patternLabelLines list to speed up reading a template by many pieces. */
|
/** @brief patternLabelLines list to speed up reading a template by many pieces. */
|
||||||
static QVector<VLabelTemplateLine> patternLabelLines;
|
static QVector<VLabelTemplateLine> patternLabelLines;
|
||||||
|
static bool patternLabelWasChanged;
|
||||||
|
|
||||||
static void ToolExists(const quint32 &id);
|
static void ToolExists(const quint32 &id);
|
||||||
static VPiecePath ParsePathNodes(const QDomElement &domElement);
|
static VPiecePath ParsePathNodes(const QDomElement &domElement);
|
||||||
|
|
|
@ -400,8 +400,7 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern
|
||||||
if (geom.IsVisible() == true)
|
if (geom.IsVisible() == true)
|
||||||
{
|
{
|
||||||
VAbstractPattern* pDoc = qApp->getCurrentDocument();
|
VAbstractPattern* pDoc = qApp->getCurrentDocument();
|
||||||
det.SetPatternInfo(pDoc, geom, qApp->Settings()->GetLabelFont(), VContainer::size(), VContainer::height(),
|
det.SetPatternInfo(pDoc, geom, qApp->Settings()->GetLabelFont(), pattern);
|
||||||
pattern);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry();
|
const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry();
|
||||||
|
@ -545,7 +544,7 @@ QStringList VLayoutPiece::GetPatternText() const
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font,
|
void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font,
|
||||||
qreal dSize, qreal dHeight, const VContainer *pattern)
|
const VContainer *pattern)
|
||||||
{
|
{
|
||||||
QPointF ptPos;
|
QPointF ptPos;
|
||||||
qreal labelWidth = 0;
|
qreal labelWidth = 0;
|
||||||
|
@ -578,7 +577,7 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLa
|
||||||
d->m_tmPattern.SetFont(font);
|
d->m_tmPattern.SetFont(font);
|
||||||
d->m_tmPattern.SetFontSize(geom.GetFontSize());
|
d->m_tmPattern.SetFontSize(geom.GetFontSize());
|
||||||
|
|
||||||
d->m_tmPattern.Update(pDoc, dSize, dHeight);
|
d->m_tmPattern.Update(pDoc);
|
||||||
|
|
||||||
// generate lines of text
|
// generate lines of text
|
||||||
d->m_tmPattern.SetFontSize(geom.GetFontSize());
|
d->m_tmPattern.SetFontSize(geom.GetFontSize());
|
||||||
|
@ -1026,8 +1025,8 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPoin
|
||||||
const TextLine& tl = tm.GetSourceLine(i);
|
const TextLine& tl = tm.GetSourceLine(i);
|
||||||
QFont fnt = tm.GetFont();
|
QFont fnt = tm.GetFont();
|
||||||
fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize);
|
fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize);
|
||||||
fnt.setWeight(tl.m_eFontWeight);
|
fnt.setBold(tl.bold);
|
||||||
fnt.setStyle(tl.m_eStyle);
|
fnt.setItalic(tl.italic);
|
||||||
|
|
||||||
QFontMetrics fm(fnt);
|
QFontMetrics fm(fnt);
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
QPointF GetPatternTextPosition() const;
|
QPointF GetPatternTextPosition() const;
|
||||||
QStringList GetPatternText() const;
|
QStringList GetPatternText() const;
|
||||||
void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont& font,
|
void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont& font,
|
||||||
qreal dSize, qreal dHeight, const VContainer *pattern);
|
const VContainer *pattern);
|
||||||
|
|
||||||
void SetGrainline(const VGrainlineData& geom, const VContainer *pattern);
|
void SetGrainline(const VGrainlineData& geom, const VContainer *pattern);
|
||||||
QVector<QPointF> GetGrainline() const;
|
QVector<QPointF> GetGrainline() const;
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
|
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
|
||||||
#include "../vmisc/vabstractapplication.h"
|
#include "../vmisc/vabstractapplication.h"
|
||||||
#include "../vmisc/vmath.h"
|
#include "../vmisc/vmath.h"
|
||||||
|
#include "../vpatterndb/vcontainer.h"
|
||||||
#include "vtextmanager.h"
|
#include "vtextmanager.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -47,11 +48,92 @@
|
||||||
TextLine::TextLine()
|
TextLine::TextLine()
|
||||||
: m_qsText(),
|
: m_qsText(),
|
||||||
m_iFontSize(MIN_FONT_SIZE),
|
m_iFontSize(MIN_FONT_SIZE),
|
||||||
m_eFontWeight(QFont::Normal),
|
bold(false),
|
||||||
m_eStyle(QFont::StyleNormal),
|
italic(false),
|
||||||
m_eAlign(Qt::AlignCenter)
|
m_eAlign(Qt::AlignCenter)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
QList<TextLine> VTextManager::m_patternLabelLines = QList<TextLine>();
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QMap<QString, QString> PreparePlaceholders(const VAbstractPattern *doc)
|
||||||
|
{
|
||||||
|
SCASSERT(doc != nullptr)
|
||||||
|
|
||||||
|
QMap<QString, QString> placeholders;
|
||||||
|
|
||||||
|
QLocale locale(qApp->Settings()->GetLocale());
|
||||||
|
placeholders.insert(pl_date, locale.toString(QDate::currentDate()));
|
||||||
|
placeholders.insert(pl_time, locale.toString(QTime::currentTime()));
|
||||||
|
placeholders.insert(pl_patternName, doc->GetPatternName());
|
||||||
|
placeholders.insert(pl_patternNumber, doc->GetPatternNumber());
|
||||||
|
placeholders.insert(pl_author, doc->GetCompanyName());
|
||||||
|
placeholders.insert(pl_customer, doc->GetCustomerName());
|
||||||
|
placeholders.insert(pl_pExt, QString("val"));
|
||||||
|
placeholders.insert(pl_pFileName, QFileInfo(qApp->GetPPath()).fileName());
|
||||||
|
placeholders.insert(pl_mFileName, QFileInfo(doc->MPath()).fileName());
|
||||||
|
|
||||||
|
QString curSize;
|
||||||
|
QString curHeight;
|
||||||
|
QString mExt;
|
||||||
|
if (qApp->patternType() == MeasurementsType::Multisize)
|
||||||
|
{
|
||||||
|
curSize = QString::number(VContainer::size());
|
||||||
|
curHeight = QString::number(VContainer::height());
|
||||||
|
mExt = "vst";
|
||||||
|
}
|
||||||
|
else if (qApp->patternType() == MeasurementsType::Individual)
|
||||||
|
{
|
||||||
|
mExt = "vit";
|
||||||
|
}
|
||||||
|
|
||||||
|
placeholders.insert(pl_size, curSize);
|
||||||
|
placeholders.insert(pl_height, curHeight);
|
||||||
|
placeholders.insert(pl_mExt, mExt);
|
||||||
|
|
||||||
|
return placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QString ReplacePlaceholders(const QMap<QString, QString> &placeholders, QString line)
|
||||||
|
{
|
||||||
|
QChar per('%');
|
||||||
|
auto i = placeholders.constBegin();
|
||||||
|
while (i != placeholders.constEnd())
|
||||||
|
{
|
||||||
|
line.replace(per+i.key()+per, i.value());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QList<TextLine> PrepareLines(const QVector<VLabelTemplateLine> &lines)
|
||||||
|
{
|
||||||
|
QList<TextLine> textLines;
|
||||||
|
|
||||||
|
for (int i=0; i < lines.size(); ++i)
|
||||||
|
{
|
||||||
|
if (not lines.at(i).line.isEmpty())
|
||||||
|
{
|
||||||
|
TextLine tl;
|
||||||
|
tl.m_qsText = lines.at(i).line;
|
||||||
|
tl.m_eAlign = static_cast<Qt::Alignment>(lines.at(i).alignment);
|
||||||
|
tl.m_iFontSize = 0;
|
||||||
|
tl.bold = lines.at(i).bold;
|
||||||
|
tl.italic = lines.at(i).italic;
|
||||||
|
|
||||||
|
textLines << tl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return textLines;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VTextManager::VTextManager constructor
|
* @brief VTextManager::VTextManager constructor
|
||||||
|
@ -60,13 +142,6 @@ VTextManager::VTextManager()
|
||||||
: m_font(), m_liLines()
|
: m_font(), m_liLines()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextManager::~VTextManager destructor
|
|
||||||
*/
|
|
||||||
VTextManager::~VTextManager()
|
|
||||||
{}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VTextManager::VTextManager(const VTextManager &text)
|
VTextManager::VTextManager(const VTextManager &text)
|
||||||
: m_font(text.GetFont()), m_liLines(text.GetAllSourceLines())
|
: m_font(text.GetFont()), m_liLines(text.GetAllSourceLines())
|
||||||
|
@ -130,25 +205,6 @@ QList<TextLine> VTextManager::GetAllSourceLines() const
|
||||||
return m_liLines;
|
return m_liLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief AddSourceLine add new text line to the list
|
|
||||||
* @param tl text line object to be added
|
|
||||||
*/
|
|
||||||
void VTextManager::AddSourceLine(const TextLine& tl)
|
|
||||||
{
|
|
||||||
m_liLines << tl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief ClearSourceLines deletes the list of texts
|
|
||||||
*/
|
|
||||||
void VTextManager::ClearSourceLines()
|
|
||||||
{
|
|
||||||
m_liLines.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VTextManager::GetSourceLinesCount returns the number of input text lines
|
* @brief VTextManager::GetSourceLinesCount returns the number of input text lines
|
||||||
|
@ -202,8 +258,8 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
|
||||||
const TextLine& tl = GetSourceLine(i);
|
const TextLine& tl = GetSourceLine(i);
|
||||||
fnt = m_font;
|
fnt = m_font;
|
||||||
fnt.setPixelSize(iFS + tl.m_iFontSize);
|
fnt.setPixelSize(iFS + tl.m_iFontSize);
|
||||||
fnt.setWeight(tl.m_eFontWeight);
|
fnt.setBold(tl.bold);
|
||||||
fnt.setStyle(tl.m_eStyle);
|
fnt.setItalic(tl.italic);
|
||||||
QFontMetrics fm(fnt);
|
QFontMetrics fm(fnt);
|
||||||
const int iTW = fm.width(tl.m_qsText);
|
const int iTW = fm.width(tl.m_qsText);
|
||||||
if (iTW > iMaxLen)
|
if (iTW > iMaxLen)
|
||||||
|
@ -215,8 +271,8 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
|
||||||
if (iMaxLen > fW)
|
if (iMaxLen > fW)
|
||||||
{
|
{
|
||||||
QFont fnt = m_font;
|
QFont fnt = m_font;
|
||||||
fnt.setWeight(maxLine.m_eFontWeight);
|
fnt.setBold(maxLine.bold);
|
||||||
fnt.setStyle(maxLine.m_eStyle);
|
fnt.setItalic(maxLine.italic);
|
||||||
|
|
||||||
int lineLength = 0;
|
int lineLength = 0;
|
||||||
do
|
do
|
||||||
|
@ -240,27 +296,27 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
|
||||||
*/
|
*/
|
||||||
void VTextManager::Update(const QString& qsName, const VPieceLabelData& data)
|
void VTextManager::Update(const QString& qsName, const VPieceLabelData& data)
|
||||||
{
|
{
|
||||||
ClearSourceLines();
|
m_liLines.clear();
|
||||||
|
|
||||||
TextLine tl;
|
TextLine tl;
|
||||||
// all text must be centered and normal style!
|
// all text must be centered and normal style!
|
||||||
tl.m_eAlign = Qt::AlignCenter;
|
tl.m_eAlign = Qt::AlignCenter;
|
||||||
tl.m_eStyle = QFont::StyleNormal;
|
|
||||||
|
|
||||||
// letter
|
// letter
|
||||||
tl.m_qsText = data.GetLetter();
|
tl.m_qsText = data.GetLetter();
|
||||||
if (tl.m_qsText.isEmpty() == false)
|
if (tl.m_qsText.isEmpty() == false)
|
||||||
{
|
{
|
||||||
tl.m_eFontWeight = QFont::Bold;
|
tl.bold = true;
|
||||||
tl.m_iFontSize = 6;
|
tl.m_iFontSize = 6;
|
||||||
AddSourceLine(tl);
|
m_liLines << tl;
|
||||||
}
|
}
|
||||||
// name
|
// name
|
||||||
tl.m_qsText = qsName;
|
tl.m_qsText = qsName;
|
||||||
if (tl.m_qsText.isEmpty() == false)
|
if (tl.m_qsText.isEmpty() == false)
|
||||||
{
|
{
|
||||||
tl.m_eFontWeight = QFont::DemiBold;
|
tl.bold = true;
|
||||||
tl.m_iFontSize = 2;
|
tl.m_iFontSize = 2;
|
||||||
AddSourceLine(tl);
|
m_liLines << tl;
|
||||||
}
|
}
|
||||||
// MCP
|
// MCP
|
||||||
QStringList qslMaterials;
|
QStringList qslMaterials;
|
||||||
|
@ -271,7 +327,7 @@ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data)
|
||||||
QString qsText = QLatin1String("%1, ") + tr("cut") + QLatin1String(" %2%3");
|
QString qsText = QLatin1String("%1, ") + tr("cut") + QLatin1String(" %2%3");
|
||||||
QStringList qslPlace;
|
QStringList qslPlace;
|
||||||
qslPlace << "" << QLatin1String(" ") + tr("on fold");
|
qslPlace << "" << QLatin1String(" ") + tr("on fold");
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
tl.bold = false;
|
||||||
tl.m_iFontSize = 0;
|
tl.m_iFontSize = 0;
|
||||||
for (int i = 0; i < data.GetMCPCount(); ++i)
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -289,7 +345,7 @@ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data)
|
||||||
}
|
}
|
||||||
tl.m_qsText = qsText.arg(qsMat).arg(mcp.m_iCutNumber).
|
tl.m_qsText = qsText.arg(qsMat).arg(mcp.m_iCutNumber).
|
||||||
arg(qslPlace[int(mcp.m_ePlacement)]);
|
arg(qslPlace[int(mcp.m_ePlacement)]);
|
||||||
AddSourceLine(tl);
|
m_liLines << tl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,89 +355,27 @@ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data)
|
||||||
* @brief VTextManager::Update updates the text lines with pattern info
|
* @brief VTextManager::Update updates the text lines with pattern info
|
||||||
* @param pDoc pointer to the abstract pattern object
|
* @param pDoc pointer to the abstract pattern object
|
||||||
*/
|
*/
|
||||||
void VTextManager::Update(const VAbstractPattern *pDoc, qreal dSize, qreal dHeight)
|
void VTextManager::Update(const VAbstractPattern *pDoc)
|
||||||
{
|
{
|
||||||
ClearSourceLines();
|
m_liLines.clear();
|
||||||
TextLine tl;
|
|
||||||
// all information must be centered
|
|
||||||
tl.m_eAlign = Qt::AlignCenter;
|
|
||||||
|
|
||||||
// Company name
|
if (m_patternLabelLines.isEmpty() || pDoc->GetPatternWasChanged())
|
||||||
tl.m_qsText = pDoc->GetCompanyName();
|
|
||||||
if (tl.m_qsText.isEmpty() == false)
|
|
||||||
{
|
{
|
||||||
tl.m_eFontWeight = QFont::DemiBold;
|
QVector<VLabelTemplateLine> lines = pDoc->GetPatternLabelTemplate();
|
||||||
tl.m_eStyle = QFont::StyleNormal;
|
if (lines.isEmpty() && m_patternLabelLines.isEmpty())
|
||||||
tl.m_iFontSize = 4;
|
|
||||||
AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
// Pattern name
|
|
||||||
tl.m_qsText = pDoc->GetPatternName();
|
|
||||||
if (tl.m_qsText.isEmpty() == false)
|
|
||||||
{
|
{
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
return; // Nothing to parse
|
||||||
tl.m_eStyle = QFont::StyleNormal;
|
|
||||||
tl.m_iFontSize = 2;
|
|
||||||
AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
// Pattern number
|
|
||||||
tl.m_qsText = pDoc->GetPatternNumber();
|
|
||||||
if (tl.m_qsText.isEmpty() == false)
|
|
||||||
{
|
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
|
||||||
tl.m_eStyle = QFont::StyleNormal;
|
|
||||||
tl.m_iFontSize = 0;
|
|
||||||
AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
// Customer name
|
|
||||||
tl.m_qsText = pDoc->GetCustomerName();
|
|
||||||
if (tl.m_qsText.isEmpty() == false)
|
|
||||||
{
|
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
|
||||||
tl.m_eStyle = QFont::StyleItalic;
|
|
||||||
tl.m_iFontSize = 0;
|
|
||||||
AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
// Size
|
|
||||||
tl.m_qsText = pDoc->GetPatternSize();
|
|
||||||
if (tl.m_qsText.isEmpty() == false)
|
|
||||||
{
|
|
||||||
// Such describing placeholders will help avoid mistake of localization.
|
|
||||||
// Translators very often remove '%'.
|
|
||||||
QString placeholder = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_size) + QLatin1String("%");
|
|
||||||
tl.m_qsText.replace(placeholder, QString::number(dSize));
|
|
||||||
|
|
||||||
placeholder = QLatin1String("%") + qApp->TrVars()->PlaceholderToUser(pl_height) + QLatin1String("%");
|
|
||||||
tl.m_qsText.replace(placeholder, QString::number(dHeight));
|
|
||||||
|
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
|
||||||
tl.m_eStyle = QFont::StyleNormal;
|
|
||||||
tl.m_iFontSize = 0;
|
|
||||||
AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
// Measurements
|
|
||||||
tl.m_qsText = QFileInfo(pDoc->MPath()).fileName();
|
|
||||||
if (tl.m_qsText.isEmpty() == false && pDoc->IsMeasurementsVisible() == true)
|
|
||||||
{
|
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
|
||||||
tl.m_eStyle = QFont::StyleNormal;
|
|
||||||
tl.m_iFontSize = 0;
|
|
||||||
AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
// Date
|
|
||||||
QDate date;
|
|
||||||
if (pDoc->IsDateVisible() == true)
|
|
||||||
{
|
|
||||||
date = QDate::currentDate();
|
|
||||||
}
|
|
||||||
if (date.isValid() == true)
|
|
||||||
{
|
|
||||||
QLocale locale(qApp->Settings()->GetLocale());
|
|
||||||
tl.m_qsText = locale.toString(date, "dd MMMM yyyy");
|
|
||||||
tl.m_eFontWeight = QFont::Normal;
|
|
||||||
tl.m_eStyle = QFont::StyleNormal;
|
|
||||||
tl.m_iFontSize = 0;
|
|
||||||
AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QMap<QString, QString> placeholders = PreparePlaceholders(pDoc);
|
||||||
|
|
||||||
|
for (int i=0; i<lines.size(); ++i)
|
||||||
|
{
|
||||||
|
lines[i].line = ReplacePlaceholders(placeholders, lines.at(i).line);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_patternLabelLines = PrepareLines(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_liLines = m_patternLabelLines;
|
||||||
|
}
|
||||||
|
|
|
@ -51,8 +51,8 @@ struct TextLine
|
||||||
{
|
{
|
||||||
QString m_qsText;
|
QString m_qsText;
|
||||||
int m_iFontSize; // 0 means default
|
int m_iFontSize; // 0 means default
|
||||||
QFont::Weight m_eFontWeight;
|
bool bold;
|
||||||
QFont::Style m_eStyle;
|
bool italic;
|
||||||
Qt::Alignment m_eAlign;
|
Qt::Alignment m_eAlign;
|
||||||
|
|
||||||
TextLine();
|
TextLine();
|
||||||
|
@ -67,7 +67,7 @@ class VTextManager
|
||||||
Q_DECLARE_TR_FUNCTIONS(VTextManager)
|
Q_DECLARE_TR_FUNCTIONS(VTextManager)
|
||||||
public:
|
public:
|
||||||
VTextManager();
|
VTextManager();
|
||||||
virtual ~VTextManager();
|
virtual ~VTextManager() = default;
|
||||||
|
|
||||||
VTextManager(const VTextManager &text);
|
VTextManager(const VTextManager &text);
|
||||||
VTextManager &operator=(const VTextManager &text);
|
VTextManager &operator=(const VTextManager &text);
|
||||||
|
@ -80,17 +80,17 @@ public:
|
||||||
void FitFontSize(qreal fW, qreal fH);
|
void FitFontSize(qreal fW, qreal fH);
|
||||||
|
|
||||||
QList<TextLine> GetAllSourceLines() const;
|
QList<TextLine> GetAllSourceLines() const;
|
||||||
void AddSourceLine(const TextLine& tl);
|
|
||||||
void ClearSourceLines();
|
|
||||||
int GetSourceLinesCount() const;
|
int GetSourceLinesCount() const;
|
||||||
const TextLine& GetSourceLine(int i) const;
|
const TextLine& GetSourceLine(int i) const;
|
||||||
|
|
||||||
void Update(const QString& qsName, const VPieceLabelData& data);
|
void Update(const QString& qsName, const VPieceLabelData& data);
|
||||||
void Update(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight);
|
void Update(const VAbstractPattern* pDoc);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFont m_font;
|
QFont m_font;
|
||||||
QList<TextLine> m_liLines;
|
QList<TextLine> m_liLines;
|
||||||
|
|
||||||
|
static QList<TextLine> m_patternLabelLines;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VTEXTMANAGER_H
|
#endif // VTEXTMANAGER_H
|
||||||
|
|
|
@ -578,7 +578,7 @@ void VToolSeamAllowance::UpdatePatternInfo()
|
||||||
|
|
||||||
if (PrepareLabelData(geom, m_patternInfo, pos, labelAngle))
|
if (PrepareLabelData(geom, m_patternInfo, pos, labelAngle))
|
||||||
{
|
{
|
||||||
m_patternInfo->UpdateData(doc, VContainer::size(), VContainer::height());
|
m_patternInfo->UpdateData(doc);
|
||||||
UpdateLabelItem(m_patternInfo, pos, labelAngle);
|
UpdateLabelItem(m_patternInfo, pos, labelAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,8 +164,8 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||||
const TextLine& tl = m_tm.GetSourceLine(i);
|
const TextLine& tl = m_tm.GetSourceLine(i);
|
||||||
|
|
||||||
fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize);
|
fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize);
|
||||||
fnt.setWeight(tl.m_eFontWeight);
|
fnt.setBold(tl.bold);
|
||||||
fnt.setStyle(tl.m_eStyle);
|
fnt.setItalic(tl.italic);
|
||||||
|
|
||||||
QString qsText = tl.m_qsText;
|
QString qsText = tl.m_qsText;
|
||||||
QFontMetrics fm(fnt);
|
QFontMetrics fm(fnt);
|
||||||
|
@ -235,25 +235,6 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextGraphicsItem::AddLine adds a line of text to the label list.
|
|
||||||
* @param tl line of text to add
|
|
||||||
*/
|
|
||||||
void VTextGraphicsItem::AddLine(const TextLine& tl)
|
|
||||||
{
|
|
||||||
m_tm.AddSourceLine(tl);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief VTextGraphicsItem::Clear deletes all the label texts
|
|
||||||
*/
|
|
||||||
void VTextGraphicsItem::Clear()
|
|
||||||
{
|
|
||||||
m_tm.ClearSourceLines();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VTextGraphicsItem::SetSize Tries to set the label size to (fW, fH). If any of those is too small, the label
|
* @brief VTextGraphicsItem::SetSize Tries to set the label size to (fW, fH). If any of those is too small, the label
|
||||||
|
@ -362,9 +343,9 @@ 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(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight)
|
void VTextGraphicsItem::UpdateData(const VAbstractPattern* pDoc)
|
||||||
{
|
{
|
||||||
m_tm.Update(pDoc, dSize, dHeight);
|
m_tm.Update(pDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -63,12 +63,10 @@ public:
|
||||||
|
|
||||||
void SetFont(const QFont& fnt);
|
void SetFont(const QFont& fnt);
|
||||||
int GetFontSize() const;
|
int GetFontSize() const;
|
||||||
void AddLine(const TextLine& tl);
|
|
||||||
void Clear();
|
|
||||||
void SetSize(qreal fW, qreal fH);
|
void SetSize(qreal fW, qreal fH);
|
||||||
bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const;
|
bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const;
|
||||||
void UpdateData(const QString& qsName, const VPieceLabelData& data);
|
void UpdateData(const QString& qsName, const VPieceLabelData& data);
|
||||||
void UpdateData(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight);
|
void UpdateData(const VAbstractPattern* pDoc);
|
||||||
int GetTextLines() const;
|
int GetTextLines() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user