Visualization for VToolEndLine.
--HG-- branch : develop
This commit is contained in:
parent
6d0029324b
commit
3953d6fb22
|
@ -31,6 +31,9 @@
|
|||
|
||||
#include "../../geometry/vpointf.h"
|
||||
#include "../../container/vcontainer.h"
|
||||
#include "../../visualization/vistoolendline.h"
|
||||
#include "../../widgets/vmaingraphicsscene.h"
|
||||
#include "../../tools/vabstracttool.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
|
@ -40,7 +43,7 @@
|
|||
*/
|
||||
DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent)
|
||||
:DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), formula(QString()),
|
||||
angle(0), basePointId(0), formulaBaseHeight(0)
|
||||
angle(0), basePointId(0), formulaBaseHeight(0), line(nullptr), prepare(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
InitVariables(ui);
|
||||
|
@ -64,6 +67,8 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent)
|
|||
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged);
|
||||
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged);
|
||||
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit);
|
||||
|
||||
line = new VisToolEndLine(data);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -86,13 +91,25 @@ void DialogEndLine::DeployFormulaTextEdit()
|
|||
*/
|
||||
void DialogEndLine::ChosenObject(quint32 id, const SceneObject &type)
|
||||
{
|
||||
if (prepare == false)// After first choose we ignore all objects
|
||||
{
|
||||
if (type == SceneObject::Point)
|
||||
{
|
||||
const VPointF *point = data->GeometricObject<const VPointF *>(id);
|
||||
basePointId = id;
|
||||
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
|
||||
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
SCASSERT(scene != nullptr);
|
||||
scene->addItem(line);
|
||||
line->VisualMode(id, scene->getScenePos());
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolEndLine::SetFactor);
|
||||
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolEndLine::MousePos);
|
||||
connect(line, &VisToolEndLine::ToolTip, this, &DialogTool::ShowVisToolTip);
|
||||
|
||||
emit ToolTip("");
|
||||
this->setModal(true);
|
||||
this->show();
|
||||
prepare = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,6 +133,7 @@ void DialogEndLine::setTypeLine(const QString &value)
|
|||
{
|
||||
typeLine = value;
|
||||
SetupTypeLine(ui->comboBoxLineType, value);
|
||||
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -133,6 +151,7 @@ void DialogEndLine::setFormula(const QString &value)
|
|||
this->DeployFormulaTextEdit();
|
||||
}
|
||||
ui->plainTextEditFormula->setPlainText(formula);
|
||||
line->setLength(data, formula);
|
||||
//QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
||||
//cursor.insertText(value);
|
||||
//ui->plainTextEditFormula->setCursor(cursor);
|
||||
|
@ -147,6 +166,7 @@ void DialogEndLine::setAngle(const qreal &value)
|
|||
{
|
||||
angle = value;
|
||||
ui->doubleSpinBoxAngle->setValue(angle);
|
||||
line->setAngle(angle);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -158,6 +178,52 @@ void DialogEndLine::setAngle(const qreal &value)
|
|||
void DialogEndLine::setBasePointId(const quint32 &value, const quint32 &id)
|
||||
{
|
||||
setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, id);
|
||||
line->setPoint1Id(value);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief DialogEndLine::ShowDialog show dialog after finish working with visual part
|
||||
* @param click true if need show dialog after click mouse
|
||||
*/
|
||||
void DialogEndLine::ShowDialog(bool click)
|
||||
{
|
||||
if (prepare)
|
||||
{
|
||||
if (click)
|
||||
{
|
||||
/*We will ignore click if poinet is in point circle*/
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
SCASSERT(scene != nullptr);
|
||||
const VPointF *point = data->GeometricObject<const VPointF *>(basePointId);
|
||||
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
|
||||
|
||||
//Radius of point circle, but little bigger. Need handle with hover sizes.
|
||||
qreal radius = ((DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI)*1.5;
|
||||
if (line.length() <= radius)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->setModal(true);
|
||||
this->setAngle(line->Angle());//Show in dialog angle what user choose
|
||||
line->setColor(Qt::red);//Now linw will be red
|
||||
emit ToolTip("");
|
||||
this->show();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogEndLine::ShowVisualization()
|
||||
{
|
||||
if (prepare == false)
|
||||
{
|
||||
//TODO move to parent class!
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolEndLine::SetFactor);
|
||||
scene->addItem(line);
|
||||
line->RefreshGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -185,10 +251,17 @@ void DialogEndLine::SaveData()
|
|||
formula.replace("\n", " ");
|
||||
angle = ui->doubleSpinBoxAngle->value();
|
||||
basePointId = getCurrentObjectId(ui->comboBoxBasePoint);
|
||||
|
||||
line->setPoint1Id(basePointId);
|
||||
line->setLength(data, formula);
|
||||
line->setAngle(angle);
|
||||
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
|
||||
line->RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogEndLine::~DialogEndLine()
|
||||
{
|
||||
delete line;
|
||||
delete ui;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ namespace Ui
|
|||
class DialogEndLine;
|
||||
}
|
||||
|
||||
class VisToolEndLine;
|
||||
|
||||
/**
|
||||
* @brief The DialogEndLine class dialog for ToolEndLine. Help create point and edit option.
|
||||
*/
|
||||
|
@ -60,6 +62,7 @@ public:
|
|||
|
||||
quint32 getBasePointId() const;
|
||||
void setBasePointId(const quint32 &value, const quint32 &id);
|
||||
virtual void ShowDialog(bool click);
|
||||
public slots:
|
||||
virtual void ChosenObject(quint32 id, const SceneObject &type);
|
||||
virtual void DialogAccepted();
|
||||
|
@ -75,6 +78,8 @@ public slots:
|
|||
* @brief FormulaTextChanged when formula text changes for validation and calc
|
||||
*/
|
||||
void FormulaTextChanged();
|
||||
protected:
|
||||
virtual void ShowVisualization();
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogEndLine)
|
||||
|
||||
|
@ -95,9 +100,15 @@ private:
|
|||
|
||||
/** @brief basePointId id base point of line */
|
||||
quint32 basePointId;
|
||||
|
||||
/** @brief formulaBaseHeight base height defined by dialogui */
|
||||
int formulaBaseHeight;
|
||||
|
||||
VisToolEndLine *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
|
||||
*/
|
||||
|
|
|
@ -319,8 +319,14 @@
|
|||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>29</number>
|
||||
<number>28</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>6</number>
|
||||
|
@ -393,7 +399,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="0" column="1" alignment="Qt::AlignHCenter">
|
||||
<widget class="QToolButton" name="toolButtonArrowUp">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
|
@ -416,7 +422,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="2" column="1" alignment="Qt::AlignHCenter">
|
||||
<widget class="QToolButton" name="toolButtonArrowDown">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
|
@ -467,17 +473,17 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="1" column="1" alignment="Qt::AlignHCenter">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBoxAngle">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>57</width>
|
||||
<width>72</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
|
@ -487,6 +493,9 @@
|
|||
<property name="maximum">
|
||||
<double>360.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>360.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -118,8 +118,6 @@ void DialogLine::DialogAccepted()
|
|||
void DialogLine::DialogApply()
|
||||
{
|
||||
this->SaveData();
|
||||
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
|
||||
line->RefreshGeometry();
|
||||
emit DialogApplied();
|
||||
}
|
||||
|
||||
|
@ -168,6 +166,11 @@ void DialogLine::SaveData()
|
|||
index = ui->comboBoxSecondPoint->currentIndex();
|
||||
secondPoint = qvariant_cast<quint32>(ui->comboBoxSecondPoint->itemData(index));
|
||||
typeLine = GetTypeLine(ui->comboBoxLineType);
|
||||
|
||||
line->setPoint1Id(firstPoint);
|
||||
line->setPoint2Id(secondPoint);
|
||||
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
|
||||
line->RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -188,7 +191,7 @@ void DialogLine::ChosenObject(quint32 id, const SceneObject &type)
|
|||
{ // -1 for not found
|
||||
|
||||
VMainGraphicsScene *scene = qApp->getCurrentScene();
|
||||
line = new VisToolLine(data, id, scene->getScenePos());
|
||||
line->VisualMode(id, scene->getScenePos());
|
||||
scene->addItem(line);
|
||||
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor);
|
||||
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolLine::MousePos);
|
||||
|
|
|
@ -1081,3 +1081,15 @@ void DialogTool::DialogApply()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogTool::ShowVisToolTip(const QString &toolTip)
|
||||
{
|
||||
emit ToolTip(toolTip);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogTool::ShowDialog(bool click)
|
||||
{
|
||||
Q_UNUSED(click);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ public:
|
|||
virtual ~DialogTool() {}
|
||||
VAbstractTool* GetAssociatedTool();
|
||||
void SetAssociatedTool(VAbstractTool* tool);
|
||||
virtual void ShowDialog(bool click);
|
||||
signals:
|
||||
/**
|
||||
* @brief DialogClosed signal dialog closed
|
||||
|
@ -75,6 +76,7 @@ signals:
|
|||
*/
|
||||
void ToolTip(const QString &toolTip);
|
||||
public slots:
|
||||
void ShowVisToolTip(const QString &toolTip);
|
||||
virtual void ChosenObject(quint32 id, const SceneObject &type);
|
||||
void NamePointChanged();
|
||||
virtual void DialogAccepted();
|
||||
|
@ -108,6 +110,7 @@ public slots:
|
|||
virtual void ValChenged(int row);
|
||||
virtual void UpdateList();
|
||||
virtual void PointNameChanged(){}
|
||||
|
||||
protected:
|
||||
Q_DISABLE_COPY(DialogTool)
|
||||
|
||||
|
|
|
@ -302,6 +302,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
|
|||
connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot);
|
||||
connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
|
||||
connect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList);
|
||||
connect(view, &VMainGraphicsView::MouseRelease, this, &MainWindow::ClickEndVisualization);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -377,6 +378,7 @@ void MainWindow::ApplyDialog()
|
|||
else
|
||||
{ // Or update associated tool with data
|
||||
VDrawTool * vtool= static_cast<VDrawTool *>(dialogTool->GetAssociatedTool());
|
||||
SCASSERT(vtool != nullptr);
|
||||
vtool->FullUpdateFromGuiApply();
|
||||
}
|
||||
}
|
||||
|
@ -1284,6 +1286,12 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
|
|||
case Qt::Key_Escape:
|
||||
ArrowTool();
|
||||
break;
|
||||
case Qt::Key_Return:
|
||||
EndVisualization();
|
||||
break;
|
||||
case Qt::Key_Enter:
|
||||
EndVisualization();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1660,6 +1668,12 @@ void MainWindow::SetEnabledGUI(bool enabled)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MainWindow::ClickEndVisualization()
|
||||
{
|
||||
EndVisualization(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief NewPattern create new empty pattern.
|
||||
|
@ -2331,3 +2345,12 @@ void MainWindow::ChangePP(int index, bool zoomBestFit)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MainWindow::EndVisualization(bool click)
|
||||
{
|
||||
if (dialogTool != nullptr)
|
||||
{
|
||||
dialogTool->ShowDialog(click);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ public slots:
|
|||
void EditPatternCode();
|
||||
void FullParseFile();
|
||||
void SetEnabledGUI(bool enabled);
|
||||
void ClickEndVisualization();
|
||||
signals:
|
||||
/**
|
||||
* @brief ModelChosen emit after calculation all details.
|
||||
|
@ -152,9 +153,9 @@ signals:
|
|||
*/
|
||||
void ModelChosen(QVector<VItem*> listDetails, const QString &curFile, const QString &description);
|
||||
protected:
|
||||
virtual void keyPressEvent ( QKeyEvent * event );
|
||||
virtual void showEvent( QShowEvent *event );
|
||||
virtual void closeEvent( QCloseEvent * event );
|
||||
virtual void keyPressEvent(QKeyEvent *event);
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
virtual void closeEvent(QCloseEvent *event);
|
||||
virtual void customEvent(QEvent * event);
|
||||
private:
|
||||
Q_DISABLE_COPY(MainWindow)
|
||||
|
@ -259,6 +260,10 @@ private:
|
|||
template <typename Func>
|
||||
void SetGradationList(const QString &label, const QStringList &list, Func changeSlot);
|
||||
void ChangePP(int index , bool zoomBestFit = true);
|
||||
/**
|
||||
* @brief EndVisualization try show dialog after and working with tool visualization.
|
||||
*/
|
||||
void EndVisualization(bool click = false);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
class QString;
|
||||
|
||||
#define SceneSize 50000
|
||||
#define DefPointRadius 2.0//mm
|
||||
|
||||
enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail };
|
||||
enum class Tool : char
|
||||
|
|
|
@ -183,7 +183,7 @@ void VToolEndLine::FullUpdateFromFile()
|
|||
typeLine = domElement.attribute(AttrTypeLine, "");
|
||||
formula = domElement.attribute(AttrLength, "");
|
||||
basePointId = domElement.attribute(AttrBasePoint, "").toUInt();
|
||||
angle = domElement.attribute(AttrAngle, "").toInt();
|
||||
angle = domElement.attribute(AttrAngle, "").toDouble();
|
||||
}
|
||||
RefreshGeometry();
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
|
||||
const QString VToolPoint::TagName = QStringLiteral("point");
|
||||
|
||||
#define DefRadius 2.0//mm
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief VToolPoint constructor.
|
||||
|
@ -44,9 +42,9 @@ const QString VToolPoint::TagName = QStringLiteral("point");
|
|||
* @param parent parent object.
|
||||
*/
|
||||
VToolPoint::VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent):VDrawTool(doc, data, id),
|
||||
QGraphicsEllipseItem(parent), radius(DefRadius), namePoint(0), lineName(0)
|
||||
QGraphicsEllipseItem(parent), radius(DefPointRadius), namePoint(0), lineName(0)
|
||||
{
|
||||
radius = (DefRadius/*mm*/ / 25.4) * VApplication::PrintDPI;
|
||||
radius = (DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI;
|
||||
namePoint = new VGraphicsSimpleTextItem(this);
|
||||
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::ShowContextMenu);
|
||||
namePoint->setBrush(Qt::black);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
|
||||
:QObject(), QGraphicsLineItem(parent), data(data), factor(VDrawTool::factor), scenePos(QPointF()),
|
||||
color(Qt::red), lineStyle(Qt::SolidLine)
|
||||
color(Qt::red), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString())
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -52,6 +52,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));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -59,4 +60,33 @@ void VisLine::MousePos(const QPointF &scenePos)
|
|||
{
|
||||
this->scenePos = scenePos;
|
||||
RefreshGeometry();
|
||||
emit ToolTip(toolTip);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::setColor(const QColor &value)
|
||||
{
|
||||
color = value;
|
||||
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::setScenePos(const QPointF &value)
|
||||
{
|
||||
scenePos = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
|
||||
{
|
||||
this->color = Qt::black;
|
||||
this->point1Id = pointId;
|
||||
this->scenePos = scenePos;
|
||||
RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::setPoint1Id(const quint32 &value)
|
||||
{
|
||||
point1Id = value;
|
||||
}
|
||||
|
|
|
@ -42,8 +42,14 @@ public:
|
|||
VisLine(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
virtual ~VisLine();
|
||||
|
||||
void setPoint1Id(const quint32 &value);
|
||||
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);
|
||||
signals:
|
||||
void ToolTip(const QString &toolTip);
|
||||
public slots:
|
||||
void SetFactor(qreal factor);
|
||||
void MousePos(const QPointF &scenePos);
|
||||
|
@ -53,6 +59,8 @@ protected:
|
|||
QPointF scenePos;
|
||||
QColor color;
|
||||
Qt::PenStyle lineStyle;
|
||||
quint32 point1Id;
|
||||
QString toolTip;
|
||||
private:
|
||||
Q_DISABLE_COPY(VisLine)
|
||||
};
|
||||
|
|
191
src/app/visualization/vistoolendline.cpp
Normal file
191
src/app/visualization/vistoolendline.cpp
Normal file
|
@ -0,0 +1,191 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolendline.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 21 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 "vistoolendline.h"
|
||||
#include "../geometry/vpointf.h"
|
||||
#include "../container/vcontainer.h"
|
||||
#include "../widgets/vapplication.h"
|
||||
#include "../tools/vabstracttool.h"
|
||||
#include "../container/calculator.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QtMath>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
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
|
||||
|
||||
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 = (DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI;
|
||||
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
|
||||
rec.translate(-rec.center().x(), -rec.center().y());
|
||||
point->setRect(rec);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolEndLine::~VisToolEndLine()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolEndLine::RefreshGeometry()
|
||||
{
|
||||
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
|
||||
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
QLineF line;
|
||||
if (qFuzzyCompare(1 + length, 1 + 0))
|
||||
{
|
||||
QGraphicsScene *sc = this->scene();
|
||||
QPointF second;
|
||||
if(sc == nullptr)
|
||||
{
|
||||
second = scenePos;
|
||||
}
|
||||
else
|
||||
{
|
||||
line = QLineF(first->toQPointF(), scenePos);
|
||||
QRectF scRect = sc->sceneRect();
|
||||
qreal diagonal = sqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2));
|
||||
line.setLength(diagonal);
|
||||
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
|
||||
{
|
||||
line.setAngle(CorrectAngle(line.angle()));
|
||||
}
|
||||
second = VAbstractTool::LineIntersectRect(scRect, line);
|
||||
}
|
||||
line = QLineF(first->toQPointF(), second);
|
||||
}
|
||||
else
|
||||
{
|
||||
line = QLineF();
|
||||
line.setP1(first->toQPointF());
|
||||
line.setLength(qApp->toPixel(length));
|
||||
line.setAngle(angle);
|
||||
|
||||
point->setPos(line.p2());
|
||||
point->setVisible(true);
|
||||
point->setPen(QPen(color, 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, "
|
||||
"<b>Enter</b> - finish creation")).arg(this->line().angle());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolEndLine::VisualMode(const quint32 &pointId, const QPointF &scenePos)
|
||||
{
|
||||
this->color = Qt::black;
|
||||
this->point1Id = pointId;
|
||||
this->scenePos = scenePos;
|
||||
RefreshGeometry();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VisToolEndLine::Angle() const
|
||||
{
|
||||
return this->line().angle();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VisToolEndLine::CorrectAngle(const qreal &angle) const
|
||||
{
|
||||
qreal ang = angle;
|
||||
if (angle > 360)
|
||||
{
|
||||
ang = angle - 360 * qFloor(angle/360);
|
||||
}
|
||||
|
||||
switch(qFloor((qAbs(ang)+22.5)/45))
|
||||
{
|
||||
case 0: // <22.5
|
||||
return 0;
|
||||
case 1: // <67.5
|
||||
return 45;
|
||||
case 2: // <112.5
|
||||
return 90;
|
||||
case 3: // <157.5
|
||||
return 135;
|
||||
case 4: // <202.5
|
||||
return 180;
|
||||
case 5: // <247.5
|
||||
return 225;
|
||||
case 6: // < 292.5
|
||||
return 270;
|
||||
case 7: // <337.5
|
||||
return 315;
|
||||
default: // <360
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolEndLine::setAngle(const qreal &value)
|
||||
{
|
||||
angle = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolEndLine::setLength(const VContainer *data, 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"
|
||||
<< "--------------------------------------";
|
||||
}
|
||||
}
|
||||
}
|
56
src/app/visualization/vistoolendline.h
Normal file
56
src/app/visualization/vistoolendline.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vistoolendline.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 21 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 VISTOOLENDLINE_H
|
||||
#define VISTOOLENDLINE_H
|
||||
|
||||
#include "visline.h"
|
||||
|
||||
class QGraphicsEllipseItem;
|
||||
|
||||
class VisToolEndLine : public VisLine
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VisToolEndLine(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
virtual ~VisToolEndLine();
|
||||
|
||||
virtual void RefreshGeometry();
|
||||
void VisualMode(const quint32 &pointId, const QPointF &scenePos);
|
||||
qreal Angle() const;
|
||||
void setAngle(const qreal &value);
|
||||
void setLength(const VContainer *data, const QString &expression);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisToolEndLine)
|
||||
qreal CorrectAngle(const qreal &angle) const;
|
||||
qreal length;
|
||||
qreal angle;
|
||||
QGraphicsEllipseItem *point;
|
||||
};
|
||||
|
||||
#endif // VISTOOLENDLINE_H
|
|
@ -34,37 +34,15 @@
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent)
|
||||
:VisLine(data, parent), point1Id(0), point2Id(0)
|
||||
:VisLine(data, parent), point2Id(0)
|
||||
{
|
||||
this->color = Qt::red;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolLine::VisToolLine(const VContainer *data, const quint32 &pointId, const QPointF &scenePos,
|
||||
QGraphicsItem *parent)
|
||||
:VisLine(data, parent), point1Id(pointId), point2Id(0)
|
||||
{
|
||||
this->color = Qt::black;
|
||||
this->scenePos = scenePos;
|
||||
RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VisToolLine::~VisToolLine()
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolLine::setPoint2Id(const quint32 &value)
|
||||
{
|
||||
point2Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolLine::setPoint1Id(const quint32 &value)
|
||||
{
|
||||
point1Id = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolLine::RefreshGeometry()
|
||||
{
|
||||
|
@ -80,3 +58,9 @@ void VisToolLine::RefreshGeometry()
|
|||
}
|
||||
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolLine::setPoint2Id(const quint32 &value)
|
||||
{
|
||||
point2Id = value;
|
||||
}
|
||||
|
|
|
@ -36,16 +36,12 @@ class VisToolLine : public VisLine
|
|||
Q_OBJECT
|
||||
public:
|
||||
VisToolLine(const VContainer *data, QGraphicsItem *parent = 0);
|
||||
VisToolLine(const VContainer *data, const quint32 &pointId, const QPointF &scenePos,
|
||||
QGraphicsItem * parent = 0);
|
||||
virtual ~VisToolLine();
|
||||
|
||||
void setPoint1Id(const quint32 &value);
|
||||
void setPoint2Id(const quint32 &value);
|
||||
virtual void RefreshGeometry();
|
||||
void setPoint2Id(const quint32 &value);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisToolLine)
|
||||
quint32 point1Id;
|
||||
quint32 point2Id;
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ HEADERS += \
|
|||
visualization/vsimplesplinepath.h \
|
||||
visualization/vsimplecurve.h \
|
||||
visualization/visline.h \
|
||||
visualization/vistoolline.h
|
||||
visualization/vistoolline.h \
|
||||
visualization/vistoolendline.h
|
||||
|
||||
SOURCES += \
|
||||
visualization/vgraphicssimpletextitem.cpp \
|
||||
|
@ -12,4 +13,5 @@ SOURCES += \
|
|||
visualization/vsimplesplinepath.cpp \
|
||||
visualization/vsimplecurve.cpp \
|
||||
visualization/visline.cpp \
|
||||
visualization/vistoolline.cpp
|
||||
visualization/vistoolline.cpp \
|
||||
visualization/vistoolendline.cpp
|
||||
|
|
|
@ -45,6 +45,7 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
|
|||
this->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
this->setInteractive(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -192,13 +193,12 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress)
|
|||
{
|
||||
case Qt::ControlModifier:
|
||||
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
QGraphicsView::mousePressEvent(mousePress);
|
||||
break;
|
||||
default:
|
||||
QGraphicsView::mousePressEvent(mousePress);
|
||||
break;
|
||||
}
|
||||
}
|
||||
QGraphicsView::mousePressEvent(mousePress);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -210,4 +210,8 @@ void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event)
|
|||
{
|
||||
QGraphicsView::mouseReleaseEvent ( event );
|
||||
QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag );
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
emit MouseRelease();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,12 @@ signals:
|
|||
* @param factor scene scale factor.
|
||||
*/
|
||||
void NewFactor(qreal factor);
|
||||
/**
|
||||
* @brief MouseRelease help catch mouse release event.
|
||||
*
|
||||
* Usefull when you need show dialog after working with tool visualization.
|
||||
*/
|
||||
void MouseRelease();
|
||||
public slots:
|
||||
void scalingTime(qreal x);
|
||||
void scrollingTime(qreal x);
|
||||
|
|
|
@ -668,6 +668,9 @@ bool VPattern::SaveDocument(const QString &fileName)
|
|||
*/
|
||||
void VPattern::LiteParseTree()
|
||||
{
|
||||
// Save name current pattern piece
|
||||
QString namePP = nameActivPP;
|
||||
|
||||
try
|
||||
{
|
||||
emit SetEnabledGUI(true);
|
||||
|
@ -725,6 +728,8 @@ void VPattern::LiteParseTree()
|
|||
return;
|
||||
}
|
||||
|
||||
// Restore name current pattern piece
|
||||
nameActivPP = namePP;
|
||||
setCurrentData();
|
||||
emit FullUpdateFromFile();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user