2014-12-25 12:33:27 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file movelabel.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 25 12, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-12-25 12:33:27 +01:00
|
|
|
** <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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "movelabel.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
#include "../tools/vabstracttool.h"
|
|
|
|
#include "../../vwidgets/vmaingraphicsview.h"
|
|
|
|
|
2014-12-25 12:33:27 +01:00
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QDomElement>
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-16 10:30:25 +02:00
|
|
|
MoveLabel::MoveLabel(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
|
2014-12-25 12:33:27 +01:00
|
|
|
QUndoCommand *parent)
|
2016-03-28 14:49:35 +02:00
|
|
|
: VUndoCommand(QDomElement(), doc, parent), oldMx(0.0), oldMy(0.0), newMx(x), newMy(y), isRedo(false), scene(scene)
|
2014-12-25 12:33:27 +01:00
|
|
|
{
|
2015-06-24 16:48:57 +02:00
|
|
|
setText(tr("move point label"));
|
2014-12-25 12:33:27 +01:00
|
|
|
nodeId = id;
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Point id %u", nodeId);
|
2014-12-25 12:33:27 +01:00
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Label new Mx %f", newMx);
|
|
|
|
qCDebug(vUndo, "Label new My %f", newMy);
|
2014-12-25 12:33:27 +01:00
|
|
|
|
|
|
|
SCASSERT(scene != nullptr);
|
2015-02-11 11:43:50 +01:00
|
|
|
QDomElement domElement = doc->elementById(id);
|
2014-12-25 12:33:27 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2015-08-11 15:41:03 +02:00
|
|
|
oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0"));
|
|
|
|
oldMy = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0"));
|
2014-12-25 12:33:27 +01:00
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Label old Mx %f", oldMx);
|
|
|
|
qCDebug(vUndo, "Label old My %f", oldMy);
|
2014-12-25 12:33:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
|
2014-12-25 12:33:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MoveLabel::~MoveLabel()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MoveLabel::undo()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Undo.");
|
2014-12-25 12:33:27 +01:00
|
|
|
|
|
|
|
Do(oldMx, oldMy);
|
2016-03-28 14:49:35 +02:00
|
|
|
isRedo = true;
|
|
|
|
emit ChangePosition(nodeId, oldMx, oldMy);
|
2014-12-25 12:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MoveLabel::redo()
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Redo.");
|
2014-12-25 12:33:27 +01:00
|
|
|
|
|
|
|
Do(newMx, newMy);
|
2016-03-28 14:49:35 +02:00
|
|
|
if (isRedo)
|
|
|
|
{
|
|
|
|
emit ChangePosition(nodeId, newMx, newMy);
|
|
|
|
}
|
2014-12-25 12:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool MoveLabel::mergeWith(const QUndoCommand *command)
|
|
|
|
{
|
|
|
|
const MoveLabel *moveCommand = static_cast<const MoveLabel *>(command);
|
|
|
|
SCASSERT(moveCommand != nullptr);
|
|
|
|
const quint32 id = moveCommand->getPointId();
|
|
|
|
|
|
|
|
if (id != nodeId)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Mergin undo.");
|
2014-12-25 12:33:27 +01:00
|
|
|
newMx = moveCommand->getNewMx();
|
|
|
|
newMy = moveCommand->getNewMy();
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Label new Mx %f", newMx);
|
|
|
|
qCDebug(vUndo, "Label new My %f", newMy);
|
2014-12-25 12:33:27 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int MoveLabel::id() const
|
|
|
|
{
|
|
|
|
return static_cast<int>(UndoCommand::MoveLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MoveLabel::Do(double mx, double my)
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "New mx %f", mx);
|
|
|
|
qCDebug(vUndo, "New my %f", my);
|
2014-12-25 12:33:27 +01:00
|
|
|
|
2015-02-11 11:43:50 +01:00
|
|
|
QDomElement domElement = doc->elementById(nodeId);
|
2014-12-25 12:33:27 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2015-08-11 15:41:03 +02:00
|
|
|
doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx)));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my)));
|
2014-12-25 12:33:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
|
2014-12-25 12:33:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|