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 vdrawtool.cpp
|
2013-11-15 13:41:26 +01:00
|
|
|
** @author Roman Telezhinsky <dismine@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.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <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-09-10 14:29:06 +02:00
|
|
|
#include "vdrawtool.h"
|
|
|
|
|
2013-10-16 11:17:34 +02:00
|
|
|
qreal VDrawTool::factor = 1;
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
VDrawTool::VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent)
|
|
|
|
:VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false), ignoreFullUpdate(false),
|
|
|
|
nameActivDraw(doc->GetNameActivDraw())
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
connect(this->doc, &VDomDocument::ChangedActivDraw, this, &VDrawTool::ChangedActivDraw);
|
|
|
|
connect(this->doc, &VDomDocument::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw);
|
|
|
|
connect(this->doc, &VDomDocument::ShowTool, this, &VDrawTool::ShowTool);
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:11:12 +01:00
|
|
|
void VDrawTool::AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
qint64 cursor = doc->getCursor();
|
|
|
|
QVector<VToolRecord> *history = doc->getHistory();
|
2013-11-04 21:35:15 +01:00
|
|
|
if (cursor <= 0)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
history->append(VToolRecord(id, toolType, doc->GetNameActivDraw()));
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
qint32 index = 0;
|
2013-11-04 21:35:15 +01:00
|
|
|
for (qint32 i = 0; i<history->size(); ++i)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
VToolRecord rec = history->at(i);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (rec.getId() == cursor)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
history->insert(index+1, VToolRecord(id, toolType, doc->GetNameActivDraw()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VDrawTool::ShowTool(qint64 id, Qt::GlobalColor color, bool enable)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
Q_UNUSED(id);
|
|
|
|
Q_UNUSED(color);
|
|
|
|
Q_UNUSED(enable);
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:11:12 +01:00
|
|
|
void VDrawTool::ChangedActivDraw(const QString &newName)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (nameActivDraw == newName)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
ignoreContextMenuEvent = false;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
ignoreContextMenuEvent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:11:12 +01:00
|
|
|
void VDrawTool::ChangedNameDraw(const QString &oldName, const QString &newName)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
|
|
|
if (nameActivDraw == oldName)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
nameActivDraw = newName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VDrawTool::SetFactor(qreal factor)
|
|
|
|
{
|
|
|
|
if (factor <= 2 && factor >= 0.5)
|
|
|
|
{
|
2013-10-16 11:17:34 +02:00
|
|
|
this->factor = factor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VDrawTool::AddToCalculation(const QDomElement &domElement)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
QDomElement calcElement;
|
|
|
|
bool ok = doc->GetActivCalculationElement(calcElement);
|
2013-11-04 21:35:15 +01:00
|
|
|
if (ok)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
qint64 id = doc->getCursor();
|
2013-11-04 21:35:15 +01:00
|
|
|
if (id <= 0)
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
calcElement.appendChild(domElement);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 14:29:06 +02:00
|
|
|
QDomElement refElement = doc->elementById(QString().setNum(doc->getCursor()));
|
2013-11-04 21:35:15 +01:00
|
|
|
if (refElement.isElement())
|
|
|
|
{
|
|
|
|
calcElement.insertAfter(domElement, refElement);
|
2013-09-10 14:29:06 +02:00
|
|
|
doc->setCursor(0);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-27 14:50:00 +01:00
|
|
|
qCritical()<<tr("Can not find the element after which you want to insert.")<< Q_FUNC_INFO;
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-29 14:45:07 +01:00
|
|
|
qCritical()<<tr("Can't find tag Calculation")<< Q_FUNC_INFO;
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
|
|
|
emit toolhaveChange();
|
|
|
|
}
|