Merge with feature. Resolved issue #216. Better powerful way creation curved

path.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-02-13 23:42:23 +02:00
commit 1925f6476c
34 changed files with 607 additions and 208 deletions

View File

@ -1,4 +1,5 @@
# Version 0.5.0
- [#216] Better powerful way creation curved path.
- Improved exporting to dxf. QPainterPath export as Polyline.
- Show additional message dialog if measurements was changed. Related to issue [#440].
- [#132] Intersect Curves.

View File

@ -48,6 +48,12 @@
#include "../ifc/xml/vvstconverter.h"
#include "../ifc/xml/vvitconverter.h"
#include "../vwidgets/vwidgetpopup.h"
#include "../vwidgets/vmaingraphicsscene.h"
#include "tools/drawTools/drawtools.h"
#include "../vtools/dialogs/tooldialogs.h"
#include "tools/vtooldetail.h"
#include "tools/vtooluniondetails.h"
#include "dialogs/dialogs.h"
#include <QInputDialog>
#include <QDebug>
@ -66,6 +72,8 @@
#include <QDesktopServices>
#include <chrono>
#include <thread>
#include <QFileSystemWatcher>
#include <QComboBox>
#if defined(Q_OS_MAC)
#include <QMimeData>

View File

@ -30,17 +30,10 @@
#define MAINWINDOW_H
#include "mainwindowsnogui.h"
#include "../vwidgets/vmaingraphicsview.h"
#include "../vtools/dialogs/tooldialogs.h"
#include "dialogs/dialogs.h"
#include "tools/vtooldetail.h"
#include "tools/vtooluniondetails.h"
#include "tools/drawTools/drawtools.h"
#include "core/vcmdexport.h"
#include "../vmisc/vlockguard.h"
#include <QPointer>
#include <QFileSystemWatcher>
#include <QPointer>
namespace Ui
{
@ -49,6 +42,12 @@ namespace Ui
class VToolOptionsPropertyBrowser;
class VMeasurements;
class VMainGraphicsScene;
class QFileSystemWatcher;
class QLabel;
class DialogIncrements;
class DialogTool;
class DialogHistory;
/**
* @brief The MainWindow class main windows.

View File

@ -42,6 +42,7 @@
#include "../vmisc/vsettings.h"
#include "../qmuparser/qmuparsererror.h"
#include "../vgeometry/varc.h"
#include "../vgeometry/vsplinepath.h"
#include "../core/vapplication.h"
#include "../vpatterndb/calculator.h"

View File

@ -87,7 +87,7 @@ void VSplinePoint::SetAngle1(const qreal &value)
line.setAngle(value);
d->angle1 = line.angle();
line.setAngle(value+180);
line.setAngle(d->angle1+180);
d->angle2 = line.angle();
}
@ -102,7 +102,7 @@ void VSplinePoint::SetAngle2(const qreal &value)
line.setAngle(value);
d->angle2 = line.angle();
line.setAngle(value-180);
line.setAngle(d->angle2+180);
d->angle1 = line.angle();
}

View File

@ -279,7 +279,7 @@ void DialogEndLine::ShowDialog(bool click)
{
if (click)
{
/*We will ignore click if poinet is in point circle*/
/*We will ignore click if pointer is in point circle*/
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());

View File

@ -30,8 +30,10 @@
#include "ui_dialogspline.h"
#include "../vgeometry/vpointf.h"
#include "../vgeometry/vspline.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/vistoolspline.h"
#include <QDebug>
//---------------------------------------------------------------------------------------------------------------------
@ -41,8 +43,7 @@
* @param parent parent widget
*/
DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1),
kCurve(1)
:DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1)
{
ui->setupUi(this);
InitOkCancelApply(ui);
@ -57,6 +58,13 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
this, &DialogSpline::PointNameChanged);
vis = new VisToolSpline(data);
auto path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
auto scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
connect(scene, &VMainGraphicsScene::MouseLeftPressed, path, &VisToolSpline::MouseLeftPressed);
connect(scene, &VMainGraphicsScene::MouseLeftReleased, path, &VisToolSpline::MouseLeftReleased);
}
//---------------------------------------------------------------------------------------------------------------------
@ -88,7 +96,7 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
auto *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
switch (number)
@ -96,7 +104,7 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
case 0:
if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve")))
{
number++;
++number;
path->VisualMode(id);
}
break;
@ -104,29 +112,13 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type)
{
if (getCurrentObjectId(ui->comboBoxP1) != id)
{
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(id);
qint32 index = ui->comboBoxP4->findText(point->name());
if ( index != -1 )
{ // -1 for not found
ui->comboBoxP4->setCurrentIndex(index);
emit ToolTip("");
index = ui->comboBoxP1->currentIndex();
quint32 p1Id = qvariant_cast<quint32>(ui->comboBoxP1->itemData(index));
QPointF p1 = data->GeometricObject<VPointF>(p1Id)->toQPointF();
QPointF p4 = data->GeometricObject<VPointF>(id)->toQPointF();
ui->spinBoxAngle1->setValue(static_cast<qint32>(QLineF(p1, p4).angle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(QLineF(p4, p1).angle()));
if (SetObject(id, ui->comboBoxP4, ""))
{
++number;
path->setObject4Id(id);
path->RefreshGeometry();
prepare = true;
DialogAccepted();
}
else
{
qWarning()<<"Can't find object by name"<<point->name();
}
}
break;
@ -147,7 +139,7 @@ void DialogSpline::SaveData()
kAsm2 = ui->doubleSpinBoxKasm2->value();
kCurve = ui->doubleSpinBoxKcurve->value();
VisToolSpline *path = qobject_cast<VisToolSpline *>(vis);
auto path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
path->setObject1Id(GetP1());
@ -157,6 +149,7 @@ void DialogSpline::SaveData()
path->SetKAsm1(kAsm1);
path->SetKAsm2(kAsm2);
path->SetKCurve(kCurve);
path->SetMode(Mode::Show);
path->RefreshGeometry();
}
@ -183,6 +176,32 @@ void DialogSpline::PointNameChanged()
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::ShowDialog(bool click)
{
if (prepare && click)
{
const auto p1 = data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP1));
const auto p4 = data->GeometricObject<VPointF>(getCurrentObjectId(ui->comboBoxP4));
auto *path = qobject_cast<VisToolSpline *>(vis);
SCASSERT(path != nullptr);
const QPointF p2 = path->GetP2();
const QPointF p3 = path->GetP3();
VSpline spline(*p1, p2, p3, *p4, kCurve);
ui->spinBoxAngle1->setValue(static_cast<qint32>(spline.GetStartAngle()));
ui->spinBoxAngle2->setValue(static_cast<qint32>(spline.GetEndAngle()));
ui->doubleSpinBoxKasm1->setValue(spline.GetKasm1());
ui->doubleSpinBoxKasm2->setValue(spline.GetKasm2());
DialogAccepted();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::ShowVisualization()
{

View File

@ -72,6 +72,7 @@ public:
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE;
virtual void PointNameChanged() Q_DECL_OVERRIDE;
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE;
protected:
virtual void ShowVisualization() Q_DECL_OVERRIDE;
/**

View File

@ -61,6 +61,13 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId
this, &DialogSplinePath::KAsm2Changed);
vis = new VisToolSplinePath(data);
auto path = qobject_cast<VisToolSplinePath *>(vis);
SCASSERT(path != nullptr);
auto scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
connect(scene, &VMainGraphicsScene::MouseLeftPressed, path, &VisToolSplinePath::MouseLeftPressed);
connect(scene, &VMainGraphicsScene::MouseLeftReleased, path, &VisToolSplinePath::MouseLeftReleased);
}
//---------------------------------------------------------------------------------------------------------------------
@ -88,7 +95,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value)
ui->listWidget->setFocus(Qt::OtherFocusReason);
ui->doubleSpinBoxKcurve->setValue(path.GetKCurve());
VisToolSplinePath *visPath = qobject_cast<VisToolSplinePath *>(vis);
auto visPath = qobject_cast<VisToolSplinePath *>(vis);
SCASSERT(visPath != nullptr);
visPath->setPath(path);
ui->listWidget->blockSignals(false);
@ -126,7 +133,7 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type)
SavePath();
VisToolSplinePath *visPath = qobject_cast<VisToolSplinePath *>(vis);
auto visPath = qobject_cast<VisToolSplinePath *>(vis);
SCASSERT(visPath != nullptr);
visPath->setPath(path);
@ -148,9 +155,10 @@ void DialogSplinePath::SaveData()
{
SavePath();
VisToolSplinePath *visPath = qobject_cast<VisToolSplinePath *>(vis);
auto visPath = qobject_cast<VisToolSplinePath *>(vis);
SCASSERT(visPath != nullptr);
visPath->setPath(path);
visPath->SetMode(Mode::Show);
visPath->RefreshGeometry();
}
@ -271,19 +279,7 @@ void DialogSplinePath::PathUpdated(const VSplinePath &path)
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
VisToolSplinePath *visPath = qobject_cast<VisToolSplinePath *>(vis);
SCASSERT(visPath != nullptr);
connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor);
scene->addItem(visPath);
visPath->setMode(Mode::Show);
visPath->RefreshGeometry();
}
AddVisualization<VisToolSplinePath>();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -349,6 +349,7 @@ inline void DialogTool::AddVisualization()
scene->addItem(toolVis);
}
toolVis->SetMode(Mode::Show);
toolVis->RefreshGeometry();
}
}

View File

@ -27,6 +27,8 @@
*************************************************************************/
#include "vabstractspline.h"
#include "../vwidgets/vcontrolpointspline.h"
#include <QKeyEvent>
const QString VAbstractSpline::TagName = QStringLiteral("spline");
@ -204,16 +206,16 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event)
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @brief mousePressEvent handle mouse press events.
* @param event mouse release event.
*/
void VAbstractSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void VAbstractSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit ChoosedTool(id, sceneType);
}
QGraphicsItem::mouseReleaseEvent(event);
QGraphicsPathItem::mousePressEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -30,10 +30,11 @@
#define VABSTRACTSPLINE_H
#include "../vdrawtool.h"
#include "../vwidgets/vcontrolpointspline.h"
#include <QGraphicsPathItem>
class VControlPointSpline;
class VAbstractSpline:public VDrawTool, public QGraphicsPathItem
{
Q_OBJECT
@ -56,15 +57,6 @@ public slots:
virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE;
void DetailsMode(bool mode);
signals:
/**
* @brief RefreshLine refresh control line.
* @param indexSpline position spline in spline list.
* @param pos position point in spline.
* @param controlPoint new position control point.
* @param splinePoint new position spline point.
*/
void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos,
const QPointF &controlPoint, const QPointF &splinePoint);
/**
* @brief setEnabledPoint disable control points.
* @param enable enable or diasable points.
@ -88,7 +80,7 @@ protected:
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE;
virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const;
virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE;
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;

View File

@ -31,6 +31,7 @@
#include "../../../dialogs/tools/dialogspline.h"
#include "../../../undocommands/movespline.h"
#include "../../../visualization/vistoolspline.h"
#include "../vwidgets/vcontrolpointspline.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
# include "../vmisc/vmath.h"
@ -64,23 +65,20 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co
this->setAcceptHoverEvents(true);
this->setPath(ToolPath());
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);
VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
spl->GetP1().toQPointF(), *data->GetPatternUnit(),
this);
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(),
spl->GetP1().toQPointF(), *data->GetPatternUnit(), this);
connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine);
connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint);
connect(controlPoint1, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
controlPoints.append(controlPoint1);
VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(),
spl->GetP4().toQPointF(), *data->GetPatternUnit(),
this);
auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(),
spl->GetP4().toQPointF(), *data->GetPatternUnit(), this);
connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSpline::ControlPointChangePosition);
connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine);
connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint);
connect(controlPoint2, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent);
controlPoints.append(controlPoint2);
@ -488,6 +486,7 @@ void VToolSpline::SetVisualization()
visual->SetKAsm1(spl->GetKasm1());
visual->SetKAsm2(spl->GetKasm2());
visual->SetKCurve(spl->GetKcurve());
visual->SetMode(Mode::Show);
visual->RefreshGeometry();
}
}
@ -499,7 +498,7 @@ void VToolSpline::SetVisualization()
void VToolSpline::RefreshGeometry()
{
// Very important to disable control points. Without it the pogram can't move the curve.
foreach (VControlPointSpline *point, controlPoints)
foreach (auto *point, controlPoints)
{
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
}
@ -515,26 +514,27 @@ void VToolSpline::RefreshGeometry()
this->setPath(ToolPath());
}
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);
QPointF splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP1().id())->toQPointF();
QPointF controlPoint = spl->GetP2();
emit RefreshLine(1, SplinePointPosition::FirstPoint, controlPoint, splinePoint);
splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP4().id())->toQPointF();
controlPoint = spl->GetP3();
emit RefreshLine(1, SplinePointPosition::LastPoint, controlPoint, splinePoint);
controlPoints[0]->blockSignals(true);
controlPoints[1]->blockSignals(true);
controlPoints[0]->setPos(spl->GetP2());
controlPoints[1]->setPos(spl->GetP3());
const auto spl = VAbstractTool::data.GeometricObject<VSpline>(id);
{
const QPointF splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP1().id())->toQPointF();
controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, spl->GetP2(), splinePoint);
}
{
const QPointF splinePoint = VAbstractTool::data.GeometricObject<VPointF>(spl->GetP4().id())->toQPointF();
controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, spl->GetP3(), splinePoint);
}
controlPoints[0]->blockSignals(false);
controlPoints[1]->blockSignals(false);
SetVisualization();
foreach (VControlPointSpline *point, controlPoints)
foreach (auto *point, controlPoints)
{
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}

View File

@ -31,6 +31,8 @@
#include "vabstractspline.h"
class VSpline;
/**
* @brief The VToolSpline class tool for creation spline. I mean bezier curve.
*/

View File

@ -30,6 +30,7 @@
#include "../../../dialogs/tools/dialogsplinepath.h"
#include "../../../undocommands/movesplinepath.h"
#include "../../../visualization/vistoolsplinepath.h"
#include "../vwidgets/vcontrolpointspline.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
# include "../vmisc/vmath.h"
@ -66,12 +67,10 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
for (qint32 i = 1; i<=splPath->Count(); ++i)
{
VSpline spl = splPath->GetSpline(i);
VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(),
spl.GetP1().toQPointF(), *data->GetPatternUnit(),
this);
auto *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(),
spl.GetP1().toQPointF(), *data->GetPatternUnit(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
controlPoints.append(controlPoint);
@ -80,7 +79,6 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3
*data->GetPatternUnit(), this);
connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this,
&VToolSplinePath::ControlPointChangePosition);
connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine);
connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint);
connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent);
controlPoints.append(controlPoint);
@ -559,7 +557,7 @@ void VToolSplinePath::SetVisualization()
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
visual->setPath(*splPath.data());
visual->setMode(Mode::Show);
visual->SetMode(Mode::Show);
visual->RefreshGeometry();
}
}
@ -571,7 +569,7 @@ void VToolSplinePath::SetVisualization()
void VToolSplinePath::RefreshGeometry()
{
// Very important to disable control points. Without it the pogram can't move the curve.
foreach (VControlPointSpline *point, controlPoints)
foreach (auto *point, controlPoints)
{
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
}
@ -584,26 +582,29 @@ void VToolSplinePath::RefreshGeometry()
{
this->setPath(ToolPath());
}
this->setPen(QPen(CorrectColor(lineColor),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
const QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
const auto splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);
for (qint32 i = 1; i<=splPath->Count(); ++i)
{
VSpline spl = splPath->GetSpline(i);
QPointF splinePoint = spl.GetP1().toQPointF();
QPointF controlPoint = spl.GetP2();
emit RefreshLine(i, SplinePointPosition::FirstPoint, controlPoint, splinePoint);
splinePoint = spl.GetP4().toQPointF();
controlPoint = spl.GetP3();
emit RefreshLine(i, SplinePointPosition::LastPoint, controlPoint, splinePoint);
qint32 j = i*2;
const qint32 j = i*2;
controlPoints[j-2]->blockSignals(true);
controlPoints[j-1]->blockSignals(true);
controlPoints[j-2]->setPos(spl.GetP2());
controlPoints[j-1]->setPos(spl.GetP3());
const auto spl = splPath->GetSpline(i);
{
const auto splinePoint = spl.GetP1().toQPointF();
controlPoints[j-2]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(), splinePoint);
}
{
const auto splinePoint = spl.GetP4().toQPointF();
controlPoints[j-1]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(), splinePoint);
}
controlPoints[j-2]->blockSignals(false);
controlPoints[j-1]->blockSignals(false);
@ -611,7 +612,7 @@ void VToolSplinePath::RefreshGeometry()
SetVisualization();
foreach (VControlPointSpline *point, controlPoints)
foreach (auto *point, controlPoints)
{
point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}

View File

@ -31,6 +31,10 @@
#include "vabstractspline.h"
class VSplinePath;
class VSplinePoint;
class VSpline;
/**
* @brief The VToolSplinePath class tool for creation spline path.
*/

View File

@ -177,16 +177,16 @@ void VToolSinglePoint::FullUpdateFromFile()
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief mouseReleaseEvent handle mouse release events.
* @brief mousePressEvent handle mouse press events.
* @param event mouse release event.
*/
void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
PointChoosed();
}
QGraphicsEllipseItem::mouseReleaseEvent(event);
QGraphicsEllipseItem::mousePressEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -73,7 +73,7 @@ protected:
QGraphicsLineItem *lineName;
virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void RefreshPointGeometry(const VPointF &point);

View File

@ -31,12 +31,10 @@
#include "../vabstracttool.h"
#include "../../dialogs/tools/dialogtool.h"
#include "../vwidgets/vmaingraphicsscene.h"
#include "../vwidgets/vmaingraphicsview.h"
#include <QMenu>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsView>
/**
* @brief The VDrawTool abstract class for all draw tool.

View File

@ -446,9 +446,14 @@ void VToolDetail::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
event->accept();
}
}
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
emit ChoosedTool(id, SceneObject::Detail);
}
VNoBrushScalePathItem::mousePressEvent(event);
}
@ -461,11 +466,10 @@ void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit ChoosedTool(id, SceneObject::Detail);
//Disable cursor-arrow-closehand
RestoreOverrideCursor(cursorArrowCloseHand);
}
QGraphicsItem::mouseReleaseEvent(event);
VNoBrushScalePathItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -51,7 +51,7 @@ void VisToolEndLine::RefreshGeometry()
{
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
QLineF line;
if (qFuzzyCompare(1 + length, 1 + 0))
if (qFuzzyIsNull(length))
{
line = QLineF(first->toQPointF(), Ray(first->toQPointF()));
}

View File

@ -30,17 +30,38 @@
#include "../../vgeometry/vpointf.h"
#include "../../vgeometry/vspline.h"
#include "../../vpatterndb/vcontainer.h"
#include "../vwidgets/vcontrolpointspline.h"
const int EMPTY_ANGLE = -1;
//---------------------------------------------------------------------------------------------------------------------
VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent), object4Id(NULL_ID), lineP1(nullptr), lineP4(nullptr), line(nullptr), angle1(EMPTY_ANGLE),
angle2(EMPTY_ANGLE), kAsm1(1), kAsm2(1), kCurve(1)
: VisPath(data, parent),
object4Id(NULL_ID),
point1(nullptr),
point4(nullptr),
angle1(EMPTY_ANGLE),
angle2(EMPTY_ANGLE),
kAsm1(1),
kAsm2(1),
kCurve(1),
isLeftMousePressed(false),
p2Selected(false),
p3Selected(false),
p2(),
p3(),
controlPoints()
{
lineP1 = InitPoint(supportColor, this);
lineP4 = InitPoint(supportColor, this); //-V656
line = InitItem<QGraphicsLineItem>(mainColor, this);
point1 = InitPoint(supportColor, this);
point4 = InitPoint(supportColor, this); //-V656
auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, *data->GetPatternUnit(), this);
controlPoint1->hide();
controlPoints.append(controlPoint1);
auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, *data->GetPatternUnit(), this);
controlPoint2->hide();
controlPoints.append(controlPoint2);
}
//---------------------------------------------------------------------------------------------------------------------
@ -50,23 +71,80 @@ VisToolSpline::~VisToolSpline()
//---------------------------------------------------------------------------------------------------------------------
void VisToolSpline::RefreshGeometry()
{
//Radius of point circle, but little bigger. Need handle with hover sizes.
const static qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5;
if (object1Id > NULL_ID)
{
const QSharedPointer<VPointF> first = Visualization::data->GeometricObject<VPointF>(object1Id);
DrawPoint(lineP1, first->toQPointF(), supportColor);
const auto first = Visualization::data->GeometricObject<VPointF>(object1Id);
DrawPoint(point1, first->toQPointF(), supportColor);
if (mode == Mode::Creation)
{
if (isLeftMousePressed && not p2Selected)
{
p2 = Visualization::scenePos;
controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, p2, first->toQPointF());
if (not controlPoints[0]->isVisible())
{
if (QLineF(first->toQPointF(), p2).length() > radius)
{
controlPoints[0]->show();
}
else
{
p2 = first->toQPointF();
}
}
}
else
{
p2Selected = true;
}
}
if (object4Id <= NULL_ID)
{
DrawLine(line, QLineF(first->toQPointF(), Visualization::scenePos), mainColor);
VSpline spline(*first, p2, Visualization::scenePos, VPointF(Visualization::scenePos), kCurve);
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
}
else
{
const QSharedPointer<VPointF> second = Visualization::data->GeometricObject<VPointF>(object4Id);
DrawPoint(lineP4, second->toQPointF(), supportColor);
const auto second = Visualization::data->GeometricObject<VPointF>(object4Id);
DrawPoint(point4, second->toQPointF(), supportColor);
if (mode == Mode::Creation)
{
if (isLeftMousePressed && not p3Selected)
{
QLineF ctrlLine (second->toQPointF(), Visualization::scenePos);
ctrlLine.setAngle(ctrlLine.angle()+180);
p3 = ctrlLine.p2();
controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, p3, second->toQPointF());
if (not controlPoints[1]->isVisible())
{
if (QLineF(second->toQPointF(), p3).length() > radius)
{
controlPoints[1]->show();
}
else
{
p3 = second->toQPointF();
}
}
}
else
{
p3Selected = true;
}
}
if (qFuzzyCompare(angle1, EMPTY_ANGLE) || qFuzzyCompare(angle2, EMPTY_ANGLE))
{
DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), mainColor);
VSpline spline(*first, p2, p3, *second, kCurve);
DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
}
else
{
@ -112,3 +190,34 @@ void VisToolSpline::SetKCurve(const qreal &value)
{
kCurve = value;
}
//---------------------------------------------------------------------------------------------------------------------
QPointF VisToolSpline::GetP2() const
{
return p2;
}
//---------------------------------------------------------------------------------------------------------------------
QPointF VisToolSpline::GetP3() const
{
return p3;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSpline::MouseLeftPressed()
{
if (mode == Mode::Creation)
{
isLeftMousePressed = true;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSpline::MouseLeftReleased()
{
if (mode == Mode::Creation)
{
isLeftMousePressed = false;
RefreshGeometry();
}
}

View File

@ -31,6 +31,8 @@
#include "vispath.h"
class VControlPointSpline;
class VisToolSpline : public VisPath
{
Q_OBJECT
@ -47,19 +49,35 @@ public:
void SetKAsm2(const qreal &value);
void SetKCurve(const qreal &value);
QPointF GetP2() const;
QPointF GetP3() const;
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolSpline)};
public slots:
void MouseLeftPressed();
void MouseLeftReleased();
protected:
Q_DISABLE_COPY(VisToolSpline)
quint32 object4Id;
QGraphicsEllipseItem *lineP1;
QGraphicsEllipseItem *lineP4;
QGraphicsLineItem *line;
QGraphicsEllipseItem *point1;
QGraphicsEllipseItem *point4;
qreal angle1;
qreal angle2;
qreal kAsm1;
qreal kAsm2;
qreal kCurve;
bool isLeftMousePressed;
bool p2Selected;
bool p3Selected;
QPointF p2;
QPointF p3;
QVector<VControlPointSpline *> controlPoints;
};
#endif // VISTOOLSPLINE_H

View File

@ -27,19 +27,27 @@
*************************************************************************/
#include "vistoolsplinepath.h"
#include "../vwidgets/vcontrolpointspline.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent)
: VisPath(data, parent), points(QVector<QGraphicsEllipseItem *>()), line(nullptr), path(VSplinePath()),
mode(Mode::Creation)
: VisPath(data, parent),
points(QVector<QGraphicsEllipseItem *>()),
ctrlPoints(QVector<VControlPointSpline *>()),
newCurveSegment(nullptr),
path(VSplinePath()),
isLeftMousePressed(false),
pointSelected(false),
ctrlPoint()
{
line = InitItem<QGraphicsLineItem>(mainColor, this);
newCurveSegment = InitItem<QGraphicsPathItem>(mainColor, this);
}
//---------------------------------------------------------------------------------------------------------------------
VisToolSplinePath::~VisToolSplinePath()
{
qDeleteAll(points.begin(), points.end());
qDeleteAll(ctrlPoints);
qDeleteAll(points);
}
//---------------------------------------------------------------------------------------------------------------------
@ -47,41 +55,41 @@ void VisToolSplinePath::RefreshGeometry()
{
if (path.CountPoint() > 0)
{
QVector<VSplinePoint> pathPoints = path.GetSplinePath();
if (path.CountPoint() == 1)
const QVector<VSplinePoint> pathPoints = path.GetSplinePath();
const int size = pathPoints.size();
for (int i = 0; i < size; ++i)
{
QGraphicsEllipseItem *point = this->getPoint(0);
DrawPoint(point, pathPoints.at(0).P().toQPointF(), supportColor);
if (mode == Mode::Creation)
{
QLineF sceneLine = QLineF(pathPoints.at(0).P().toQPointF(), Visualization::scenePos);
DrawLine(line, sceneLine, mainColor, lineStyle);
path[0].SetAngle2(sceneLine.angle());
emit PathChanged(path);
}
QGraphicsEllipseItem *point = this->getPoint(static_cast<unsigned>(i));
DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor);
}
else
if (mode == Mode::Creation)
{
for (int i = 0; i < pathPoints.size(); ++i)
if (size > 1)
{
QGraphicsEllipseItem *point = this->getPoint(static_cast<unsigned>(i));
DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor);
for (qint32 i = 1; i<=path.Count(); ++i)
{
const int preLastPoint = (path.Count() - 1) * 2;
const int lastPoint = preLastPoint + 1;
VSpline spl = path.GetSpline(i);
ctrlPoints[preLastPoint]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(),
spl.GetP1().toQPointF());
ctrlPoints[lastPoint]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(),
spl.GetP4().toQPointF());
}
}
if (mode == Mode::Creation)
{
QLineF sceneLine = QLineF(pathPoints.at(pathPoints.size() - 1).P().toQPointF(),
Visualization::scenePos);
DrawLine(line, sceneLine, mainColor, lineStyle);
path[pathPoints.size() - 1].SetAngle2(sceneLine.angle());
emit PathChanged(path);
}
Creating(pathPoints.at(size-1).P().toQPointF(), size);
}
if (size > 1)
{
DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap);
}
if (path.CountPoint() < 3)
{
Visualization::toolTip = tr("<b>Curved path</b>: select three or more points");
@ -108,15 +116,22 @@ VSplinePath VisToolSplinePath::getPath()
}
//---------------------------------------------------------------------------------------------------------------------
Mode VisToolSplinePath::getMode() const
void VisToolSplinePath::MouseLeftPressed()
{
return mode;
if (mode == Mode::Creation)
{
isLeftMousePressed = true;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSplinePath::setMode(const Mode &value)
void VisToolSplinePath::MouseLeftReleased()
{
mode = value;
if (mode == Mode::Creation)
{
isLeftMousePressed = false;
RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -128,9 +143,147 @@ QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i)
}
else
{
QGraphicsEllipseItem * point = InitPoint(supportColor, this);
pointSelected = false;
auto point = InitPoint(supportColor, this);
points.append(point);
if (points.size() == 1)
{
auto *controlPoint1 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint,
*Visualization::data->GetPatternUnit(),
this);
controlPoint1->hide();
ctrlPoints.append(controlPoint1);
}
else
{
auto *controlPoint1 = new VControlPointSpline(points.size()-1, SplinePointPosition::LastPoint,
*Visualization::data->GetPatternUnit(),
this);
controlPoint1->hide();
ctrlPoints.append(controlPoint1);
auto *controlPoint2 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint,
*Visualization::data->GetPatternUnit(),
this);
controlPoint2->hide();
ctrlPoints.append(controlPoint2);
}
return point;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolSplinePath::Creating(const QPointF &pSpl, int size)
{
//Radius of point circle, but little bigger. Need handle with hover sizes.
const static qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5;
int lastPoint = 0;
int preLastPoint = 0;
if (size > 1)
{
lastPoint = (size - 1) * 2;
preLastPoint = lastPoint - 1;
}
if (isLeftMousePressed && not pointSelected)
{
newCurveSegment->hide();
ctrlPoint = Visualization::scenePos;
if (not ctrlPoints[lastPoint]->isVisible())
{
if (QLineF(pSpl, ctrlPoint).length() > radius)
{
if (size == 1)
{
ctrlPoints[lastPoint]->show();
}
else
{
ctrlPoints[preLastPoint]->show();
ctrlPoints[lastPoint]->show();
}
}
else
{
ctrlPoint = pSpl;
}
}
QLineF ctrlLine (pSpl, Visualization::scenePos);
ctrlLine.setAngle(ctrlLine.angle()+180);
if (size == 1)
{
ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl);
}
else
{
ctrlPoints[preLastPoint]->RefreshCtrlPoint(size-1, SplinePointPosition::LastPoint, ctrlLine.p2(), pSpl);
ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl);
}
VSpline spline(VPointF(pSpl), ctrlPoint, Visualization::scenePos,
VPointF(Visualization::scenePos), path.GetKCurve());
if (size == 1)
{
path[size-1].SetAngle2(spline.GetStartAngle());
if (ctrlPoint != pSpl)
{
path[size-1].SetKAsm2(spline.GetKasm1());
}
else
{
path[size-1].SetKAsm2(0);
}
emit PathChanged(path);
}
else
{
const VSpline spl = path.GetSpline(size - 1);
VSpline preSpl(spl.GetP1(), spl.GetP2(), ctrlLine.p2(), VPointF(pSpl), path.GetKCurve());
path[size-1].SetAngle2(spline.GetStartAngle());
if (ctrlPoint != pSpl)
{
path[size-1].SetKAsm1(preSpl.GetKasm2());
path[size-1].SetKAsm2(spline.GetKasm1());
}
else
{
path[size-1].SetKAsm1(0);
path[size-1].SetKAsm2(0);
}
emit PathChanged(path);
}
}
else
{
pointSelected = true;
VSpline spline(VPointF(pSpl), ctrlPoint, Visualization::scenePos,
VPointF(Visualization::scenePos), path.GetKCurve());
path[size-1].SetAngle2(spline.GetStartAngle());
if (ctrlPoint != pSpl)
{
path[size-1].SetKAsm2(spline.GetKasm1());
}
else
{
path[size-1].SetKAsm2(0);
}
emit PathChanged(path);
DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap);
}
}

