Moving and resizing pattern info label (has few bugs still, probably just XML parsing)

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-06-27 01:17:27 +02:00
parent 28c4eddbd7
commit fa105537d2
7 changed files with 236 additions and 14 deletions

View File

@ -82,6 +82,11 @@ void VPattern::CreateEmptyFile()
version.appendChild(newNodeText); version.appendChild(newNodeText);
patternElement.appendChild(version); patternElement.appendChild(version);
QDomElement domCreated = createElement(TagCreationDate);
QDomText domCreatedText = createTextNode(QDate::currentDate().toString("d.M.yyyy"));
domCreated.appendChild(domCreatedText);
patternElement.appendChild(domCreated);
QDomElement unit = createElement(TagUnit); QDomElement unit = createElement(TagUnit);
newNodeText = createTextNode(UnitsToStr(qApp->patternUnit())); newNodeText = createTextNode(UnitsToStr(qApp->patternUnit()));
unit.appendChild(newNodeText); unit.appendChild(newNodeText);
@ -131,7 +136,9 @@ void VPattern::Parse(const Document &parse)
SCASSERT(sceneDraw != nullptr); SCASSERT(sceneDraw != nullptr);
SCASSERT(sceneDetail != nullptr); SCASSERT(sceneDetail != nullptr);
QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes
<< TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit; << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit
<< TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName
<< TagCreationDate;
PrepareForParse(parse); PrepareForParse(parse);
QDomNode domNode = documentElement().firstChild(); QDomNode domNode = documentElement().firstChild();
while (domNode.isNull() == false) while (domNode.isNull() == false)
@ -191,6 +198,21 @@ void VPattern::Parse(const Document &parse)
case 9: // TagUnit case 9: // TagUnit
qCDebug(vXML, "Tag unit."); qCDebug(vXML, "Tag unit.");
break; break;
case 10: // TagPatternName
qCDebug(vXML, "Pattern name.");
break;
case 11: // TagPatternNumber
qCDebug(vXML, "Pattern number.");
break;
case 12: // TagCompanyName
qCDebug(vXML, "Company name.");
break;
case 13: // TagCustomerName
qCDebug(vXML, "Customer name.");
break;
case 14: // TagCreationDate
qCDebug(vXML, "Creation date.");
break;
default: default:
qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName()));
break; break;

View File

