valentina/tools/vtoolsimplepoint.cpp

78 lines
2.9 KiB
C++
Raw Normal View History

2013-07-13 12:51:31 +02:00
#include "vtoolsimplepoint.h"
#include <QPen>
#include <QBrush>
#include <QDebug>
#include <QGraphicsItem>
#include <cmath>
#include <QMenu>
#include <QGraphicsSceneContextMenuEvent>
#include "../options.h"
#include "../container/vpointf.h"
VToolSimplePoint::VToolSimplePoint (VDomDocument *doc, VContainer *data, qint64 id, Tool::Enum typeCreation,
2013-07-17 13:38:11 +02:00
QGraphicsItem * parent ):VToolPoint(doc, data, id, parent){
if(typeCreation == Tool::FromGui){
AddToFile();
2013-07-13 12:51:31 +02:00
}
}
2013-07-17 13:38:11 +02:00
void VToolSimplePoint::AddToFile(){
2013-07-25 20:39:51 +02:00
VPointF point = VAbstractTool::data->GetPoint(id);
2013-07-13 12:51:31 +02:00
QDomElement domElement = doc->createElement("point");
2013-07-25 14:00:51 +02:00
AddAttribute(domElement, "id", id);
AddAttribute(domElement, "type", "simple");
AddAttribute(domElement, "name", point.name());
AddAttribute(domElement, "x", point.x()/PrintDPI*25.4);
AddAttribute(domElement, "y", point.y()/PrintDPI*25.4);
AddAttribute(domElement, "mx", point.mx()/PrintDPI*25.4);
AddAttribute(domElement, "my", point.my()/PrintDPI*25.4);
2013-07-13 12:51:31 +02:00
2013-07-29 14:55:40 +02:00
AddToCalculation(domElement);
2013-07-13 12:51:31 +02:00
}
2013-07-28 00:18:06 +02:00
void VToolSimplePoint::FullUpdateFromGui(int result){
if(result == QDialog::Accepted){
QPointF p = dialogSinglePoint->getPoint();
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
domElement.setAttribute("name", dialogSinglePoint->getName());
domElement.setAttribute("x", QString().setNum(p.x()/PrintDPI*25.4));
domElement.setAttribute("y", QString().setNum(p.y()/PrintDPI*25.4));
emit FullUpdateTree();
}
2013-07-13 12:51:31 +02:00
}
2013-07-28 00:18:06 +02:00
dialogSinglePoint.clear();
2013-07-13 12:51:31 +02:00
}
void VToolSimplePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){
if(!ignoreContextMenuEvent){
QMenu menu;
QAction *actionOption = menu.addAction("Властивості");
QAction *selectedAction = menu.exec(event->screenPos());
if(selectedAction == actionOption){
2013-07-28 00:18:06 +02:00
dialogSinglePoint = QSharedPointer<DialogSinglePoint>(new DialogSinglePoint(VAbstractTool::data));
connect(dialogSinglePoint.data(), &DialogSinglePoint::DialogClosed, this,
&VToolSimplePoint::FullUpdateFromGui);
2013-07-25 20:39:51 +02:00
VPointF p = VAbstractTool::data->GetPoint(id);
2013-07-13 12:51:31 +02:00
dialogSinglePoint->setData(p.name(), p.toQPointF());
2013-07-28 00:18:06 +02:00
dialogSinglePoint->exec();
2013-07-13 12:51:31 +02:00
}
}
}
void VToolSimplePoint::FullUpdateFromFile(){
QString name;
qreal x, y, mx, my;
QDomElement domElement = doc->elementById(QString().setNum(id));
if(domElement.isElement()){
name = domElement.attribute("name", "");
x = domElement.attribute("x", "").toDouble()*PrintDPI/25.4;
y = domElement.attribute("y", "").toDouble()*PrintDPI/25.4;
mx = domElement.attribute("mx", "").toDouble()*PrintDPI/25.4;
my = domElement.attribute("my", "").toDouble()*PrintDPI/25.4;
}
2013-07-25 14:00:51 +02:00
RefreshBaseGeometry(name, x, y, mx, my);
2013-07-13 12:51:31 +02:00
}