2016-08-12 12:11:12 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpatternpiecedata.cpp
|
|
|
|
** @author Bojan Kverh
|
|
|
|
** @date July 19, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QDate>
|
|
|
|
#include <QFileInfo>
|
2016-07-18 22:30:14 +02:00
|
|
|
#include <QFontMetrics>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLatin1String>
|
|
|
|
#include <QRegularExpression>
|
2016-08-11 22:44:53 +02:00
|
|
|
#include <QApplication>
|
2016-07-18 22:30:14 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
|
|
|
#include "../vpatterndb/vpatternpiecedata.h"
|
2016-08-23 13:02:09 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-07-18 22:30:14 +02:00
|
|
|
#include "vtextmanager.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief TextLine::TextLine default constructor
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
TextLine::TextLine()
|
|
|
|
:m_qsText(), m_iFontSize(MIN_FONT_SIZE), m_eFontWeight(QFont::Normal), m_eStyle(QFont::StyleNormal),
|
|
|
|
m_eAlign(Qt::AlignCenter), m_iHeight(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::VTextManager constructor
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
VTextManager::VTextManager()
|
2016-08-02 14:12:13 +02:00
|
|
|
:m_font(), m_liLines(), m_liOutput()
|
2016-07-18 22:30:14 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::~VTextManager destructor
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
VTextManager::~VTextManager()
|
|
|
|
{}
|
|
|
|
|
2016-11-01 09:42:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VTextManager::VTextManager(const VTextManager &text)
|
|
|
|
: m_font(text.GetFont()), m_liLines(text.GetAllSourceLines()), m_liOutput(text.GetAllOutputLines())
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VTextManager &VTextManager::operator=(const VTextManager &text)
|
|
|
|
{
|
|
|
|
if ( &text == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
m_font = text.GetFont();
|
|
|
|
m_liLines = text.GetAllSourceLines();
|
|
|
|
m_liOutput = text.GetAllOutputLines();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-18 22:30:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief GetSpacing returns the vertical spacing between the lines
|
2016-11-01 10:46:51 +01:00
|
|
|
* @return spacing
|
2016-07-23 15:26:15 +02:00
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
int VTextManager::GetSpacing() const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief SetFont set the text base font
|
2016-07-23 15:26:15 +02:00
|
|
|
* @param font text base font
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
void VTextManager::SetFont(const QFont& font)
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
m_font = font;
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief GetFont returns the text base font
|
2016-07-23 15:26:15 +02:00
|
|
|
* @return text base font
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
const QFont& VTextManager::GetFont() const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
return m_font;
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief SetFontSize sets the font size
|
2016-07-23 15:26:15 +02:00
|
|
|
* @param iFS font size in pixels
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
void VTextManager::SetFontSize(int iFS)
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
m_font.setPixelSize(iFS);
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
2016-11-01 09:42:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<TextLine> VTextManager::GetAllSourceLines() const
|
|
|
|
{
|
|
|
|
return m_liLines;
|
|
|
|
}
|
|
|
|
|
2016-07-18 22:30:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief AddSourceLine add new text line to the list
|
2016-07-23 15:26:15 +02:00
|
|
|
* @param tl text line object to be added
|
|
|
|
*/
|
2016-11-01 09:42:32 +01:00
|
|
|
void VTextManager::AddSourceLine(const TextLine& tl)
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
m_liLines << tl;
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief ClearSourceLines deletes the list of texts
|
2016-07-23 15:26:15 +02:00
|
|
|
*/
|
2016-11-01 09:42:32 +01:00
|
|
|
void VTextManager::ClearSourceLines()
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
m_liLines.clear();
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief VTextManager::GetOutputLinesCount returns the number of output text lines
|
2016-07-23 15:26:15 +02:00
|
|
|
* @return number of output text lines
|
|
|
|
*/
|
2016-11-01 09:42:32 +01:00
|
|
|
int VTextManager::GetOutputLinesCount() const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
return m_liOutput.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief VTextManager::GetSourceLinesCount returns the number of input text lines
|
2016-07-23 15:26:15 +02:00
|
|
|
* @return number of text lines that were added to the list by calling AddLine
|
|
|
|
*/
|
2016-11-01 09:42:32 +01:00
|
|
|
int VTextManager::GetSourceLinesCount() const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
return m_liLines.count();
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
2016-11-01 09:42:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<TextLine> VTextManager::GetAllOutputLines() const
|
|
|
|
{
|
|
|
|
return m_liOutput;
|
|
|
|
}
|
|
|
|
|
2016-07-18 22:30:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::GetLine returns the i-th output text line
|
|
|
|
* @param i index of the output text line
|
|
|
|
* @return i-th output text line
|
|
|
|
*/
|
2016-11-01 09:42:32 +01:00
|
|
|
const TextLine& VTextManager::GetOutputLine(int i) const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
return m_liOutput[i];
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::IsBigEnough Checks if rectangle of size (fW, fH) is big enough to hold the text with base font
|
|
|
|
* size iFontSize
|
|
|
|
* @param fW rectangle width
|
|
|
|
* @param fH rectangle height
|
|
|
|
* @param iFontSize base font size
|
2016-09-29 01:39:50 +02:00
|
|
|
* @param fMinW minimal required rectangle width to fit the text
|
|
|
|
* @param fMinH minimal required rectangle height to fit the text
|
2016-07-23 15:26:15 +02:00
|
|
|
* @return true, if rectangle of size (fW, fH)
|
|
|
|
*/
|
2016-09-29 01:39:50 +02:00
|
|
|
bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize, qreal& fMinW, qreal& fMinH)
|
2016-07-18 22:30:14 +02:00
|
|
|
{
|
|
|
|
m_liOutput.clear();
|
|
|
|
QFont fnt = m_font;
|
|
|
|
int iY = 0;
|
2016-09-29 01:39:50 +02:00
|
|
|
fMinW = fW;
|
|
|
|
fMinH = fH;
|
|
|
|
|
2016-07-18 22:30:14 +02:00
|
|
|
for (int i = 0; i < m_liLines.count(); ++i)
|
|
|
|
{
|
|
|
|
const TextLine& tl = m_liLines.at(i);
|
|
|
|
TextLine tlOut = tl;
|
|
|
|
fnt.setPixelSize(iFontSize + tl.m_iFontSize);
|
|
|
|
QFontMetrics fm(fnt);
|
2016-07-29 21:59:48 +02:00
|
|
|
int iHorSp = fm.width(" ");
|
2016-07-18 22:30:14 +02:00
|
|
|
tlOut.m_iHeight = fm.height();
|
|
|
|
QStringList qslLines = SplitString(tlOut.m_qsText, fW, fm);
|
|
|
|
for (int iL = 0; iL < qslLines.count(); ++iL)
|
|
|
|
{
|
2016-07-24 12:30:10 +02:00
|
|
|
// check if every line fits within the label width
|
2016-07-29 21:59:48 +02:00
|
|
|
if (fm.width(qslLines[iL]) + iHorSp > fW)
|
2016-07-24 12:30:10 +02:00
|
|
|
{
|
2016-09-29 01:39:50 +02:00
|
|
|
fMinW = fm.width(qslLines[iL]) + iHorSp;
|
2016-07-24 12:30:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
tlOut.m_qsText = qslLines[iL];
|
|
|
|
m_liOutput << tlOut;
|
|
|
|
iY += tlOut.m_iHeight + GetSpacing();
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 01:39:50 +02:00
|
|
|
if (iY > fH)
|
|
|
|
{
|
|
|
|
fMinH = iY;
|
|
|
|
}
|
|
|
|
return iY <= fH;
|
2016-07-18 22:30:14 +02:00
|
|
|
}
|
|
|
|
|
2016-07-19 13:47:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2016-07-19 13:47:21 +02:00
|
|
|
void VTextManager::FitFontSize(qreal fW, qreal fH)
|
|
|
|
{
|
|
|
|
int iFontSize = GetFont().pixelSize();
|
2016-09-29 01:39:50 +02:00
|
|
|
qreal fMinW;
|
|
|
|
qreal fMinH;
|
|
|
|
|
|
|
|
while (IsBigEnough(fW, fH, iFontSize, fMinW, fMinH) == true && iFontSize <= MAX_FONT_SIZE)
|
2016-07-19 13:47:21 +02:00
|
|
|
{
|
|
|
|
++iFontSize;
|
|
|
|
}
|
2016-09-29 01:39:50 +02:00
|
|
|
while (IsBigEnough(fW, fH, iFontSize, fMinW, fMinH) == false && iFontSize >= MIN_FONT_SIZE)
|
2016-07-19 13:47:21 +02:00
|
|
|
{
|
|
|
|
--iFontSize;
|
|
|
|
}
|
|
|
|
SetFontSize(iFontSize);
|
|
|
|
}
|
|
|
|
|
2016-07-21 21:46:49 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::Update updates the text lines with detail data
|
|
|
|
* @param qsName detail name
|
|
|
|
* @param data reference to the detail data
|
|
|
|
*/
|
2016-07-21 21:46:49 +02:00
|
|
|
void VTextManager::Update(const QString& qsName, const VPatternPieceData& data)
|
|
|
|
{
|
2016-11-01 09:42:32 +01:00
|
|
|
ClearSourceLines();
|
2016-07-21 21:46:49 +02:00
|
|
|
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;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
// name
|
|
|
|
tl.m_qsText = qsName;
|
|
|
|
if (tl.m_qsText.isEmpty() == false)
|
|
|
|
{
|
|
|
|
tl.m_eFontWeight = QFont::DemiBold;
|
|
|
|
tl.m_iFontSize = 2;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
// MCP
|
2016-08-11 22:44:53 +02:00
|
|
|
QStringList qslMaterials;
|
|
|
|
qslMaterials << QApplication::translate("Detail", "Fabric", 0)
|
|
|
|
<< QApplication::translate("Detail", "Lining", 0)
|
|
|
|
<< QApplication::translate("Detail", "Interfacing", 0)
|
|
|
|
<< QApplication::translate("Detail", "Interlining", 0);
|
2016-08-26 11:28:30 +02:00
|
|
|
QString qsText = QLatin1String("%1, ") + tr("cut") + QLatin1String(" %2%3");
|
2016-07-21 21:46:49 +02:00
|
|
|
QStringList qslPlace;
|
2016-08-26 11:28:30 +02:00
|
|
|
qslPlace << "" << QLatin1String(" ") + tr("on fold");
|
2016-07-21 21:46:49 +02:00
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_iFontSize = 0;
|
|
|
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
|
|
|
{
|
|
|
|
MaterialCutPlacement mcp = data.GetMCP(i);
|
2016-08-22 10:47:21 +02:00
|
|
|
if (mcp.m_iCutNumber > 0)//Not gonna happen because min value is 1 now, but decided to left
|
2016-07-21 21:46:49 +02:00
|
|
|
{
|
2016-08-11 22:44:53 +02:00
|
|
|
QString qsMat;
|
|
|
|
if (mcp.m_eMaterial == MaterialType::mtUserDefined)
|
|
|
|
{
|
|
|
|
qsMat = mcp.m_qsMaterialUserDef;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qsMat = qslMaterials[int(mcp.m_eMaterial)];
|
|
|
|
}
|
2016-08-22 11:00:12 +02:00
|
|
|
tl.m_qsText = qsText.arg(qsMat).arg(mcp.m_iCutNumber).
|
2016-07-21 21:46:49 +02:00
|
|
|
arg(qslPlace[int(mcp.m_ePlacement)]);
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::Update updates the text lines with pattern info
|
|
|
|
* @param pDoc pointer to the abstract pattern object
|
|
|
|
*/
|
2016-08-15 13:03:59 +02:00
|
|
|
void VTextManager::Update(const VAbstractPattern *pDoc, qreal dSize, qreal dHeight)
|
2016-07-21 21:46:49 +02:00
|
|
|
{
|
2016-11-01 09:42:32 +01:00
|
|
|
ClearSourceLines();
|
2016-07-21 21:46:49 +02:00
|
|
|
TextLine tl;
|
|
|
|
// all information must be centered
|
|
|
|
tl.m_eAlign = Qt::AlignCenter;
|
|
|
|
|
|
|
|
// Company name
|
2016-07-22 11:56:45 +02:00
|
|
|
tl.m_qsText = pDoc->GetCompanyName();
|
2016-07-21 21:46:49 +02:00
|
|
|
if (tl.m_qsText.isEmpty() == false)
|
|
|
|
{
|
|
|
|
tl.m_eFontWeight = QFont::DemiBold;
|
|
|
|
tl.m_eStyle = QFont::StyleNormal;
|
|
|
|
tl.m_iFontSize = 4;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
// Pattern name
|
2016-07-22 11:56:45 +02:00
|
|
|
tl.m_qsText = pDoc->GetPatternName();
|
2016-07-21 21:46:49 +02:00
|
|
|
if (tl.m_qsText.isEmpty() == false)
|
|
|
|
{
|
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_eStyle = QFont::StyleNormal;
|
|
|
|
tl.m_iFontSize = 2;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
// Pattern number
|
2016-07-22 11:56:45 +02:00
|
|
|
tl.m_qsText = pDoc->GetPatternNumber();
|
2016-07-21 21:46:49 +02:00
|
|
|
if (tl.m_qsText.isEmpty() == false)
|
|
|
|
{
|
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_eStyle = QFont::StyleNormal;
|
|
|
|
tl.m_iFontSize = 0;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
// Customer name
|
2016-07-22 11:56:45 +02:00
|
|
|
tl.m_qsText = pDoc->GetCustomerName();
|
2016-07-21 21:46:49 +02:00
|
|
|
if (tl.m_qsText.isEmpty() == false)
|
|
|
|
{
|
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_eStyle = QFont::StyleItalic;
|
|
|
|
tl.m_iFontSize = 0;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
// Size
|
2016-07-22 11:56:45 +02:00
|
|
|
tl.m_qsText = pDoc->GetPatternSize();
|
2016-07-21 21:46:49 +02:00
|
|
|
if (tl.m_qsText.isEmpty() == false)
|
|
|
|
{
|
2016-08-23 13:02:09 +02:00
|
|
|
// 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));
|
|
|
|
|
2016-07-21 21:46:49 +02:00
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_eStyle = QFont::StyleNormal;
|
|
|
|
tl.m_iFontSize = 0;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
2016-07-24 12:30:10 +02:00
|
|
|
// Measurements
|
2016-07-25 19:10:13 +02:00
|
|
|
tl.m_qsText = QFileInfo(pDoc->MPath()).fileName();
|
2016-07-24 12:30:10 +02:00
|
|
|
if (tl.m_qsText.isEmpty() == false && pDoc->IsMeasurementsVisible() == true)
|
|
|
|
{
|
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_eStyle = QFont::StyleNormal;
|
|
|
|
tl.m_iFontSize = 0;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-24 12:30:10 +02:00
|
|
|
}
|
2016-07-21 21:46:49 +02:00
|
|
|
// Date
|
2016-07-22 11:56:45 +02:00
|
|
|
QDate date;
|
|
|
|
if (pDoc->IsDateVisible() == true)
|
|
|
|
{
|
|
|
|
date = QDate::currentDate();
|
|
|
|
}
|
2016-07-21 21:46:49 +02:00
|
|
|
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;
|
2016-11-01 09:42:32 +01:00
|
|
|
AddSourceLine(tl);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
2016-07-22 11:56:45 +02:00
|
|
|
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
2016-07-18 22:30:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::SplitString splits the string into several lines, which all fit into width fW
|
|
|
|
* @param qs string to split
|
|
|
|
* @param fW required width of every output string
|
|
|
|
* @param fm font metrics of the font used
|
|
|
|
* @return list of strings, each of which is not wider than fW using the font metrics fm
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm)
|
|
|
|
{
|
|
|
|
QRegularExpression reg("\\s+");
|
2016-07-23 15:26:15 +02:00
|
|
|
// split the string into words
|
2016-07-18 22:30:14 +02:00
|
|
|
QStringList qslWords = qs.split(reg);
|
|
|
|
QStringList qslLines;
|
|
|
|
QString qsCurrent;
|
|
|
|
for (int i = 0; i < qslWords.count(); ++i)
|
|
|
|
{
|
|
|
|
if (qsCurrent.length() > 0)
|
|
|
|
{
|
2016-08-02 14:12:13 +02:00
|
|
|
qsCurrent += QLatin1String(" ");
|
2016-07-18 22:30:14 +02:00
|
|
|
}
|
2016-07-23 15:26:15 +02:00
|
|
|
// check if another word can be added into current line
|
2016-07-18 22:30:14 +02:00
|
|
|
if (fm.width(qsCurrent + qslWords[i]) > fW)
|
|
|
|
{
|
2016-07-23 15:26:15 +02:00
|
|
|
// if not, add the current line into the list of text lines
|
2016-07-24 12:30:10 +02:00
|
|
|
if (qsCurrent.isEmpty() == false)
|
|
|
|
{
|
|
|
|
qslLines << qsCurrent;
|
|
|
|
}
|
2016-07-23 15:26:15 +02:00
|
|
|
// and set the current line to contain the current word
|
2016-07-18 22:30:14 +02:00
|
|
|
qsCurrent = qslWords[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qsCurrent += qslWords[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qslLines << qsCurrent;
|
|
|
|
return qslLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|