@ -67,6 +67,7 @@ const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"
const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer");
const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company");
const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created");
const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel");
const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrName = QStringLiteral("name");
const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible");
@ -78,6 +79,8 @@ const QString VAbstractPattern::AttrMaterial = QStringLiteral("material");
const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef");
const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber");
const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement");
const QString VAbstractPattern::AttrWidth = QStringLiteral("width");
const QString VAbstractPattern::AttrFont = QStringLiteral("font");
const QString VAbstractPattern::AttrAll = QStringLiteral("all"); const QString VAbstractPattern::AttrAll = QStringLiteral("all");
@ -1075,6 +1078,92 @@ QDate VAbstractPattern::GetCreationDate() const
return QDate::currentDate(); return QDate::currentDate();
} }
//---------------------------------------------------------------------------------------------------------------------
QPointF VAbstractPattern::GetLabelPosition() const
{
QPointF ptPos(0.0, 0.0);
QDomNodeList li = elementsByTagName(TagPatternLabel);
if (li.count() == 0)
{
return ptPos;
}
QDomNamedNodeMap attr = li.at(0).attributes();
if (attr.contains(AttrMx) == true)
{
ptPos.setX(attr.namedItem(AttrMx).nodeValue().toDouble());
}
if (attr.contains(AttrMy) == true)
{
ptPos.setY(attr.namedItem(AttrMy).nodeValue().toDouble());
}
return ptPos;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetLabelPosition(const QPointF& ptPos)
{
CheckTagExists(TagPatternLabel);
QDomNode node = elementsByTagName(TagPatternLabel).at(0);
node.toElement().setAttribute(AttrMx, ptPos.x());
node.toElement().setAttribute(AttrMy, ptPos.y());
emit patternChanged(false);
qDebug() << "LABEL POSITION" << GetLabelPosition();
}
//---------------------------------------------------------------------------------------------------------------------
qreal VAbstractPattern::GetLabelWidth() const
{
qreal fW = 0.0;
QDomNodeList li = elementsByTagName(TagPatternLabel);
if (li.count() == 0)
{
return fW;
}
QDomNamedNodeMap attr = li.at(0).attributes();
if (attr.contains(AttrWidth) == true)
{
fW = attr.namedItem(AttrWidth).nodeName().toDouble();
}
return fW;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetLabelWidth(qreal fW)
{
CheckTagExists(TagPatternLabel);
QDomNode node = elementsByTagName(TagPatternLabel).at(0);
node.toElement().setAttribute(AttrWidth, fW);
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
int VAbstractPattern::GetFontSize() const
{
int iFS = 0;
QDomNodeList li = elementsByTagName(TagPatternLabel);
if (li.count() == 0)
{
return iFS;
}
QDomNamedNodeMap attr = li.at(0).attributes();
if (attr.contains(AttrFont) == true)
{
iFS = attr.namedItem(AttrFont).nodeName().toInt();
}
return iFS;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetFontSize(int iFS)
{
CheckTagExists(TagPatternLabel);
QDomNode node = elementsByTagName(TagPatternLabel).at(0);
node.toElement().setAttribute(AttrWidth, iFS);
emit patternChanged(false);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetImage() const QString VAbstractPattern::GetImage() const
{ {
@ -1200,7 +1289,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
{ {
const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes
<< TagGradation << TagPatternName << TagPatternNum << TagCompanyName << TagGradation << TagPatternName << TagPatternNum << TagCompanyName
<< TagCustomerName << TagCreationDate; << TagCustomerName << TagCreationDate << TagPatternLabel;
switch (tags.indexOf(tag)) switch (tags.indexOf(tag))
{ {
case 0: //TagUnit case 0: //TagUnit
@ -1266,6 +1355,11 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
element = createElement(TagCreationDate); element = createElement(TagCreationDate);
break; break;
} }
case 11:
{
element = createElement(TagPatternLabel);
break;
}
default: default:
{ {

View File

@ -117,6 +117,12 @@ public:
QString GetCustomerName() const; QString GetCustomerName() const;
void SetCustomerName(QString qsName); void SetCustomerName(QString qsName);
QDate GetCreationDate() const; QDate GetCreationDate() const;
QPointF GetLabelPosition() const;
void SetLabelPosition(const QPointF& ptPos);
qreal GetLabelWidth() const;
void SetLabelWidth(qreal fW);
int GetFontSize() const;
void SetFontSize(int iFS);
QString GetImage() const; QString GetImage() const;
QString GetImageExtension() const; QString GetImageExtension() const;
@ -173,6 +179,7 @@ public:
static const QString TagCompanyName; static const QString TagCompanyName;
static const QString TagCustomerName; static const QString TagCustomerName;
static const QString TagCreationDate; static const QString TagCreationDate;
static const QString TagPatternLabel;
static const QString AttrName; static const QString AttrName;
static const QString AttrVisible; static const QString AttrVisible;
@ -184,6 +191,8 @@ public:
static const QString AttrUserDefined; static const QString AttrUserDefined;
static const QString AttrCutNumber; static const QString AttrCutNumber;
static const QString AttrPlacement; static const QString AttrPlacement;
static const QString AttrWidth;
static const QString AttrFont;
static const QString AttrAll; static const QString AttrAll;
@ -308,6 +317,8 @@ protected:
QDomElement CheckTagExists(const QString &tag); QDomElement CheckTagExists(const QString &tag);
void InsertTag(const QStringList &tags, const QDomElement &element); void InsertTag(const QStringList &tags, const QDomElement &element);
void SetChildTag(const QString& qsParent, const QString& qsChild, const QString& qsValue);
int GetIndexActivPP() const; int GetIndexActivPP() const;
private: private:
Q_DISABLE_COPY(VAbstractPattern) Q_DISABLE_COPY(VAbstractPattern)

View File

@ -124,6 +124,16 @@ void VTextGraphicsItem::Clear()
m_liLines.clear(); m_liLines.clear();
} }
//---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::SetWidth(qreal fW)
{
if (fW < MIN_W)
{
fW = MIN_W;
}
m_rectBoundingBox.setWidth(fW);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VTextGraphicsItem::Reset() void VTextGraphicsItem::Reset()
{ {

View File

@ -66,6 +66,7 @@ public:
QRectF boundingRect() const; QRectF boundingRect() const;
void AddLine(const TextLine& tl); void AddLine(const TextLine& tl);
void Clear(); void Clear();
void SetWidth(qreal fW);
protected: protected:
void Resize(qreal fW, qreal fH); void Resize(qreal fW, qreal fH);
@ -78,9 +79,9 @@ protected:
QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm);
signals: signals:
void SignalMoved(QPointF ptPos); void SignalMoved(QPointF ptPos);
void SignalResized(qreal iTW, int iFontSize); void SignalResized(qreal iTW, int iFontSize);
void SignalShrink(); void SignalShrink();
private: private:
Mode m_eMode; Mode m_eMode;

View File

@ -79,7 +79,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent) VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent)
:VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene), :VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene),
drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)), drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)),
dataLabel(new VTextGraphicsItem(this)) dataLabel(new VTextGraphicsItem(this)), patternInfo(new VTextGraphicsItem(this))
{ {
VDetail detail = data->GetDetail(id); VDetail detail = data->GetDetail(id);
for (int i = 0; i< detail.CountNode(); ++i) for (int i = 0; i< detail.CountNode(); ++i)
@ -128,10 +128,16 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
} }
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMove); connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail);
connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResize); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail);
connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern);
connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern);
connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo);
UpdateLabel(); UpdateLabel();
UpdatePatternInfo();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -684,9 +690,63 @@ void VToolDetail::UpdateLabel()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief SaveMove saves the move operation to the undo stack * @brief UpdatePatternInfo updates the pattern info label
*/ */
void VToolDetail::SaveMove(QPointF ptPos) void VToolDetail::UpdatePatternInfo()
{
QFont fnt = qApp->font();
int iFS = doc->GetFontSize();
if (iFS < MIN_FONT_SIZE)
{
iFS = MIN_FONT_SIZE;
}
fnt.setPixelSize(iFS);
patternInfo->SetFont(fnt);
patternInfo->SetWidth(doc->GetLabelWidth());
patternInfo->Clear();
TextLine tl;
// Company name
tl.m_qsText = doc->GetCompanyName();
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();
tl.m_eFontWeight = QFont::Normal;
tl.m_iFontSize = 2;
patternInfo->AddLine(tl);
// Pattern number
tl.m_qsText = doc->GetPatternNumber();
tl.m_iFontSize = 0;
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
patternInfo->AddLine(tl);
// Customer name
tl.m_qsText = doc->GetCustomerName();
tl.m_eStyle = QFont::StyleItalic;
patternInfo->AddLine(tl);
// Creation date
QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", ");
tl.m_qsText = qslDate.last();
patternInfo->AddLine(tl);
qDebug() << "UpdatePatternInfo" << doc->GetLabelPosition() << sender();
patternInfo->setPos(doc->GetLabelPosition());
patternInfo->Reset();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveMoveDetail saves the move detail operation to the undo stack
*/
void VToolDetail::SaveMoveDetail(QPointF ptPos)
{ {
VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet; VDetail newDet = oldDet;
@ -699,9 +759,9 @@ void VToolDetail::SaveMove(QPointF ptPos)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief: SaveResize save the resize label operation to the undo stack * @brief SaveResizeDetail saves the resize detail label operation to the undo stack
*/ */
void VToolDetail::SaveResize(qreal dLabelW, int iFontSize) void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize)
{ {
VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet; VDetail newDet = oldDet;
@ -713,6 +773,26 @@ void VToolDetail::SaveResize(qreal dLabelW, int iFontSize)
qApp->getUndoStack()->push(resizeCommand); qApp->getUndoStack()->push(resizeCommand);
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveMovePattern saves the pattern label position
*/
void VToolDetail::SaveMovePattern(QPointF ptPos)
{
qDebug() << "Pattern moved to" << ptPos;
doc->SetLabelPosition(ptPos);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief: SaveResizePattern saves the pattern label width and font size
*/
void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize)
{
doc->SetLabelWidth(dLabelW);
doc->SetFontSize(iFontSize);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief AddNode add node to the file. * @brief AddNode add node to the file.

View File

@ -106,10 +106,13 @@ protected:
virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE;
virtual void SetVisualization() Q_DECL_OVERRIDE {} virtual void SetVisualization() Q_DECL_OVERRIDE {}
virtual void UpdateLabel(); virtual void UpdateLabel();
virtual void UpdatePatternInfo();
protected slots: protected slots:
virtual void SaveMove(QPointF ptPos); virtual void SaveMoveDetail(QPointF ptPos);
virtual void SaveResize(qreal dLabelW, int iFontSize); virtual void SaveResizeDetail(qreal dLabelW, int iFontSize);
virtual void SaveMovePattern(QPointF ptPos);
virtual void SaveResizePattern(qreal dLabelW, int iFontSize);
private: private:
Q_DISABLE_COPY(VToolDetail) Q_DISABLE_COPY(VToolDetail)
@ -122,6 +125,7 @@ private:
VNoBrushScalePathItem *seamAllowance; VNoBrushScalePathItem *seamAllowance;
VTextGraphicsItem* dataLabel; VTextGraphicsItem* dataLabel;
VTextGraphicsItem* patternInfo;
VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr);