Visualization for VToolAlongLine.
--HG-- branch : develop
This commit is contained in:
parent
ba7f8f0507
commit
36e90eb86b
|
@ -28,6 +28,9 @@
|
|||
|
||||
#include "dialogalongline.h"
|
||||
#include "ui_dialogalongline.h"
|
||||
#include "../../visualization/vistoolalongline.h"
|
||||
#include "../../tools/vabstracttool.h"
|
||||
#include "../../widgets/vmaingraphicsscene.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
|
@ -39,7 +42,7 @@
|
|||
*/
|
||||
DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
|
||||
:DialogTool(data, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), typeLine(QString()),
|
||||
formula(QString()), firstPointId(0), secondPointId(0), formulaBaseHeight(0)
|
||||
formula(QString()), firstPointId(0), secondPointId(0), formulaBaseHeight(0), line(nullptr), prepare(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
InitVariables(ui);
|
||||
|
@ -67,6 +70,8 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
|
|||
this, &DialogAlongLine::PointChanged);
|
||||
connect(ui->comboBoxSecondPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
||||
this, &DialogAlongLine::PointChanged);
|
||||
|
||||
line = new VisToolAlongLine(data);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -94,6 +99,18 @@ void DialogAlongLine::PointChanged()
|
|||
CheckState();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogAlongLine::ShowVisualization()
|
||||
{
|
||||
if (prepare == false)
|
||||
{
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolAlongLine::SetFactor);
|
||||
scene->addItem(line);
|
||||
line->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogAlongLine::DeployFormulaTextEdit()
|
||||
{
|
||||
|
@ -103,6 +120,7 @@ void DialogAlongLine::DeployFormulaTextEdit()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogAlongLine::~DialogAlongLine()
|
||||
{
|
||||
delete line;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
@ -114,25 +132,39 @@ DialogAlongLine::~DialogAlongLine()
|
|||
*/
|
||||
void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
|
||||
{
|
||||
if (type == SceneObject::Point)
|
||||
if (prepare == false)// After first choose we ignore all objects
|
||||
{
|
||||
if (number == 0)
|
||||
if (type == SceneObject::Point)
|
||||
{
|
||||
if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
|
||||
if (number == 0)
|
||||
{
|
||||
number++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (number == 1)
|
||||
{
|
||||
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
|
||||
{
|
||||
number = 0;
|
||||
if (isInitialized == false)
|
||||
if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line")))
|
||||
{
|
||||
this->setModal(true);
|
||||
this->show();
|
||||
number++;
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
SCASSERT(scene != nullptr);
|
||||
line->VisualMode(id, scene->getScenePos());
|
||||
scene->addItem(line);
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolAlongLine::SetFactor);
|
||||
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolAlongLine::MousePos);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (number == 1)
|
||||
{
|
||||
if (ChoosedPoint(id, ui->comboBoxSecondPoint, ""))
|
||||
{
|
||||
number = 0;
|
||||
if (isInitialized == false)
|
||||
{
|
||||
line->setPoint2Id(id);
|
||||
line->setMainColor(Qt::red);
|
||||
line->RefreshGeometry();
|
||||
|
||||
prepare = true;
|
||||
this->setModal(true);
|
||||
this->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +196,12 @@ void DialogAlongLine::SaveData()
|
|||
formula.replace("\n", " ");
|
||||
firstPointId = getCurrentObjectId(ui->comboBoxFirstPoint);
|
||||
secondPointId = getCurrentObjectId(ui->comboBoxSecondPoint);
|
||||
|
||||
line->setPoint1Id(firstPointId);
|
||||
line->setPoint2Id(secondPointId);
|
||||
line->setLength(formula);
|
||||
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
|
||||
line->RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -175,6 +213,7 @@ void DialogAlongLine::SaveData()
|
|||
void DialogAlongLine::setSecondPointId(const quint32 &value, const quint32 &id)
|
||||
{
|
||||
setCurrentPointId(ui->comboBoxSecondPoint, secondPointId, value, id);
|
||||
line->setPoint2Id(value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -186,6 +225,7 @@ void DialogAlongLine::setSecondPointId(const quint32 &value, const quint32 &id)
|
|||
void DialogAlongLine::setFirstPointId(const quint32 &value, const quint32 &id)
|
||||
{
|
||||
setCurrentPointId(ui->comboBoxFirstPoint, firstPointId, value, id);
|
||||
line->setPoint1Id(value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -202,6 +242,7 @@ void DialogAlongLine::setFormula(const QString &value)
|
|||
this->DeployFormulaTextEdit();
|
||||
}
|
||||
ui->plainTextEditFormula->setPlainText(formula);
|
||||
line->setLength(formula);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -213,6 +254,7 @@ void DialogAlongLine::setTypeLine(const QString &value)
|
|||
{
|
||||
typeLine = value;
|
||||
SetupTypeLine(ui->comboBoxLineType, value);
|
||||
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include "dialogtool.h"
|
||||
|
||||
class VisToolAlongLine;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class DialogAlongLine;
|
||||
|
@ -75,6 +77,8 @@ public slots:
|
|||
*/
|
||||
void FormulaTextChanged();
|
||||
void PointChanged();
|
||||
protected:
|
||||
virtual void ShowVisualization();
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogAlongLine)
|
||||
|
||||
|
@ -101,6 +105,9 @@ private:
|
|||
|
||||
/** @brief formulaBaseHeight base height defined by dialogui */
|
||||
int formulaBaseHeight;
|
||||
VisToolAlongLine *line;
|
||||
/** @brief prepare show if we prepare show dialog after finish working with visual part of tool*/
|
||||
bool prepare;
|
||||
|
||||
/**
|
||||
* @brief SaveData Put dialog data in local variables
|
||||
|
|
|
@ -151,7 +151,7 @@ void DialogEndLine::setFormula(const QString &value)
|
|||
this->DeployFormulaTextEdit();
|
||||
}
|
||||
ui->plainTextEditFormula->setPlainText(formula);
|
||||
line->setLength(data, formula);
|
||||
line->setLength(formula);
|
||||
//QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
||||
//cursor.insertText(value);
|
||||
//ui->plainTextEditFormula->setCursor(cursor);
|
||||
|
@ -207,7 +207,7 @@ void DialogEndLine::ShowDialog(bool click)
|
|||
}
|
||||
this->setModal(true);
|
||||
this->setAngle(line->Angle());//Show in dialog angle what user choose
|
||||
line->setColor(Qt::red);//Now linw will be red
|
||||
line->setMainColor(Qt::red);//Now linw will be red
|
||||
emit ToolTip("");
|
||||
this->show();
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ void DialogEndLine::SaveData()
|
|||
basePointId = getCurrentObjectId(ui->comboBoxBasePoint);
|
||||
|
||||
line->setPoint1Id(basePointId);
|
||||
line->setLength(data, formula);
|
||||
line->setLength(formula);
|
||||
line->setAngle(angle);
|
||||
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
|
||||
line->RefreshGeometry();
|
||||
|
|
|
@ -567,7 +567,6 @@ quint32 DialogTool::getCurrentObjectId(QComboBox *box) const
|
|||
{
|
||||
SCASSERT(box != nullptr);
|
||||
qint32 index = box->currentIndex();
|
||||
SCASSERT(index != -1);
|
||||
if (index != -1)
|
||||
{
|
||||
return qvariant_cast<quint32>(box->itemData(index));
|
||||
|
|
|
@ -43,7 +43,8 @@ const QString VToolSpline::ToolType = QStringLiteral("simple");
|
|||
* @param parent parent object.
|
||||
*/
|
||||
VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
|
||||
QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent)
|
||||
QGraphicsItem *parent)
|
||||
:VAbstractSpline(doc, data, id, parent)
|
||||
{
|
||||
const VSpline *spl = data->GeometricObject<const VSpline *>(id);
|
||||
QPainterPath path;
|
||||
|
|
|
@ -42,7 +42,8 @@ const QString VToolSplinePath::ToolType = QStringLiteral("path");
|
|||
* @param parent parent object.
|
||||
*/
|
||||
VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation,
|
||||
QGraphicsItem *parent) :VAbstractSpline(doc, data, id, parent)
|
||||
QGraphicsItem *parent)
|
||||
:VAbstractSpline(doc, data, id, parent)
|
||||
{
|
||||
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(id);
|
||||
QPainterPath path;
|
||||
|
|
|
@ -30,12 +30,15 @@
|
|||
#include "../container/vcontainer.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
#include "../tools/drawTools/vdrawtool.h"
|
||||
#include "../container/calculator.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
|
||||
:QObject(), QGraphicsLineItem(parent), data(data), factor(VDrawTool::factor), scenePos(QPointF()),
|
||||
color(Qt::red), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString())
|
||||
{}
|
||||
mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString())
|
||||
{
|
||||
this->setZValue(1);// Show on top real tool
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisLine::~VisLine()
|
||||
|
@ -52,7 +55,7 @@ void VisLine::SetFactor(qreal factor)
|
|||
void VisLine::setLineStyle(const Qt::PenStyle &value)
|
||||
{
|
||||
lineStyle = value;
|
||||
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -60,14 +63,59 @@ void VisLine::MousePos(const QPointF &scenePos)
|
|||
{
|
||||
this->scenePos = scenePos;
|
||||
RefreshGeometry();
|
||||
emit ToolTip(toolTip);
|
||||
if (toolTip.isEmpty() == false)
|
||||
{
|
||||
emit ToolTip(toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::setColor(const QColor &value)
|
||||
QRectF VisLine::PointRect()
|
||||
{
|
||||
color = value;
|
||||
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
const qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm);
|
||||
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
|
||||
rec.translate(-rec.center().x(), -rec.center().y());
|
||||
return rec;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VisLine::FindLength(const QString &expression)
|
||||
{
|
||||
qreal length = 0;
|
||||
if (expression.isEmpty())
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// Replace line return with spaces for calc if exist
|
||||
QString formula = expression;
|
||||
formula.replace("\n", " ");
|
||||
formula = qApp->FormulaFromUser(formula);
|
||||
Calculator *cal = new Calculator(data);
|
||||
length = cal->EvalFormula(formula);
|
||||
delete cal;
|
||||
}
|
||||
catch (qmu::QmuParserError &e)
|
||||
{
|
||||
length = 0;
|
||||
qDebug() << "\nMath parser error:\n"
|
||||
<< "--------------------------------------\n"
|
||||
<< "Message: " << e.GetMsg() << "\n"
|
||||
<< "Expression: " << e.GetExpr() << "\n"
|
||||
<< "--------------------------------------";
|
||||
}
|
||||
}
|
||||
return qApp->toPixel(length);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::setMainColor(const QColor &value)
|
||||
{
|
||||
mainColor = value;
|
||||
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -79,7 +127,7 @@ void VisLine::setScenePos(const QPointF &value)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
|
||||
{
|
||||
this->color = Qt::black;
|
||||
this->mainColor = Qt::black;
|
||||
this->point1Id = pointId;
|
||||
this->scenePos = scenePos;
|
||||
RefreshGeometry();
|
||||
|
|
|
@ -46,8 +46,8 @@ public:
|
|||
void setLineStyle(const Qt::PenStyle &value);
|
||||
virtual void RefreshGeometry()=0;
|
||||
void setScenePos(const QPointF &value);
|
||||
void VisualMode(const quint32 &pointId, const QPointF &scenePos);
|
||||
void setColor(const QColor &value);
|
||||
virtual void VisualMode(const quint32 &pointId, const QPointF &scenePos);
|
||||
void setMainColor(const QColor &value);
|
||||
signals:
|
||||
void ToolTip(const QString &toolTip);
|
||||
public slots:
|
||||
|
@ -57,10 +57,13 @@ protected:
|
|||
const VContainer *data;
|
||||
qreal factor;
|
||||
QPointF scenePos;
|
||||
QColor color;
|
||||
QColor mainColor;
|
||||
QColor supportColor;
|
||||
Qt::PenStyle lineStyle;
|
||||
quint32 point1Id;
|
||||
QString toolTip;
|
||||
QRectF PointRect();
|
||||
qreal FindLength(const QString &expression);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisLine)
|
||||
};
|
||||
|
|
135
src/app/visualization/vistoolalongline.cpp
Normal file
135
src/app/visualization/vistoolalongline.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolalongline.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 24 7, 2014
|
||||
**
|
||||
** @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) 2014 Valentina project
|
||||
** <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 "vistoolalongline.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../geometry/vpointf.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent)
|
||||
: VisLine(data, parent), point2Id(0), point(nullptr), lineP1(nullptr), lineP2(nullptr), line(nullptr), length(0)
|
||||
{
|
||||
this->mainColor = Qt::red;
|
||||
this->setZValue(2);// Show on top real tool
|
||||
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
|
||||
line = new QGraphicsLineItem(this);
|
||||
line->setVisible(false);
|
||||
line->setPen(QPen(supportColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
line->setZValue(1);
|
||||
line->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolAlongLine::~VisToolAlongLine()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::setPoint2Id(const quint32 &value)
|
||||
{
|
||||
point2Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::setLength(const QString &expression)
|
||||
{
|
||||
length = FindLength(expression);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsEllipseItem *VisToolAlongLine::InitPoint(const QColor &color)
|
||||
{
|
||||
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(this);
|
||||
point->setVisible(false);
|
||||
point->setZValue(1);
|
||||
point->setBrush(QBrush(Qt::NoBrush));
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
point->setRect(PointRect());
|
||||
return point;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style)
|
||||
{
|
||||
SCASSERT (lineItem != nullptr);
|
||||
|
||||
lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style));
|
||||
lineItem->setLine(line);
|
||||
lineItem->setVisible(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color)
|
||||
{
|
||||
SCASSERT (point != nullptr);
|
||||
|
||||
point->setPos(pos);
|
||||
point->setVisible(true);
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::RefreshGeometry()
|
||||
{
|
||||
if (point1Id > 0)
|
||||
{
|
||||
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
|
||||
DrawPoint(lineP1, first->toQPointF(), supportColor);
|
||||
|
||||
if (point2Id <= 0)
|
||||
{
|
||||
DrawLine(line, QLineF(first->toQPointF(), scenePos), supportColor);
|
||||
}
|
||||
|
||||
if (point2Id > 0)
|
||||
{
|
||||
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
|
||||
DrawPoint(lineP2, second->toQPointF(), supportColor);
|
||||
|
||||
DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), supportColor);
|
||||
|
||||
if (qFuzzyCompare(1 + length, 1 + 0) == false)
|
||||
{
|
||||
QLineF mainLine = QLineF();
|
||||
mainLine.setP1(first->toQPointF());
|
||||
mainLine.setAngle(line->line().angle());
|
||||
mainLine.setLength(length);
|
||||
|
||||
DrawLine(this, mainLine, mainColor, lineStyle);
|
||||
|
||||
DrawPoint(point, mainLine.p2(), mainColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
src/app/visualization/vistoolalongline.h
Normal file
60
src/app/visualization/vistoolalongline.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolalongline.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 24 7, 2014
|
||||
**
|
||||
** @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) 2014 Valentina project
|
||||
** <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/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef VISTOOLALONGLINE_H
|
||||
#define VISTOOLALONGLINE_H
|
||||
|
||||
#include "visline.h"
|
||||
|
||||
class VContainer;
|
||||
|
||||
class VisToolAlongLine :public VisLine
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VisToolAlongLine(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
virtual ~VisToolAlongLine();
|
||||
|
||||
virtual void RefreshGeometry();
|
||||
void setPoint2Id(const quint32 &value);
|
||||
void setLength(const QString &expression);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisToolAlongLine)
|
||||
quint32 point2Id;
|
||||
QGraphicsEllipseItem *point;
|
||||
QGraphicsEllipseItem *lineP1;
|
||||
QGraphicsEllipseItem *lineP2;
|
||||
QGraphicsLineItem *line;
|
||||
qreal length;
|
||||
QGraphicsEllipseItem *InitPoint(const QColor &mainColor);
|
||||
void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color);
|
||||
};
|
||||
|
||||
#endif // VISTOOLALONGLINE_H
|
|
@ -31,7 +31,6 @@
|
|||
#include "../container/vcontainer.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
#include "../tools/vabstracttool.h"
|
||||
#include "../container/calculator.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QtMath>
|
||||
|
@ -40,19 +39,14 @@
|
|||
VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent)
|
||||
: VisLine(data, parent), length(0), angle(0), point(nullptr)
|
||||
{
|
||||
this->color = Qt::red;
|
||||
this->setZValue(1);// Show on top real tool
|
||||
this->mainColor = Qt::red;
|
||||
|
||||
point = new QGraphicsEllipseItem(this);
|
||||
point->setVisible(false);
|
||||
point->setZValue(1);
|
||||
point->setBrush(QBrush(Qt::NoBrush));
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
|
||||
const qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm);
|
||||
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
|
||||
rec.translate(-rec.center().x(), -rec.center().y());
|
||||
point->setRect(rec);
|
||||
point->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
point->setRect(PointRect());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -63,7 +57,7 @@ VisToolEndLine::~VisToolEndLine()
|
|||
void VisToolEndLine::RefreshGeometry()
|
||||
{
|
||||
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
|
||||
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
QLineF line;
|
||||
if (qFuzzyCompare(1 + length, 1 + 0))
|
||||
{
|
||||
|
@ -91,12 +85,12 @@ void VisToolEndLine::RefreshGeometry()
|
|||
{
|
||||
line = QLineF();
|
||||
line.setP1(first->toQPointF());
|
||||
line.setLength(qApp->toPixel(length));
|
||||
line.setLength(length);
|
||||
line.setAngle(angle);
|
||||
|
||||
point->setPos(line.p2());
|
||||
point->setVisible(true);
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
point->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
}
|
||||
this->setLine(line);
|
||||
toolTip = QString(tr("<b>Point at distance and angle</b>: angle = %1°; <b>Shift</b> - sticking angle, "
|
||||
|
@ -106,7 +100,7 @@ void VisToolEndLine::RefreshGeometry()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolEndLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
|
||||
{
|
||||
this->color = Qt::black;
|
||||
this->mainColor = Qt::black;
|
||||
this->point1Id = pointId;
|
||||
this->scenePos = scenePos;
|
||||
RefreshGeometry();
|
||||
|
@ -158,34 +152,7 @@ void VisToolEndLine::setAngle(const qreal &value)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolEndLine::setLength(const VContainer *data, const QString &expression)
|
||||
void VisToolEndLine::setLength(const QString &expression)
|
||||
{
|
||||
SCASSERT(data != nullptr);
|
||||
|
||||
if (expression.isEmpty())
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// Replace line return with spaces for calc if exist
|
||||
QString formula = expression;
|
||||
formula.replace("\n", " ");
|
||||
formula = qApp->FormulaFromUser(formula);
|
||||
Calculator *cal = new Calculator(data);
|
||||
length = cal->EvalFormula(formula);
|
||||
delete cal;
|
||||
}
|
||||
catch (qmu::QmuParserError &e)
|
||||
{
|
||||
length = 0;
|
||||
qDebug() << "\nMath parser error:\n"
|
||||
<< "--------------------------------------\n"
|
||||
<< "Message: " << e.GetMsg() << "\n"
|
||||
<< "Expression: " << e.GetExpr() << "\n"
|
||||
<< "--------------------------------------";
|
||||
}
|
||||
}
|
||||
length = FindLength(expression);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
void VisualMode(const quint32 &pointId, const QPointF &scenePos);
|
||||
qreal Angle() const;
|
||||
void setAngle(const qreal &value);
|
||||
void setLength(const VContainer *data, const QString &expression);
|
||||
void setLength(const QString &expression);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisToolEndLine)
|
||||
qreal CorrectAngle(const qreal &angle) const;
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent)
|
||||
:VisLine(data, parent), point2Id(0)
|
||||
{
|
||||
this->color = Qt::red;
|
||||
this->mainColor = Qt::red;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -56,7 +56,7 @@ void VisToolLine::RefreshGeometry()
|
|||
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
|
||||
this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
|
||||
}
|
||||
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -5,7 +5,8 @@ HEADERS += \
|
|||
visualization/vsimplecurve.h \
|
||||
visualization/visline.h \
|
||||
visualization/vistoolline.h \
|
||||
visualization/vistoolendline.h
|
||||
visualization/vistoolendline.h \
|
||||
visualization/vistoolalongline.h
|
||||
|
||||
SOURCES += \
|
||||
visualization/vgraphicssimpletextitem.cpp \
|
||||
|
@ -14,4 +15,5 @@ SOURCES += \
|
|||
visualization/vsimplecurve.cpp \
|
||||
visualization/visline.cpp \
|
||||
visualization/vistoolline.cpp \
|
||||
visualization/vistoolendline.cpp
|
||||
visualization/vistoolendline.cpp \
|
||||
visualization/vistoolalongline.cpp
|
||||
|
|
Loading…
Reference in New Issue
Block a user