From 312b8e458b1e0ea2999eb448885af663397332f1 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 21 Jul 2016 21:46:49 +0200 Subject: [PATCH] Centered the label texts and did some refactoring, so that the label content is generated in one place --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 4 +- src/libs/vlayout/vlayoutdetail.cpp | 108 +------------------ src/libs/vlayout/vtextmanager.cpp | 108 +++++++++++++++++++ src/libs/vlayout/vtextmanager.h | 13 +++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 13 +++ src/libs/vtools/tools/vtextgraphicsitem.h | 3 + src/libs/vtools/tools/vtooldetail.cpp | 109 +------------------- 7 files changed, 148 insertions(+), 210 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 258d9ec94..a54d26812 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -486,10 +486,10 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de QDate date; if (pDoc->IsDateVisible() == true) { - date = QDate::currentDate(); + date = QDate::currentDate(); } det.SetPatternInfo(pDoc->GetPatternName(), pDoc->GetPatternNumber(), pDoc->GetPatternSize(), - pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); + pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); qApp->getCurrentDocument(); } det.setWidth(qApp->toPixel(d.getWidth())); diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index c438543c3..2de021f92 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -140,47 +140,8 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da // generate text m_tmDetail.SetFont(font); m_tmDetail.SetFontSize(data.GetFontSize()); - m_tmDetail.Clear(); - 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; - 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.Update(qsName, data); + // this will generate the lines of text m_tmDetail.SetFontSize(data.GetFontSize()); m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); } @@ -207,69 +168,8 @@ void VLayoutDetail::SetPatternInfo(const QString& qsPattern, const QString& qsNu // Generate text m_tmPattern.SetFont(font); m_tmPattern.SetFontSize(geom.GetFontSize()); - m_tmPattern.Clear(); - TextLine tl; - // 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); - } + + m_tmPattern.Update(qsPattern, qsNumber, qsSize, qsCompany, qsCustomer, date); // generate lines of text m_tmPattern.SetFontSize(geom.GetFontSize()); m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 4d2bc9c68..5793c0c92 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -111,6 +111,114 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) 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) { diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 659a07277..167073f73 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -3,6 +3,9 @@ #include #include +#include + +#include "../vpatterndb/vpatternpiecedata.h" #define MIN_FONT_SIZE 12 #define MAX_FONT_SIZE 128 @@ -36,6 +39,16 @@ public: const TextLine& GetLine(int i) const; bool IsBigEnough(qreal fW, qreal fH, int iFontSize); 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: QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index eeee34aee..f739c973e 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -220,6 +220,19 @@ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal 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 { diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 6e5ddb92c..29f9e39a9 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -62,6 +62,9 @@ public: void SetSize(qreal fW, qreal fH); void Update(); 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: void mousePressEvent(QGraphicsSceneMouseEvent* pME); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 73afc8e47..ec757abbd 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -685,45 +685,7 @@ void VToolDetail::UpdateLabel() fnt.setPixelSize(data.GetFontSize()); dataLabel->SetFont(fnt); dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight()); - dataLabel->Clear(); - 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); - } - } - + dataLabel->UpdateData(detail.getName(), data); QPointF pt = data.GetPos(); QRectF rectBB; rectBB.setTopLeft(pt); @@ -768,75 +730,14 @@ void VToolDetail::UpdatePatternInfo() fnt.setPixelSize(iFS); patternInfo->SetFont(fnt); patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); - patternInfo->Clear(); - TextLine tl; - // Company name - 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 + QDate date; if (doc->IsDateVisible() == true) { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - 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); + date = QDate::currentDate(); } + patternInfo->UpdateData(doc->GetPatternName(), doc->GetPatternNumber(), doc->GetPatternSize(), + doc->GetCompanyName(), doc->GetCustomerName(), date); QPointF pt = geom.GetPos(); QRectF rectBB;