1 /************************************************************************
2 **
3 ** @file moverotationlabel.cpp
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 13 5, 2016
6 **
7 ** @brief
8 ** @copyright
9 ** This source code is part of the Valentina project, a pattern making
10 ** program, whose allow create and modeling patterns of clothing.
11 ** Copyright (C) 2016 Valentina project
12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13 **
14 ** Valentina is free software: you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation, either version 3 of the License, or
17 ** (at your option) any later version.
18 **
19 ** Valentina is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
23 **
24 ** You should have received a copy of the GNU General Public License
25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
26 **
27 *************************************************************************/
28
29 #include "operationmovelabel.h"
30
31 #include <QDomNode>
32 #include <QDomNodeList>
33
34 #include "../ifc/xml/vabstractpattern.h"
35 #include "../ifc/ifcdef.h"
36 #include "../vmisc/vabstractapplication.h"
37 #include "../vmisc/def.h"
38 #include "../vundocommand.h"
39 #include "moveabstractlabel.h"
40 #include "../vtools/tools/drawTools/vdrawtool.h"
41
42 //---------------------------------------------------------------------------------------------------------------------
OperationMoveLabel(quint32 idTool,VAbstractPattern * doc,const QPointF & pos,quint32 idPoint,QUndoCommand * parent)43 OperationMoveLabel::OperationMoveLabel(quint32 idTool, VAbstractPattern *doc, const QPointF &pos, quint32 idPoint,
44 QUndoCommand *parent)
45 : MoveAbstractLabel(doc, idPoint, pos, parent),
46 m_idTool(idTool),
47 m_scene(VAbstractValApplication::VApp()->getCurrentScene())
48 {
49 setText(tr("move point label"));
50
51 qCDebug(vUndo, "Tool id %u", m_idTool);
52
53 const QDomElement element = GetDestinationObject(m_idTool, nodeId);
54 if (element.isElement())
55 {
56 m_oldPos.rx() = VAbstractValApplication::VApp()->toPixel(doc->GetParametrDouble(element, AttrMx, "0.0"));
57 m_oldPos.ry() = VAbstractValApplication::VApp()->toPixel(doc->GetParametrDouble(element, AttrMy, "0.0"));
58
59 qCDebug(vUndo, "Label old Mx %f", m_oldPos.x());
60 qCDebug(vUndo, "Label old My %f", m_oldPos.y());
61 }
62 else
63 {
64 qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
65 }
66 }
67
68 //---------------------------------------------------------------------------------------------------------------------
mergeWith(const QUndoCommand * command)69 bool OperationMoveLabel::mergeWith(const QUndoCommand *command)
70 {
71 const OperationMoveLabel *moveCommand = static_cast<const OperationMoveLabel *>(command);
72 SCASSERT(moveCommand != nullptr)
73
74 if (moveCommand->GetToolId() != m_idTool && moveCommand->GetPointId() != nodeId)
75 {
76 return false;
77 }
78
79 qCDebug(vUndo, "Mergin undo.");
80 m_newPos = moveCommand->GetNewPos();
81 qCDebug(vUndo, "Label new Mx %f", m_newPos.x());
82 qCDebug(vUndo, "Label new My %f", m_newPos.y());
83 return true;
84 }
85
86 //---------------------------------------------------------------------------------------------------------------------
id() const87 int OperationMoveLabel::id() const
88 {
89 return static_cast<int>(UndoCommand::RotationMoveLabel);
90 }
91
92 //---------------------------------------------------------------------------------------------------------------------
Do(const QPointF & pos)93 void OperationMoveLabel::Do(const QPointF &pos)
94 {
95 qCDebug(vUndo, "New mx %f", pos.x());
96 qCDebug(vUndo, "New my %f", pos.y());
97
98 QDomElement domElement = GetDestinationObject(m_idTool, nodeId);
99 if (not domElement.isNull() && domElement.isElement())
100 {
101 doc->SetAttribute(domElement, AttrMx, QString().setNum(VAbstractValApplication::VApp()->fromPixel(pos.x())));
102 doc->SetAttribute(domElement, AttrMy, QString().setNum(VAbstractValApplication::VApp()->fromPixel(pos.y())));
103
104 if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool)))
105 {
106 tool->ChangeLabelPosition(nodeId, pos);
107 }
108 }
109 else
110 {
111 qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
112 }
113 }
114