View File

@ -32,7 +32,7 @@
#include "vispath.h"
#include "../../vgeometry/vsplinepath.h"
enum class Mode : char {Creation, Show};
class VControlPointSpline;
class VisToolSplinePath : public VisPath
{
@ -49,19 +49,27 @@ public:
virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Vis::ToolSplinePath)};
Mode getMode() const;
void setMode(const Mode &value);
signals:
void PathChanged(const VSplinePath &path);
public slots:
void MouseLeftPressed();
void MouseLeftReleased();
protected:
Q_DISABLE_COPY(VisToolSplinePath)
QVector<QGraphicsEllipseItem *> points;
QGraphicsLineItem *line;
QVector<VControlPointSpline *> ctrlPoints;
QGraphicsPathItem *newCurveSegment;
VSplinePath path;
Mode mode;
bool isLeftMousePressed;
bool pointSelected;
QPointF ctrlPoint;
QGraphicsEllipseItem * getPoint(quint32 i);
void Creating(const QPointF &pSpl, int size);
};
#endif // VISTOOLSPLINEPATH_H

View File

@ -37,8 +37,16 @@ Q_LOGGING_CATEGORY(vVis, "v.visualization")
//---------------------------------------------------------------------------------------------------------------------
Visualization::Visualization(const VContainer *data)
:QObject(), data(data), factor(VDrawTool::factor), scenePos(QPointF()),
mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), object1Id(NULL_ID), toolTip(QString())
:QObject(),
data(data),
factor(VDrawTool::factor),
scenePos(QPointF()),
mainColor(Qt::red),
supportColor(Qt::magenta),
lineStyle(Qt::SolidLine),
object1Id(NULL_ID),
toolTip(QString()),
mode(Mode::Creation)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -196,3 +204,16 @@ void Visualization::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &pa
pathItem->setPath(path);
pathItem->setVisible(true);
}
//---------------------------------------------------------------------------------------------------------------------
Mode Visualization::GetMode() const
{
return mode;
}
//---------------------------------------------------------------------------------------------------------------------
void Visualization::SetMode(const Mode &value)
{
mode = value;
}

