2013-09-18 21:16:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Valentina project All Rights Reserved.
|
|
|
|
**
|
|
|
|
** This file is part of Valentina.
|
|
|
|
**
|
|
|
|
** Tox 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
#include "vtoolsinglepoint.h"
|
|
|
|
|
2013-09-29 12:58:45 +02:00
|
|
|
VToolSinglePoint::VToolSinglePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation,
|
2013-09-10 14:29:06 +02:00
|
|
|
QGraphicsItem * parent ):VToolPoint(doc, data, id, parent),
|
2013-08-20 12:26:02 +02:00
|
|
|
dialogSinglePoint(QSharedPointer<DialogSinglePoint>()){
|
2013-10-21 09:45:49 +02:00
|
|
|
ignoreFullUpdate = true;
|
2013-08-13 18:48:36 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
2013-08-05 10:37:56 +02:00
|
|
|
if(typeCreation == Tool::FromGui){
|
|
|
|
AddToFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 22:39:00 +02:00
|
|
|
void VToolSinglePoint::setDialog(){
|
|
|
|
Q_ASSERT(!dialogSinglePoint.isNull());
|
|
|
|
if(!dialogSinglePoint.isNull()){
|
|
|
|
VPointF p = VAbstractTool::data.GetPoint(id);
|
|
|
|
dialogSinglePoint->setData(p.name(), p.toQPointF());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
void VToolSinglePoint::AddToFile(){
|
2013-08-13 18:48:36 +02:00
|
|
|
VPointF point = VAbstractTool::data.GetPoint(id);
|
2013-08-05 10:37:56 +02:00
|
|
|
QDomElement domElement = doc->createElement("point");
|
|
|
|
|
|
|
|
AddAttribute(domElement, "id", id);
|
|
|
|
AddAttribute(domElement, "type", "single");
|
|
|
|
AddAttribute(domElement, "name", point.name());
|
2013-09-10 14:29:06 +02:00
|
|
|
AddAttribute(domElement, "x", toMM(point.x()));
|
|
|
|
AddAttribute(domElement, "y", toMM(point.y()));
|
|
|
|
AddAttribute(domElement, "mx", toMM(point.mx()));
|
|
|
|
AddAttribute(domElement, "my", toMM(point.my()));
|
2013-08-05 10:37:56 +02:00
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
AddToCalculation(domElement);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 18:48:36 +02:00
|
|
|
QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value){
|
|
|
|
if (change == ItemPositionChange && scene()) {
|
|
|
|
// value - это новое положение.
|
|
|
|
QPointF newPos = value.toPointF();
|
|
|
|
QRectF rect = scene()->sceneRect();
|
|
|
|
if (!rect.contains(newPos)) {
|
|
|
|
// Сохраняем элемент внутри прямоугольника сцены.
|
|
|
|
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
|
|
|
|
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
|
|
|
|
return newPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (change == ItemPositionHasChanged && scene()) {
|
|
|
|
// value - это новое положение.
|
|
|
|
QPointF newPos = value.toPointF();
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
2013-09-10 14:29:06 +02:00
|
|
|
domElement.setAttribute("x", QString().setNum(toMM(newPos.x())));
|
|
|
|
domElement.setAttribute("y", QString().setNum(toMM(newPos.y())));
|
2013-08-13 18:48:36 +02:00
|
|
|
//I don't now why but signal does not work.
|
|
|
|
doc->FullUpdateTree();
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2013-09-30 18:29:03 +02:00
|
|
|
void VToolSinglePoint::decrementReferens(){
|
|
|
|
if(_referens > 1){
|
|
|
|
--_referens;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 18:48:36 +02:00
|
|
|
void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){
|
2013-08-20 12:26:02 +02:00
|
|
|
ContextMenu(dialogSinglePoint, this, event, false);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VToolSinglePoint::FullUpdateFromFile(){
|
2013-09-10 14:29:06 +02:00
|
|
|
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VToolSinglePoint::FullUpdateFromGui(int result){
|
|
|
|
if(result == QDialog::Accepted){
|
|
|
|
QPointF p = dialogSinglePoint->getPoint();
|
|
|
|
QString name = dialogSinglePoint->getName();
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
domElement.setAttribute("name", name);
|
2013-09-10 14:29:06 +02:00
|
|
|
domElement.setAttribute("x", QString().setNum(toMM(p.x())));
|
|
|
|
domElement.setAttribute("y", QString().setNum(toMM(p.y())));
|
2013-08-13 18:48:36 +02:00
|
|
|
//I don't now why but signal does not work.
|
|
|
|
doc->FullUpdateTree();
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dialogSinglePoint.clear();
|
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
|
|
|
|
void VToolSinglePoint::ChangedActivDraw(const QString newName){
|
|
|
|
if(nameActivDraw == newName){
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
VToolPoint::ChangedActivDraw(newName);
|
|
|
|
} else {
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
|
|
VToolPoint::ChangedActivDraw(newName);
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 11:17:34 +02:00
|
|
|
|
|
|
|
void VToolSinglePoint::SetFactor(qreal factor){
|
|
|
|
VDrawTool::SetFactor(factor);
|
|
|
|
RefreshPointGeometry(VAbstractTool::data.GetPoint(id));
|
|
|
|
}
|