2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vtooldetail.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @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
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
#include "vtooldetail.h"
|
2013-09-10 14:29:06 +02:00
|
|
|
#include "nodeDetails/nodedetails.h"
|
2016-01-10 14:31:43 +01:00
|
|
|
#include "../vgeometry/varc.h"
|
2016-03-10 18:08:37 +01:00
|
|
|
#include "../vgeometry/vcubicbezier.h"
|
2016-01-10 14:31:43 +01:00
|
|
|
#include "../vgeometry/vsplinepath.h"
|
2016-03-22 16:33:05 +01:00
|
|
|
#include "../vgeometry/vcubicbezierpath.h"
|
2016-01-10 14:31:43 +01:00
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2016-01-15 13:57:47 +01:00
|
|
|
#include "../vwidgets/vmaingraphicsview.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../dialogs/tools/dialogtool.h"
|
|
|
|
#include "../dialogs/tools/dialogdetail.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
#include "../undocommands/savedetailoptions.h"
|
|
|
|
#include "../undocommands/movedetail.h"
|
|
|
|
#include "../undocommands/adddet.h"
|
|
|
|
#include "../undocommands/deletedetail.h"
|
2016-06-21 19:53:15 +02:00
|
|
|
#include "../vpatterndb/vpatternpiecedata.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2014-04-17 19:18:26 +02:00
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QMenu>
|
2014-06-03 14:15:17 +02:00
|
|
|
#include <QGraphicsView>
|
2014-06-16 14:14:46 +02:00
|
|
|
#include <QMessageBox>
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VToolDetail::TagNode = QStringLiteral("node");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VToolDetail::AttrSupplement = QStringLiteral("supplement");
|
|
|
|
const QString VToolDetail::AttrClosed = QStringLiteral("closed");
|
|
|
|
const QString VToolDetail::AttrWidth = QStringLiteral("width");
|
2016-06-27 17:18:43 +02:00
|
|
|
const QString VToolDetail::AttrHeight = QStringLiteral("height");
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType");
|
2014-12-17 13:56:14 +01:00
|
|
|
const QString VToolDetail::AttrReverse = QStringLiteral("reverse");
|
2016-06-23 22:35:32 +02:00
|
|
|
const QString VToolDetail::AttrFont = QStringLiteral("fontSize");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
2013-10-29 18:46:58 +01:00
|
|
|
const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour");
|
2013-10-29 14:45:07 +01:00
|
|
|
const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling");
|
|
|
|
|
2014-04-17 19:18:26 +02:00
|
|
|
const QString VToolDetail::NodeArc = QStringLiteral("NodeArc");
|
|
|
|
const QString VToolDetail::NodePoint = QStringLiteral("NodePoint");
|
|
|
|
const QString VToolDetail::NodeSpline = QStringLiteral("NodeSpline");
|
|
|
|
const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath");
|
2014-02-25 19:03:17 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief VToolDetail constructor.
|
|
|
|
* @param doc dom document container
|
|
|
|
* @param data container with variables
|
|
|
|
* @param id object id in container
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param parent parent object
|
|
|
|
*/
|
2015-06-18 19:23:24 +02:00
|
|
|
VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
|
2016-01-07 17:43:08 +01:00
|
|
|
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent)
|
2016-01-10 14:31:43 +01:00
|
|
|
:VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene),
|
2016-06-23 00:59:45 +02:00
|
|
|
drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)),
|
2016-06-27 01:17:27 +02:00
|
|
|
dataLabel(new VTextGraphicsItem(this)), patternInfo(new VTextGraphicsItem(this))
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail detail = data->GetDetail(id);
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i< detail.CountNode(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-09 21:11:33 +02:00
|
|
|
switch (detail.at(i).getTypeTool())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2016-06-17 15:13:49 +02:00
|
|
|
{
|
|
|
|
VNodePoint *tool = InitTool<VNodePoint>(scene, detail.at(i));
|
|
|
|
connect(tool, &VNodePoint::ShowContextMenu, this, &VToolDetail::contextMenuEvent);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2016-06-17 15:13:49 +02:00
|
|
|
}
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2016-02-10 17:45:49 +01:00
|
|
|
doc->IncrementReferens(detail.at(i).getId());
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2016-02-10 17:45:49 +01:00
|
|
|
doc->IncrementReferens(detail.at(i).getId());
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2016-02-10 17:45:49 +01:00
|
|
|
doc->IncrementReferens(detail.at(i).getId());
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"Get wrong tool type. Ignore.";
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
|
|
RefreshGeometry();
|
2016-01-10 14:31:43 +01:00
|
|
|
|
|
|
|
this->setBrush(QBrush(Qt::Dense7Pattern));
|
|
|
|
seamAllowance->setBrush(QBrush(Qt::FDiagPattern));
|
|
|
|
|
2013-08-28 10:55:11 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
2016-05-08 17:04:18 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
2015-12-20 20:53:59 +01:00
|
|
|
|
|
|
|
connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove);
|
2016-06-27 11:06:51 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChildren);
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-15 19:07:54 +02:00
|
|
|
AddToFile();
|
|
|
|
if (typeCreation != Source::FromTool)
|
|
|
|
{
|
|
|
|
qApp->getUndoStack()->endMacro();
|
|
|
|
}
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2015-12-02 20:33:42 +01:00
|
|
|
setAcceptHoverEvents(true);
|
2016-06-23 22:35:32 +02:00
|
|
|
|
2016-06-27 01:17:27 +02:00
|
|
|
connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail);
|
|
|
|
connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail);
|
2016-06-25 17:19:44 +02:00
|
|
|
connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll);
|
2016-06-27 01:17:27 +02:00
|
|
|
|
|
|
|
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);
|
2016-06-27 20:51:29 +02:00
|
|
|
|
|
|
|
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel);
|
2016-06-24 17:57:08 +02:00
|
|
|
UpdateLabel();
|
2016-06-27 01:17:27 +02:00
|
|
|
UpdatePatternInfo();
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-06 14:57:23 +01:00
|
|
|
VToolDetail::~VToolDetail()
|
|
|
|
{
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief setDialog set dialog when user want change tool option.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::setDialog()
|
|
|
|
{
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2014-01-02 16:50:01 +01:00
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
2015-01-27 17:32:50 +01:00
|
|
|
dialogTool->setDetail(detail);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool from GUI.
|
|
|
|
* @param dialog dialog.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
*/
|
2015-06-18 19:23:24 +02:00
|
|
|
void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2014-02-06 14:57:23 +01:00
|
|
|
DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
2015-01-27 17:32:50 +01:00
|
|
|
VDetail detail = dialogTool->getDetail();
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail det;
|
2014-06-15 19:07:54 +02:00
|
|
|
qApp->getUndoStack()->beginMacro("add detail");
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i< detail.CountNode(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = 0;
|
2015-11-02 17:25:29 +01:00
|
|
|
const VNodeDetail &nodeD = detail.at(i);
|
2015-10-28 15:22:36 +01:00
|
|
|
switch (nodeD.getTypeTool())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
id = CreateNode<VPointF>(data, nodeD.getId());
|
2015-12-26 18:10:02 +01:00
|
|
|
VNodePoint::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
id = CreateNode<VArc>(data, nodeD.getId());
|
2016-02-10 17:45:49 +01:00
|
|
|
VNodeArc::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-10 18:08:37 +01:00
|
|
|
const auto obj = data->GetGObject(nodeD.getId());
|
|
|
|
if (obj->getType() == GOType::Spline)
|
|
|
|
{
|
|
|
|
id = CreateNode<VSpline>(data, nodeD.getId());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id = CreateNode<VCubicBezier>(data, nodeD.getId());
|
|
|
|
}
|
2016-02-10 17:45:49 +01:00
|
|
|
VNodeSpline::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-22 16:33:05 +01:00
|
|
|
const auto obj = data->GetGObject(nodeD.getId());
|
|
|
|
if (obj->getType() == GOType::SplinePath)
|
|
|
|
{
|
|
|
|
id = CreateNode<VSplinePath>(data, nodeD.getId());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id = CreateNode<VCubicBezierPath>(data, nodeD.getId());
|
|
|
|
}
|
2016-02-10 17:45:49 +01:00
|
|
|
VNodeSplinePath::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2013-11-04 21:35:15 +01:00
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2016-02-10 17:45:49 +01:00
|
|
|
VNodeDetail node(id, nodeD.getTypeTool(), NodeDetail::Contour, nodeD.getMx(), nodeD.getMy(),
|
|
|
|
nodeD.getReverse());
|
2013-12-30 19:59:33 +01:00
|
|
|
det.append(node);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2013-12-30 19:59:33 +01:00
|
|
|
det.setName(detail.getName());
|
2014-06-15 19:07:54 +02:00
|
|
|
det.setWidth(detail.getWidth());
|
2014-11-20 19:13:27 +01:00
|
|
|
det.setClosed(detail.getClosed());
|
|
|
|
det.setSeamAllowance(detail.getSeamAllowance());
|
2014-06-12 09:22:29 +02:00
|
|
|
Create(0, det, scene, doc, data, Document::FullParse, Source::FromGui);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief Create help create tool.
|
|
|
|
* @param _id tool id, 0 if tool doesn't exist yet.
|
|
|
|
* @param newDetail detail what we want show.
|
|
|
|
* @param scene pointer to scene.
|
|
|
|
* @param doc dom document container.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param parse parser file mode.
|
|
|
|
* @param typeCreation way we create this tool.
|
|
|
|
*/
|
2015-06-18 19:23:24 +02:00
|
|
|
void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, VAbstractPattern *doc,
|
2016-01-07 17:43:08 +01:00
|
|
|
VContainer *data, const Document &parse, const Source &typeCreation, const QString &drawName)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 id = _id;
|
2014-06-12 09:22:29 +02:00
|
|
|
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
id = data->AddDetail(newDetail);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
data->UpdateDetail(id, newDetail);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse != Document::FullParse)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
doc->UpdateToolData(id, data);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-26 20:31:28 +02:00
|
|
|
VAbstractTool::AddRecord(id, Tool::Detail, doc);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (parse == Document::FullParse)
|
|
|
|
{
|
2016-01-07 17:43:08 +01:00
|
|
|
VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene, drawName);
|
2013-08-28 10:55:11 +02:00
|
|
|
scene->addItem(detail);
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
2016-03-31 16:01:41 +02:00
|
|
|
connect(scene, &VMainGraphicsScene::EnableDetailItemHover, detail, &VToolDetail::AllowHover);
|
|
|
|
connect(scene, &VMainGraphicsScene::EnableDetailItemSelection, detail, &VToolDetail::AllowSelecting);
|
2016-02-10 11:13:34 +01:00
|
|
|
doc->AddTool(id, detail);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief Remove full delete detail.
|
|
|
|
*/
|
2014-06-15 19:07:54 +02:00
|
|
|
void VToolDetail::Remove(bool ask)
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
DeleteTool(ask);
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::FullUpdateFromFile()
|
|
|
|
{
|
2013-08-28 10:55:11 +02:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromGuiOk refresh tool data after change in options.
|
|
|
|
* @param result keep result working dialog.
|
|
|
|
*/
|
2014-06-11 18:38:09 +02:00
|
|
|
void VToolDetail::FullUpdateFromGuiOk(int result)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (result == QDialog::Accepted)
|
|
|
|
{
|
2014-06-12 15:38:28 +02:00
|
|
|
SCASSERT(dialog != nullptr);
|
2016-06-18 16:00:01 +02:00
|
|
|
DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
|
2016-06-18 22:14:35 +02:00
|
|
|
SCASSERT(dialogTool != nullptr);
|
|
|
|
|
|
|
|
VDetail newDet = dialogTool->getDetail();
|
|
|
|
VDetail oldDet = VAbstractTool::data.GetDetail(id);
|
|
|
|
|
2016-06-26 14:21:06 +02:00
|
|
|
qDebug() << "VToolDetail Position" << newDet.GetPatternPieceData().GetPos();
|
2014-06-12 15:38:28 +02:00
|
|
|
SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
|
2015-06-16 17:01:17 +02:00
|
|
|
connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
2014-06-12 15:38:28 +02:00
|
|
|
qApp->getUndoStack()->push(saveCommand);
|
2016-06-24 17:57:08 +02:00
|
|
|
UpdateLabel();
|
2013-10-25 13:10:45 +02:00
|
|
|
}
|
2014-02-06 14:57:23 +01:00
|
|
|
delete dialog;
|
2014-06-12 09:22:29 +02:00
|
|
|
dialog = nullptr;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief AddToFile add tag with informations about tool into file.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::AddToFile()
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
2016-05-16 19:59:04 +02:00
|
|
|
QDomElement domElement = doc->createElement(getTagName());
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-03-21 11:08:29 +01:00
|
|
|
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, detail.getName());
|
2014-03-19 19:27:11 +01:00
|
|
|
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(detail.getMx()));
|
|
|
|
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(detail.getMy()));
|
2014-10-28 12:33:39 +01:00
|
|
|
doc->SetAttribute(domElement, AttrSupplement, static_cast<quint8>(detail.getSeamAllowance()));
|
|
|
|
doc->SetAttribute(domElement, AttrClosed, static_cast<quint8>(detail.getClosed()));
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrWidth, detail.getWidth());
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2016-06-21 00:49:22 +02:00
|
|
|
QDomElement domData = doc->createElement(VAbstractPattern::TagData);
|
2016-06-23 22:35:32 +02:00
|
|
|
const VPatternPieceData& data = detail.GetPatternPieceData();
|
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
|
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName());
|
|
|
|
doc->SetAttribute(domData, AttrMx, data.GetPos().x());
|
|
|
|
doc->SetAttribute(domData, AttrMy, data.GetPos().y());
|
|
|
|
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth());
|
2016-06-27 17:18:43 +02:00
|
|
|
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
|
2016-06-23 22:35:32 +02:00
|
|
|
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
|
|
|
|
|
|
|
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
2016-06-21 00:49:22 +02:00
|
|
|
{
|
2016-06-23 22:35:32 +02:00
|
|
|
MaterialCutPlacement mcp = data.GetMCP(i);
|
2016-06-21 00:49:22 +02:00
|
|
|
QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial));
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement));
|
|
|
|
domData.appendChild(domMCP);
|
|
|
|
}
|
|
|
|
domElement.appendChild(domData);
|
|
|
|
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i < detail.CountNode(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-06-12 15:38:28 +02:00
|
|
|
AddNode(doc, domElement, detail.at(i));
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2016-01-07 17:43:08 +01:00
|
|
|
AddDet *addDet = new AddDet(domElement, doc, detail, drawName);
|
2015-06-18 19:23:24 +02:00
|
|
|
connect(addDet, &AddDet::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
|
2014-06-15 19:07:54 +02:00
|
|
|
qApp->getUndoStack()->push(addDet);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
|
|
|
|
*/
|
2013-12-24 12:24:29 +01:00
|
|
|
void VToolDetail::RefreshDataInFile()
|
|
|
|
{
|
2015-02-11 11:43:50 +01:00
|
|
|
QDomElement domElement = doc->elementById(id);
|
2013-12-24 12:24:29 +01:00
|
|
|
if (domElement.isElement())
|
|
|
|
{
|
2013-12-30 19:59:33 +01:00
|
|
|
VDetail det = VAbstractTool::data.GetDetail(id);
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrName, det.getName());
|
2014-10-28 12:33:39 +01:00
|
|
|
doc->SetAttribute(domElement, AttrSupplement, QString().setNum(static_cast<quint8>(det.getSeamAllowance())));
|
|
|
|
doc->SetAttribute(domElement, AttrClosed, QString().setNum(static_cast<quint8>(det.getClosed())));
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth()));
|
2016-03-04 17:08:29 +01:00
|
|
|
doc->RemoveAllChildren(domElement);
|
2016-06-21 00:49:22 +02:00
|
|
|
|
|
|
|
QDomElement domData = doc->createElement(VAbstractPattern::TagData);
|
2016-06-23 22:35:32 +02:00
|
|
|
const VPatternPieceData& data = det.GetPatternPieceData();
|
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
|
|
|
|
doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName());
|
|
|
|
doc->SetAttribute(domData, AttrMx, data.GetPos().x());
|
|
|
|
doc->SetAttribute(domData, AttrMy, data.GetPos().y());
|
|
|
|
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth());
|
2016-06-27 17:18:43 +02:00
|
|
|
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
|
2016-06-23 22:35:32 +02:00
|
|
|
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
|
|
|
|
|
|
|
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
2016-06-21 00:49:22 +02:00
|
|
|
{
|
2016-06-23 22:35:32 +02:00
|
|
|
MaterialCutPlacement mcp = data.GetMCP(i);
|
2016-06-21 00:49:22 +02:00
|
|
|
QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial));
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber);
|
|
|
|
doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement));
|
|
|
|
domData.appendChild(domMCP);
|
|
|
|
}
|
|
|
|
domElement.appendChild(domData);
|
|
|
|
|
2014-10-05 22:25:07 +02:00
|
|
|
for (int i = 0; i < det.CountNode(); ++i)
|
2013-12-24 12:24:29 +01:00
|
|
|
{
|
2014-06-12 15:38:28 +02:00
|
|
|
AddNode(doc, domElement, det.at(i));
|
2013-12-24 12:24:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief itemChange handle detail change.
|
|
|
|
* @param change change
|
|
|
|
* @param value value
|
|
|
|
* @return new value.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
2016-01-15 13:56:33 +01:00
|
|
|
if (change == ItemPositionChange && scene())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-01-15 13:57:47 +01:00
|
|
|
// Each time we move something we call recalculation scene rect. In some cases this can cause moving
|
|
|
|
// objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move.
|
|
|
|
static bool changeFinished = true;
|
|
|
|
if (changeFinished)
|
|
|
|
{
|
|
|
|
changeFinished = false;
|
2016-01-15 13:56:33 +01:00
|
|
|
|
2016-01-15 13:57:47 +01:00
|
|
|
// value - this is new position.
|
|
|
|
const QPointF newPos = value.toPointF();
|
2014-01-12 20:23:44 +01:00
|
|
|
|
2016-05-20 14:20:08 +02:00
|
|
|
MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id);
|
2016-01-15 13:57:47 +01:00
|
|
|
connect(moveDet, &MoveDetail::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveDet);
|
2016-01-15 13:56:33 +01:00
|
|
|
|
2016-01-15 13:57:47 +01:00
|
|
|
const QList<QGraphicsView *> viewList = scene()->views();
|
|
|
|
if (not viewList.isEmpty())
|
2016-01-15 13:56:33 +01:00
|
|
|
{
|
2016-01-15 13:57:47 +01:00
|
|
|
if (QGraphicsView *view = viewList.at(0))
|
|
|
|
{
|
|
|
|
const int xmargin = 50;
|
|
|
|
const int ymargin = 50;
|
|
|
|
|
|
|
|
const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view);
|
|
|
|
const QRectF itemRect = mapToScene(boundingRect()|childrenBoundingRect()).boundingRect();
|
|
|
|
|
|
|
|
// If item's rect is bigger than view's rect ensureVisible works very unstable.
|
|
|
|
if (itemRect.height() + 2*ymargin < viewRect.height() &&
|
|
|
|
itemRect.width() + 2*xmargin < viewRect.width())
|
|
|
|
{
|
|
|
|
view->ensureVisible(itemRect, xmargin, ymargin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ensure visible only small rect around a cursor
|
|
|
|
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
|
|
|
|
SCASSERT(currentScene);
|
|
|
|
const QPointF cursorPosition = currentScene->getScenePos();
|
|
|
|
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
|
|
|
|
}
|
|
|
|
}
|
2016-01-15 13:56:33 +01:00
|
|
|
}
|
2016-01-15 13:57:47 +01:00
|
|
|
// Don't forget to update geometry, because first change never call full parse
|
|
|
|
RefreshGeometry();
|
|
|
|
changeFinished = true;
|
2016-01-15 13:56:33 +01:00
|
|
|
}
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2014-01-03 16:13:43 +01:00
|
|
|
|
|
|
|
if (change == QGraphicsItem::ItemSelectedChange)
|
|
|
|
{
|
|
|
|
if (value == true)
|
|
|
|
{
|
|
|
|
// do stuff if selected
|
|
|
|
this->setFocus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// do stuff if not selected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 17:04:18 +02:00
|
|
|
return VNoBrushScalePathItem::itemChange(change, value);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief keyReleaseEvent handle key release events.
|
|
|
|
* @param event key release event.
|
|
|
|
*/
|
2014-01-03 16:13:43 +01:00
|
|
|
void VToolDetail::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Delete:
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
DeleteTool();
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
|
|
|
break;
|
2014-01-03 16:13:43 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-08 17:04:18 +02:00
|
|
|
VNoBrushScalePathItem::keyReleaseEvent ( event );
|
2014-01-03 16:13:43 +01:00
|
|
|
}
|
|
|
|
|
2015-12-02 22:07:23 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolDetail::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2016-03-31 16:01:41 +02:00
|
|
|
// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
VNoBrushScalePathItem::mousePressEvent(event);
|
2016-05-24 11:43:30 +02:00
|
|
|
|
|
|
|
// Somehow clicking on notselectable object do not clean previous selections.
|
|
|
|
if (not (flags() & ItemIsSelectable) && scene())
|
|
|
|
{
|
|
|
|
scene()->clearSelection();
|
|
|
|
}
|
|
|
|
|
2015-12-02 22:07:23 +01:00
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 12:05:08 +01:00
|
|
|
|
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
|
|
|
{
|
|
|
|
emit ChoosedTool(id, SceneObject::Detail);
|
|
|
|
}
|
|
|
|
|
2016-03-31 16:01:41 +02:00
|
|
|
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
|
2015-12-02 22:07:23 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief mouseReleaseEvent handle mouse release events.
|
|
|
|
* @param event mouse release event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
2015-12-02 22:07:23 +01:00
|
|
|
//Disable cursor-arrow-closehand
|
|
|
|
RestoreOverrideCursor(cursorArrowCloseHand);
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2016-02-11 12:05:08 +01:00
|
|
|
VNoBrushScalePathItem::mouseReleaseEvent(event);
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
|
|
|
|
2015-12-02 20:33:42 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-12-06 17:20:37 +01:00
|
|
|
void VToolDetail::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
2015-12-20 20:55:27 +01:00
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
|
|
|
|
}
|
2015-12-06 17:20:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-12-02 20:33:42 +01:00
|
|
|
void VToolDetail::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
2015-12-20 20:55:27 +01:00
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
SetOverrideCursor(cursorArrowOpenHand, 1, 1);
|
|
|
|
}
|
2015-12-02 20:33:42 +01:00
|
|
|
}
|
|
|
|
|
2016-06-18 16:00:01 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-12-02 20:33:42 +01:00
|
|
|
void VToolDetail::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
//Disable cursor-arrow-openhand
|
2015-12-20 20:55:27 +01:00
|
|
|
if (flags() & QGraphicsItem::ItemIsMovable)
|
|
|
|
{
|
|
|
|
RestoreOverrideCursor(cursorArrowOpenHand);
|
|
|
|
}
|
2015-12-02 20:33:42 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief contextMenuEvent handle context menu events.
|
|
|
|
* @param event context menu event.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
QMenu menu;
|
2014-10-29 12:31:02 +01:00
|
|
|
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
|
|
|
|
QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (_referens > 1)
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
actionRemove->setEnabled(false);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
actionRemove->setEnabled(true);
|
|
|
|
}
|
|
|
|
QAction *selectedAction = menu.exec(event->screenPos());
|
2013-11-04 21:35:15 +01:00
|
|
|
if (selectedAction == actionOption)
|
|
|
|
{
|
2014-07-29 14:19:11 +02:00
|
|
|
dialog = new DialogDetail(getData(), id, qApp->getMainWindow());
|
2014-07-04 13:55:36 +02:00
|
|
|
dialog->setModal(true);
|
2013-10-25 13:10:45 +02:00
|
|
|
connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
|
2014-07-15 16:42:41 +02:00
|
|
|
dialog, &DialogTool::ChosenObject);
|
2014-06-11 18:38:09 +02:00
|
|
|
connect(dialog, &DialogTool::DialogClosed, this, &VToolDetail::FullUpdateFromGuiOk);
|
2013-10-25 13:10:45 +02:00
|
|
|
setDialog();
|
2014-02-06 14:57:23 +01:00
|
|
|
dialog->show();
|
2013-10-25 13:10:45 +02:00
|
|
|
}
|
2016-06-18 16:00:01 +02:00
|
|
|
else if (selectedAction == actionRemove)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
DeleteTool();
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
2014-10-04 21:12:46 +02:00
|
|
|
return; //Leave this method immediately after call!!!
|
2013-09-30 18:29:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 17:57:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief UpdateLabel updates the text label, making it just big enough for the text to fit it
|
|
|
|
*/
|
|
|
|
void VToolDetail::UpdateLabel()
|
|
|
|
{
|
|
|
|
const VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
|
2016-06-27 20:51:29 +02:00
|
|
|
qDebug() << "Update label";
|
2016-06-24 17:57:08 +02:00
|
|
|
const VPatternPieceData& data = detail.GetPatternPieceData();
|
|
|
|
if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0)
|
|
|
|
{
|
2016-06-27 17:18:43 +02:00
|
|
|
dataLabel->Reset();
|
|
|
|
|
2016-06-25 17:19:44 +02:00
|
|
|
QString qsText = "Cut %1 of %2%3";
|
2016-06-24 17:57:08 +02:00
|
|
|
QStringList qslPlace;
|
|
|
|
qslPlace << "" << " on Fold";
|
|
|
|
QFont fnt = qApp->font();
|
|
|
|
fnt.setPixelSize(data.GetFontSize());
|
2016-06-25 17:19:44 +02:00
|
|
|
dataLabel->SetFont(fnt);
|
2016-06-27 17:18:43 +02:00
|
|
|
dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight());
|
2016-06-25 17:19:44 +02:00
|
|
|
dataLabel->Clear();
|
|
|
|
TextLine tl;
|
|
|
|
// letter
|
|
|
|
tl.m_qsText = data.GetLetter();
|
|
|
|
tl.m_eAlign = Qt::AlignCenter;
|
|
|
|
tl.m_eFontWeight = QFont::Bold;
|
2016-06-26 14:21:06 +02:00
|
|
|
tl.m_eStyle = QFont::StyleNormal;
|
|
|
|
tl.m_iFontSize = 6;
|
2016-06-25 17:19:44 +02:00
|
|
|
dataLabel->AddLine(tl);
|
|
|
|
tl.m_qsText = data.GetName();
|
|
|
|
tl.m_eAlign = Qt::AlignCenter;
|
|
|
|
tl.m_eFontWeight = QFont::DemiBold;
|
|
|
|
tl.m_iFontSize = 2;
|
|
|
|
dataLabel->AddLine(tl);
|
|
|
|
// MCP
|
|
|
|
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
|
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_iFontSize = 0;
|
|
|
|
for (int i = 0; i < data.GetMCPCount(); ++i) {
|
2016-06-24 17:57:08 +02:00
|
|
|
MaterialCutPlacement mcp = data.GetMCP(i);
|
2016-06-25 17:19:44 +02:00
|
|
|
tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]);
|
|
|
|
dataLabel->AddLine(tl);
|
2016-06-24 17:57:08 +02:00
|
|
|
}
|
2016-06-25 17:19:44 +02:00
|
|
|
|
2016-06-24 17:57:08 +02:00
|
|
|
dataLabel->setPos(data.GetPos());
|
2016-06-27 17:18:43 +02:00
|
|
|
dataLabel->Update();
|
2016-06-24 17:57:08 +02:00
|
|
|
dataLabel->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dataLabel->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 22:35:32 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2016-06-27 01:17:27 +02:00
|
|
|
* @brief UpdatePatternInfo updates the pattern info label
|
2016-06-23 22:35:32 +02:00
|
|
|
*/
|
2016-06-27 01:17:27 +02:00
|
|
|
void VToolDetail::UpdatePatternInfo()
|
|
|
|
{
|
2016-06-27 17:18:43 +02:00
|
|
|
patternInfo->Reset();
|
2016-06-27 01:17:27 +02:00
|
|
|
QFont fnt = qApp->font();
|
|
|
|
int iFS = doc->GetFontSize();
|
|
|
|
if (iFS < MIN_FONT_SIZE)
|
|
|
|
{
|
|
|
|
iFS = MIN_FONT_SIZE;
|
|
|
|
}
|
|
|
|
fnt.setPixelSize(iFS);
|
|
|
|
patternInfo->SetFont(fnt);
|
2016-06-27 17:18:43 +02:00
|
|
|
QSizeF sz = doc->GetLabelSize();
|
|
|
|
patternInfo->SetSize(sz.width(), sz.height());
|
2016-06-27 01:17:27 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
patternInfo->setPos(doc->GetLabelPosition());
|
2016-06-27 17:18:43 +02:00
|
|
|
patternInfo->Update();
|
2016-06-27 01:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SaveMoveDetail saves the move detail operation to the undo stack
|
|
|
|
*/
|
|
|
|
void VToolDetail::SaveMoveDetail(QPointF ptPos)
|
2016-06-23 22:35:32 +02:00
|
|
|
{
|
|
|
|
VDetail oldDet = VAbstractTool::data.GetDetail(id);
|
|
|
|
VDetail newDet = oldDet;
|
|
|
|
newDet.GetPatternPieceData().SetPos(ptPos);
|
|
|
|
SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
|
|
|
|
moveCommand->setText(tr("move pattern piece label"));
|
|
|
|
connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(moveCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2016-06-27 01:17:27 +02:00
|
|
|
* @brief SaveResizeDetail saves the resize detail label operation to the undo stack
|
2016-06-23 22:35:32 +02:00
|
|
|
*/
|
2016-06-27 01:17:27 +02:00
|
|
|
void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize)
|
2016-06-23 22:35:32 +02:00
|
|
|
{
|
|
|
|
VDetail oldDet = VAbstractTool::data.GetDetail(id);
|
|
|
|
VDetail newDet = oldDet;
|
|
|
|
newDet.GetPatternPieceData().SetLabelWidth(dLabelW);
|
2016-06-27 17:18:43 +02:00
|
|
|
newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height());
|
2016-06-23 22:35:32 +02:00
|
|
|
newDet.GetPatternPieceData().SetFontSize(iFontSize);
|
|
|
|
SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
|
|
|
|
resizeCommand->setText(tr("resize pattern piece label"));
|
|
|
|
connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
|
|
|
qApp->getUndoStack()->push(resizeCommand);
|
|
|
|
}
|
|
|
|
|
2016-06-27 01:17:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
{
|
2016-06-27 17:18:43 +02:00
|
|
|
doc->SetLabelSize(QSizeF(dLabelW, patternInfo->boundingRect().height()));
|
2016-06-27 01:17:27 +02:00
|
|
|
doc->SetFontSize(iFontSize);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief AddNode add node to the file.
|
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param node node of detail.
|
|
|
|
*/
|
2015-06-16 10:30:25 +02:00
|
|
|
void VToolDetail::AddNode(VAbstractPattern *doc, QDomElement &domElement, const VNodeDetail &node)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-10-29 14:45:07 +01:00
|
|
|
QDomElement nod = doc->createElement(TagNode);
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(nod, AttrIdObject, node.getId());
|
2014-03-19 19:27:11 +01:00
|
|
|
doc->SetAttribute(nod, AttrMx, qApp->fromPixel(node.getMx()));
|
|
|
|
doc->SetAttribute(nod, AttrMy, qApp->fromPixel(node.getMy()));
|
2014-12-17 13:56:14 +01:00
|
|
|
|
|
|
|
if (node.getTypeTool() != Tool::NodePoint)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(nod, AttrReverse, static_cast<quint8>(node.getReverse()));
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
if (node.getTypeNode() == NodeDetail::Contour)
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(nod, AttrNodeType, NodeTypeContour);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
doc->SetAttribute(nod, AttrNodeType, NodeTypeModeling);
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
switch (node.getTypeTool())
|
|
|
|
{
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeArc):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodeArc);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodePoint):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodePoint);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSpline):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodeSpline);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2014-06-12 09:22:29 +02:00
|
|
|
case (Tool::NodeSplinePath):
|
2014-02-25 19:03:17 +01:00
|
|
|
doc->SetAttribute(nod, AttrType, NodeSplinePath);
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-28 14:11:46 +01:00
|
|
|
qDebug()<<"May be wrong tool type!!! Ignoring."<<Q_FUNC_INFO;
|
2013-11-04 21:35:15 +01:00
|
|
|
break;
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
|
|
|
domElement.appendChild(nod);
|
|
|
|
}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VToolDetail::getTagName() const
|
|
|
|
{
|
2016-05-16 19:59:04 +02:00
|
|
|
return VAbstractPattern::TagDetail;
|
2014-08-30 21:58:31 +02:00
|
|
|
}
|
|
|
|
|
2014-09-03 15:52:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolDetail::ShowVisualization(bool show)
|
|
|
|
{
|
2014-09-11 18:52:02 +02:00
|
|
|
Q_UNUSED(show)
|
2014-09-03 15:52:16 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 11:03:34 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolDetail::GroupVisibility(quint32 object, bool visible)
|
|
|
|
{
|
|
|
|
Q_UNUSED(object);
|
|
|
|
Q_UNUSED(visible);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-14 08:42:01 +02:00
|
|
|
/**
|
|
|
|
* @brief RefreshGeometry refresh item on scene.
|
|
|
|
*/
|
2013-11-04 21:35:15 +01:00
|
|
|
void VToolDetail::RefreshGeometry()
|
|
|
|
{
|
2014-06-16 09:52:55 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
2016-01-10 14:31:43 +01:00
|
|
|
|
|
|
|
const VDetail detail = VAbstractTool::data.GetDetail(id);
|
|
|
|
QPainterPath mainPath = detail.ContourPath(this->getData());
|
|
|
|
this->setPath(mainPath);
|
2014-06-13 12:29:23 +02:00
|
|
|
this->setPos(detail.getMx(), detail.getMy());
|
2016-01-10 14:31:43 +01:00
|
|
|
|
|
|
|
if (detail.getSeamAllowance())
|
|
|
|
{
|
|
|
|
mainPath.addPath(detail.SeamAllowancePath(this->getData()));
|
|
|
|
mainPath.setFillRule(Qt::OddEvenFill);
|
|
|
|
seamAllowance->setPath(mainPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
seamAllowance->setPath(QPainterPath());
|
|
|
|
}
|
|
|
|
|
2014-06-13 12:29:23 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
2013-08-28 10:55:11 +02:00
|
|
|
}
|
2013-10-29 16:01:56 +01:00
|
|
|
|
2014-12-15 15:25:40 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-16 14:14:46 +02:00
|
|
|
void VToolDetail::DeleteTool(bool ask)
|
|
|
|
{
|
2015-12-26 14:08:41 +01:00
|
|
|
DeleteDetail *delDet = new DeleteDetail(doc, id, VAbstractTool::data.GetDetail(id));
|
2014-06-16 14:14:46 +02:00
|
|
|
if (ask)
|
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
if (ConfirmDeletion() == QMessageBox::No)
|
2014-06-16 14:14:46 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-06-26 12:41:59 +02:00
|
|
|
/* If UnionDetails tool delete detail no need emit FullParsing.*/
|
2015-06-18 19:23:24 +02:00
|
|
|
connect(delDet, &DeleteDetail::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
|
2014-06-16 14:14:46 +02:00
|
|
|
}
|
|
|
|
qApp->getUndoStack()->push(delDet);
|
2015-11-02 17:25:29 +01:00
|
|
|
|
|
|
|
// Throw exception, this will help prevent case when we forget to immediately quit function.
|
|
|
|
VExceptionToolWasDeleted e("Tool was used after deleting.");
|
|
|
|
throw e;
|
2014-06-16 14:14:46 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-10-29 16:01:56 +01:00
|
|
|
template <typename Tool>
|
2014-01-27 16:48:11 +01:00
|
|
|
//cppcheck-suppress unusedFunction
|
2016-06-17 15:13:49 +02:00
|
|
|
Tool* VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:40:24 +01:00
|
|
|
QHash<quint32, VDataTool*>* tools = doc->getTools();
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(tools != nullptr);
|
2013-10-29 16:01:56 +01:00
|
|
|
Tool *tool = qobject_cast<Tool*>(tools->value(node.getId()));
|
2014-06-03 14:15:17 +02:00
|
|
|
SCASSERT(tool != nullptr);
|
2013-10-29 16:01:56 +01:00
|
|
|
connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
|
|
tool->setParentItem(this);
|
2016-01-07 17:43:08 +01:00
|
|
|
tool->SetParentType(ParentType::Item);
|
2014-06-16 19:08:23 +02:00
|
|
|
doc->IncrementReferens(node.getId());
|
2016-06-17 15:13:49 +02:00
|
|
|
return tool;
|
2013-10-29 16:01:56 +01:00
|
|
|
}
|
2015-12-20 20:53:59 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolDetail::EnableToolMove(bool move)
|
|
|
|
{
|
2016-03-31 16:01:41 +02:00
|
|
|
setFlag(QGraphicsItem::ItemIsMovable, move);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolDetail::AllowHover(bool enabled)
|
|
|
|
{
|
|
|
|
setAcceptHoverEvents(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolDetail::AllowSelecting(bool enabled)
|
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemIsSelectable, enabled);
|
2015-12-20 20:53:59 +01:00
|
|
|
}
|
2016-06-23 00:59:45 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-06-27 11:06:51 +02:00
|
|
|
void VToolDetail::ResetChildren()
|
2016-06-23 00:59:45 +02:00
|
|
|
{
|
|
|
|
dataLabel->Reset();
|
2016-06-27 11:06:51 +02:00
|
|
|
patternInfo->Reset();
|
2016-06-23 00:59:45 +02:00
|
|
|
}
|
2016-06-25 17:19:44 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolDetail::UpdateAll()
|
|
|
|
{
|
|
|
|
sceneDetails->update();
|
|
|
|
update();
|
|
|
|
}
|