View File

@ -39,6 +39,8 @@
Q_DECLARE_LOGGING_CATEGORY(vVis)
enum class Mode : char {Creation, Show};
class Visualization : public QObject
{
Q_OBJECT
@ -53,6 +55,9 @@ public:
void setScenePos(const QPointF &value);
virtual void VisualMode(const quint32 &pointId);
void setMainColor(const QColor &value);
Mode GetMode() const;
void SetMode(const Mode &value);
signals:
void ToolTip(const QString &toolTip);
public slots:
@ -67,6 +72,7 @@ protected:
Qt::PenStyle lineStyle;
quint32 object1Id;
QString toolTip;
Mode mode;
virtual void InitPen()=0;
virtual void AddOnScene()=0;

View File

@ -36,6 +36,19 @@
#include "vmaingraphicsview.h"
#include "vmaingraphicsscene.h"
//---------------------------------------------------------------------------------------------------------------------
VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit,
QGraphicsItem *parent)
:QGraphicsEllipseItem(parent),
radius(CircleRadius()),
controlLine(nullptr),
indexSpline(indexSpline),
position(position),
patternUnit(patternUnit)
{
Init();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VControlPointSpline constructor.
@ -48,28 +61,22 @@
VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position,
const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit,
QGraphicsItem *parent)
:QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position),
:QGraphicsEllipseItem(parent),
radius(CircleRadius()),
controlLine(nullptr),
indexSpline(indexSpline),
position(position),
patternUnit(patternUnit)
{
//create circle
radius = (1.5/*mm*/ / 25.4) * PrintDPI;
QRectF rec = QRectF(0, 0, radius*2, radius*2);
rec.translate(-rec.center().x(), -rec.center().y());
this->setRect(rec);
this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit)));
this->setBrush(QBrush(Qt::NoBrush));
Init();
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setAcceptHoverEvents(true);
this->setPos(controlPoint);
this->setZValue(100);
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2);
controlLine = new QGraphicsLineItem(QLineF(splinePoint-controlPoint, p1), this);
controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit)));
controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
SetCtrlLine(controlPoint, splinePoint);
}
//---------------------------------------------------------------------------------------------------------------------
@ -196,22 +203,44 @@ void VControlPointSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event
emit ShowContextMenu(event);
}
//---------------------------------------------------------------------------------------------------------------------
void VControlPointSpline::Init()
{
auto rec = QRectF(0, 0, radius*2, radius*2);
rec.translate(-rec.center().x(), -rec.center().y());
this->setRect(rec);
this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit)));
this->setBrush(QBrush(Qt::NoBrush));
this->setZValue(100);
controlLine = new QGraphicsLineItem(this);
controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit)));
controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
}
//---------------------------------------------------------------------------------------------------------------------
void VControlPointSpline::SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint)
{
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2);
controlLine->setLine(QLineF(splinePoint-controlPoint, p1));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshLine refresh line control point.
* @brief RefreshCtrlPoint refresh the control point.
* @param indexSpline index spline in list.
* @param pos position point in spline.
* @param controlPoint control point.
* @param splinePoint spline point.
*/
void VControlPointSpline::RefreshLine(const qint32 &indexSpline, SplinePointPosition pos,
const QPointF &controlPoint, const QPointF &splinePoint)
void VControlPointSpline::RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos,
const QPointF &controlPoint, const QPointF &splinePoint)
{
if (this->indexSpline == indexSpline && this->position == pos)
{
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2);
controlLine->setLine(QLineF(splinePoint-controlPoint, p1));
this->setPos(controlPoint);
SetCtrlLine(controlPoint, splinePoint);
}
}

