Centered the label texts and did some refactoring, so that the label content is generated in one place

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-07-21 21:46:49 +02:00
parent 5ba40aad8c
commit 312b8e458b
7 changed files with 148 additions and 210 deletions

View File

@ -140,47 +140,8 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da
// generate text // generate text
m_tmDetail.SetFont(font); m_tmDetail.SetFont(font);
m_tmDetail.SetFontSize(data.GetFontSize()); m_tmDetail.SetFontSize(data.GetFontSize());
m_tmDetail.Clear(); m_tmDetail.Update(qsName, data);
TextLine tl; // this will generate the lines of text
// letter
tl.m_qsText = data.GetLetter();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::Bold;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 6;
m_tmDetail.AddLine(tl);
}
// name
if (qsName.isEmpty() == false)
{
tl.m_qsText = qsName;
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::DemiBold;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 2;
m_tmDetail.AddLine(tl);
}
// MCP
QString qsText = "Cut %1 of %2%3";
QStringList qslPlace;
qslPlace << "" << " on Fold";
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
for (int i = 0; i < data.GetMCPCount(); ++i)
{
MaterialCutPlacement mcp = data.GetMCP(i);
if (mcp.m_iCutNumber > 0)
{
tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]);
m_tmDetail.AddLine(tl);
}
}
// will generate the lines of text
m_tmDetail.SetFontSize(data.GetFontSize()); m_tmDetail.SetFontSize(data.GetFontSize());
m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight());
} }
@ -207,69 +168,8 @@ void VLayoutDetail::SetPatternInfo(const QString& qsPattern, const QString& qsNu
// Generate text // Generate text
m_tmPattern.SetFont(font); m_tmPattern.SetFont(font);
m_tmPattern.SetFontSize(geom.GetFontSize()); m_tmPattern.SetFontSize(geom.GetFontSize());
m_tmPattern.Clear();
TextLine tl; m_tmPattern.Update(qsPattern, qsNumber, qsSize, qsCompany, qsCustomer, date);
// Company name
tl.m_qsText = qsCompany;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::DemiBold;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 4;
m_tmPattern.AddLine(tl);
}
// Pattern name
tl.m_qsText = qsPattern;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 2;
m_tmPattern.AddLine(tl);
}
// Pattern number
tl.m_qsText = qsNumber;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
m_tmPattern.AddLine(tl);
}
// Customer name
tl.m_qsText = qsCustomer;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleItalic;
tl.m_iFontSize = 0;
m_tmPattern.AddLine(tl);
}
// Size
tl.m_qsText = qsSize;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
m_tmPattern.AddLine(tl);
}
// Creation date
if (date.isValid() == true)
{
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
QStringList qslDate = date.toString(Qt::SystemLocaleLongDate).split(", ");
tl.m_qsText = qslDate.last();
m_tmPattern.AddLine(tl);
}
// generate lines of text // generate lines of text
m_tmPattern.SetFontSize(geom.GetFontSize()); m_tmPattern.SetFontSize(geom.GetFontSize());
m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight());

View File

@ -111,6 +111,114 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
SetFontSize(iFontSize); SetFontSize(iFontSize);
} }
//---------------------------------------------------------------------------------------------------------------------
void VTextManager::Update(const QString& qsName, const VPatternPieceData& data)
{
Clear();
TextLine tl;
// all text must be centered and normal style!
tl.m_eAlign = Qt::AlignCenter;
tl.m_eStyle = QFont::StyleNormal;
// letter
tl.m_qsText = data.GetLetter();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eFontWeight = QFont::Bold;
tl.m_iFontSize = 6;
AddLine(tl);
}
// name
tl.m_qsText = qsName;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eFontWeight = QFont::DemiBold;
tl.m_iFontSize = 2;
AddLine(tl);
}
// MCP
QString qsText = "Cut %1 on %2%3";
QStringList qslPlace;
qslPlace << "" << " on Fold";
tl.m_eFontWeight = QFont::Normal;
tl.m_iFontSize = 0;
for (int i = 0; i < data.GetMCPCount(); ++i)
{
MaterialCutPlacement mcp = data.GetMCP(i);
if (mcp.m_iCutNumber > 0)
{
tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).
arg(qslPlace[int(mcp.m_ePlacement)]);
AddLine(tl);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, const QString &qsSize,
const QString &qsCompany, const QString &qsCustomer, const QDate& date)
{
Clear();
TextLine tl;
// all information must be centered
tl.m_eAlign = Qt::AlignCenter;
// Company name
tl.m_qsText = qsCompany;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eFontWeight = QFont::DemiBold;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 4;
AddLine(tl);
}
// Pattern name
tl.m_qsText = qsPattern;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 2;
AddLine(tl);
}
// Pattern number
tl.m_qsText = qsNumber;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
AddLine(tl);
}
// Customer name
tl.m_qsText = qsCustomer;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleItalic;
tl.m_iFontSize = 0;
AddLine(tl);
}
// Size
tl.m_qsText = qsSize;
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
AddLine(tl);
}
// Date
if (date.isValid() == true)
{
tl.m_qsText = date.toString("dd MMMM yyyy");
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
AddLine(tl);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm)
{ {

View File

@ -3,6 +3,9 @@
#include <QString> #include <QString>
#include <QFont> #include <QFont>
#include <QDate>
#include "../vpatterndb/vpatternpiecedata.h"
#define MIN_FONT_SIZE 12 #define MIN_FONT_SIZE 12
#define MAX_FONT_SIZE 128 #define MAX_FONT_SIZE 128
@ -36,6 +39,16 @@ public:
const TextLine& GetLine(int i) const; const TextLine& GetLine(int i) const;
bool IsBigEnough(qreal fW, qreal fH, int iFontSize); bool IsBigEnough(qreal fW, qreal fH, int iFontSize);
void FitFontSize(qreal fW, qreal fH); void FitFontSize(qreal fW, qreal fH);
/** @brief Update(const QString& qsName, const VPatternPieceData& data)
* Updates the manager with detail name and detail data
*/
void Update(const QString& qsName, const VPatternPieceData& data);
/** @brief Updateconst QString& qsPattern, const QString& qsNumber, const QString& qsSize,
const QString& qsCompany, const QString& qsCustomer, const QDate& date)
Updates the manager with pattern data
*/
void Update(const QString& qsPattern, const QString& qsNumber, const QString& qsSize,
const QString& qsCompany, const QString& qsCustomer, const QDate& date);
protected: protected:
QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm);

View File

@ -220,6 +220,19 @@ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal
return true; return true;
} }
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::UpdateData(const QString &qsName, const VPatternPieceData &data)
{
m_tm.Update(qsName, data);
}
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::UpdateData(const QString &qsPattern, const QString &qsNumber, const QString &qsSize,
const QString &qsCompany, const QString &qsCustomer, const QDate &date)
{
m_tm.Update(qsPattern, qsNumber, qsSize, qsCompany, qsCustomer, date);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VTextGraphicsItem::GetFontSize() const int VTextGraphicsItem::GetFontSize() const
{ {

View File

@ -62,6 +62,9 @@ public:
void SetSize(qreal fW, qreal fH); void SetSize(qreal fW, qreal fH);
void Update(); void Update();
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 VPatternPieceData& data);
void UpdateData(const QString& qsPattern, const QString& qsNumber, const QString& qsSize,
const QString& qsCompany, const QString& qsCustomer, const QDate& date);
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent* pME); void mousePressEvent(QGraphicsSceneMouseEvent* pME);

View File

@ -685,45 +685,7 @@ void VToolDetail::UpdateLabel()
fnt.setPixelSize(data.GetFontSize()); fnt.setPixelSize(data.GetFontSize());
dataLabel->SetFont(fnt); dataLabel->SetFont(fnt);
dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight()); dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight());
dataLabel->Clear(); dataLabel->UpdateData(detail.getName(), data);
TextLine tl;
// letter
tl.m_qsText = data.GetLetter();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::Bold;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 6;
dataLabel->AddLine(tl);
}
// name
tl.m_qsText = detail.getName();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::DemiBold;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 2;
dataLabel->AddLine(tl);
}
// MCP
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
for (int i = 0; i < data.GetMCPCount(); ++i)
{
MaterialCutPlacement mcp = data.GetMCP(i);
if (mcp.m_iCutNumber > 0)
{
tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]);
dataLabel->AddLine(tl);
}
}
QPointF pt = data.GetPos(); QPointF pt = data.GetPos();
QRectF rectBB; QRectF rectBB;
rectBB.setTopLeft(pt); rectBB.setTopLeft(pt);
@ -768,75 +730,14 @@ void VToolDetail::UpdatePatternInfo()
fnt.setPixelSize(iFS); fnt.setPixelSize(iFS);
patternInfo->SetFont(fnt); patternInfo->SetFont(fnt);
patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight());
patternInfo->Clear();
TextLine tl;
// Company name QDate date;
tl.m_qsText = doc->GetCompanyName();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::DemiBold;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 4;
patternInfo->AddLine(tl);
}
// Pattern name
tl.m_qsText = doc->GetPatternName();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 2;
patternInfo->AddLine(tl);
}
// Pattern number
tl.m_qsText = doc->GetPatternNumber();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
patternInfo->AddLine(tl);
}
// Customer name
tl.m_qsText = doc->GetCustomerName();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleItalic;
tl.m_iFontSize = 0;
patternInfo->AddLine(tl);
}
// Size
tl.m_qsText = doc->GetPatternSize();
if (tl.m_qsText.isEmpty() == false)
{
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
patternInfo->AddLine(tl);
}
// Creation date
if (doc->IsDateVisible() == true) if (doc->IsDateVisible() == true)
{ {
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; date = QDate::currentDate();
tl.m_eFontWeight = QFont::Normal;
tl.m_eStyle = QFont::StyleNormal;
tl.m_iFontSize = 0;
QStringList qslDate = QDate::currentDate().toString(Qt::SystemLocaleLongDate).split(", ");
tl.m_qsText = qslDate.last();
patternInfo->AddLine(tl);
} }
patternInfo->UpdateData(doc->GetPatternName(), doc->GetPatternNumber(), doc->GetPatternSize(),
doc->GetCompanyName(), doc->GetCustomerName(), date);
QPointF pt = geom.GetPos(); QPointF pt = geom.GetPos();
QRectF rectBB; QRectF rectBB;