View File

@ -41,6 +41,8 @@ class VControlPointSpline : public QObject, public QGraphicsEllipseItem
{
Q_OBJECT
public:
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit,
QGraphicsItem * parent = nullptr);
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint,
const QPointF &splinePoint, Unit patternUnit, QGraphicsItem * parent = nullptr);
virtual ~VControlPointSpline() Q_DECL_OVERRIDE;
@ -63,12 +65,12 @@ signals:
*/
void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
public slots:
void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
const QPointF &splinePoint);
void RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
const QPointF &splinePoint);
void setEnabledPoint(bool enable);
protected:
/** @brief radius radius circle. */
qreal radius;
const qreal radius;
/** @brief controlLine pointer to line control point. */
QGraphicsLineItem *controlLine;
@ -88,6 +90,16 @@ private:
SplinePointPosition position;
Unit patternUnit;
inline qreal CircleRadius() const;
void Init();
void SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint);
};
//---------------------------------------------------------------------------------------------------------------------
qreal VControlPointSpline::CircleRadius() const
{
return (1.5/*mm*/ / 25.4) * PrintDPI;
}
#endif // VCONTROLPOINTSPLINE_H

View File

@ -217,6 +217,9 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
SetOverrideCursor(cursorArrowCloseHand, 1, 1);
}
}
emit PointChoosed();
QGraphicsSimpleTextItem::mousePressEvent(event);
}
@ -231,10 +234,7 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
RestoreOverrideCursor(cursorArrowCloseHand);
}
}
else
{
emit PointChoosed();
}
QGraphicsSimpleTextItem::mouseReleaseEvent(event);
}

View File

@ -74,7 +74,11 @@ void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
*/
void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit mousePress(event->scenePos());
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
emit MouseLeftPressed();
}
QGraphicsScene::mousePressEvent(event);
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier)
{
@ -86,6 +90,16 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{
emit MouseLeftReleased();
}
QGraphicsScene::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsScene::InitOrigins()
{

View File

@ -61,17 +61,17 @@ public slots:
protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
signals:
/**
* @brief mouseMove send new mouse position.
* @param scenePos new mouse position.
*/
void mouseMove(const QPointF &scenePos);
/**
* @brief mousePress send new mouse press position.
* @param scenePos new mouse press position.
*/
void mousePress(QPointF scenePos);
void MouseLeftPressed();
void MouseLeftReleased();
/**
* @brief ChoosedObject send option choosed object.
* @param id object id.

View File

@ -173,13 +173,13 @@ void VSimplePoint::ContextMenu(QGraphicsSceneContextMenuEvent *event)
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit Choosed(id);
}
QGraphicsEllipseItem::mouseReleaseEvent(event);
QGraphicsEllipseItem::mousePressEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -75,7 +75,7 @@ public slots:
void ContextMenu(QGraphicsSceneContextMenuEvent * event);
protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;