Visualization for VToolEndLine.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-23 11:56:32 +03:00
parent 6d0029324b
commit 3953d6fb22
22 changed files with 482 additions and 62 deletions

View file

@ -31,6 +31,9 @@
#include "../../geometry/vpointf.h" #include "../../geometry/vpointf.h"
#include "../../container/vcontainer.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) DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent)
:DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), formula(QString()), :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); ui->setupUi(this);
InitVariables(ui); InitVariables(ui);
@ -64,6 +67,8 @@ DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent)
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit); 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) void DialogEndLine::ChosenObject(quint32 id, const SceneObject &type)
{ {
if (type == SceneObject::Point) if (prepare == false)// After first choose we ignore all objects
{ {
const VPointF *point = data->GeometricObject<const VPointF *>(id); if (type == SceneObject::Point)
ChangeCurrentText(ui->comboBoxBasePoint, point->name()); {
emit ToolTip(""); const VPointF *point = data->GeometricObject<const VPointF *>(id);
this->setModal(true); basePointId = id;
this->show(); 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("");
prepare = true;
}
} }
} }
@ -116,6 +133,7 @@ void DialogEndLine::setTypeLine(const QString &value)
{ {
typeLine = value; typeLine = value;
SetupTypeLine(ui->comboBoxLineType, value); SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -133,6 +151,7 @@ void DialogEndLine::setFormula(const QString &value)
this->DeployFormulaTextEdit(); this->DeployFormulaTextEdit();
} }
ui->plainTextEditFormula->setPlainText(formula); ui->plainTextEditFormula->setPlainText(formula);
line->setLength(data, formula);
//QTextCursor cursor = ui->plainTextEditFormula->textCursor(); //QTextCursor cursor = ui->plainTextEditFormula->textCursor();
//cursor.insertText(value); //cursor.insertText(value);
//ui->plainTextEditFormula->setCursor(cursor); //ui->plainTextEditFormula->setCursor(cursor);
@ -147,6 +166,7 @@ void DialogEndLine::setAngle(const qreal &value)
{ {
angle = value; angle = value;
ui->doubleSpinBoxAngle->setValue(angle); 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) void DialogEndLine::setBasePointId(const quint32 &value, const quint32 &id)
{ {
setCurrentPointId(ui->comboBoxBasePoint, basePointId, value, 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", " "); formula.replace("\n", " ");
angle = ui->doubleSpinBoxAngle->value(); angle = ui->doubleSpinBoxAngle->value();
basePointId = getCurrentObjectId(ui->comboBoxBasePoint); basePointId = getCurrentObjectId(ui->comboBoxBasePoint);
line->setPoint1Id(basePointId);
line->setLength(data, formula);
line->setAngle(angle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogEndLine::~DialogEndLine() DialogEndLine::~DialogEndLine()
{ {
delete line;
delete ui; delete ui;
} }

View file

@ -36,6 +36,8 @@ namespace Ui
class DialogEndLine; class DialogEndLine;
} }
class VisToolEndLine;
/** /**
* @brief The DialogEndLine class dialog for ToolEndLine. Help create point and edit option. * @brief The DialogEndLine class dialog for ToolEndLine. Help create point and edit option.
*/ */
@ -60,6 +62,7 @@ public:
quint32 getBasePointId() const; quint32 getBasePointId() const;
void setBasePointId(const quint32 &value, const quint32 &id); void setBasePointId(const quint32 &value, const quint32 &id);
virtual void ShowDialog(bool click);
public slots: public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type); virtual void ChosenObject(quint32 id, const SceneObject &type);
virtual void DialogAccepted(); virtual void DialogAccepted();
@ -75,6 +78,8 @@ public slots:
* @brief FormulaTextChanged when formula text changes for validation and calc * @brief FormulaTextChanged when formula text changes for validation and calc
*/ */
void FormulaTextChanged(); void FormulaTextChanged();
protected:
virtual void ShowVisualization();
private: private:
Q_DISABLE_COPY(DialogEndLine) Q_DISABLE_COPY(DialogEndLine)
@ -94,10 +99,16 @@ private:
qreal angle; qreal angle;
/** @brief basePointId id base point of line */ /** @brief basePointId id base point of line */
quint32 basePointId; quint32 basePointId;
/** @brief formulaBaseHeight base height defined by dialogui */ /** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight; 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 * @brief SaveData Put dialog data in local variables
*/ */

View file

@ -319,8 +319,14 @@
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum> <enum>QLayout::SetMinimumSize</enum>
</property> </property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="horizontalSpacing"> <property name="horizontalSpacing">
<number>29</number> <number>28</number>
</property> </property>
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>6</number> <number>6</number>
@ -393,7 +399,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1" alignment="Qt::AlignHCenter">
<widget class="QToolButton" name="toolButtonArrowUp"> <widget class="QToolButton" name="toolButtonArrowUp">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -416,7 +422,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1" alignment="Qt::AlignHCenter">
<widget class="QToolButton" name="toolButtonArrowDown"> <widget class="QToolButton" name="toolButtonArrowDown">
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
@ -467,17 +473,17 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1" alignment="Qt::AlignHCenter">
<widget class="QDoubleSpinBox" name="doubleSpinBoxAngle"> <widget class="QDoubleSpinBox" name="doubleSpinBoxAngle">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>57</width> <width>72</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -487,6 +493,9 @@
<property name="maximum"> <property name="maximum">
<double>360.000000000000000</double> <double>360.000000000000000</double>
</property> </property>
<property name="value">
<double>360.000000000000000</double>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

View file

@ -118,8 +118,6 @@ void DialogLine::DialogAccepted()
void DialogLine::DialogApply() void DialogLine::DialogApply()
{ {
this->SaveData(); this->SaveData();
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry();
emit DialogApplied(); emit DialogApplied();
} }
@ -168,6 +166,11 @@ void DialogLine::SaveData()
index = ui->comboBoxSecondPoint->currentIndex(); index = ui->comboBoxSecondPoint->currentIndex();
secondPoint = qvariant_cast<quint32>(ui->comboBoxSecondPoint->itemData(index)); secondPoint = qvariant_cast<quint32>(ui->comboBoxSecondPoint->itemData(index));
typeLine = GetTypeLine(ui->comboBoxLineType); 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 { // -1 for not found
VMainGraphicsScene *scene = qApp->getCurrentScene(); VMainGraphicsScene *scene = qApp->getCurrentScene();
line = new VisToolLine(data, id, scene->getScenePos()); line->VisualMode(id, scene->getScenePos());
scene->addItem(line); scene->addItem(line);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor); connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolLine::MousePos); connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolLine::MousePos);

View file

@ -84,7 +84,7 @@ private:
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;
VisToolLine *line; VisToolLine *line;
/** /**
* @brief SaveData Put dialog data in local variables * @brief SaveData Put dialog data in local variables
*/ */

View file

@ -1081,3 +1081,15 @@ void DialogTool::DialogApply()
{ {
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::ShowVisToolTip(const QString &toolTip)
{
emit ToolTip(toolTip);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::ShowDialog(bool click)
{
Q_UNUSED(click);
}

View file

@ -57,8 +57,9 @@ class DialogTool : public QDialog
public: public:
DialogTool(const VContainer *data, QWidget *parent = nullptr); DialogTool(const VContainer *data, QWidget *parent = nullptr);
virtual ~DialogTool() {} virtual ~DialogTool() {}
VAbstractTool* GetAssociatedTool(); VAbstractTool* GetAssociatedTool();
void SetAssociatedTool(VAbstractTool* tool); void SetAssociatedTool(VAbstractTool* tool);
virtual void ShowDialog(bool click);
signals: signals:
/** /**
* @brief DialogClosed signal dialog closed * @brief DialogClosed signal dialog closed
@ -75,6 +76,7 @@ signals:
*/ */
void ToolTip(const QString &toolTip); void ToolTip(const QString &toolTip);
public slots: public slots:
void ShowVisToolTip(const QString &toolTip);
virtual void ChosenObject(quint32 id, const SceneObject &type); virtual void ChosenObject(quint32 id, const SceneObject &type);
void NamePointChanged(); void NamePointChanged();
virtual void DialogAccepted(); virtual void DialogAccepted();
@ -108,6 +110,7 @@ public slots:
virtual void ValChenged(int row); virtual void ValChenged(int row);
virtual void UpdateList(); virtual void UpdateList();
virtual void PointNameChanged(){} virtual void PointNameChanged(){}
protected: protected:
Q_DISABLE_COPY(DialogTool) Q_DISABLE_COPY(DialogTool)

View file

@ -302,6 +302,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot); connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot);
connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
connect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); connect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList);
connect(view, &VMainGraphicsView::MouseRelease, this, &MainWindow::ClickEndVisualization);
} }
else else
{ {
@ -377,6 +378,7 @@ void MainWindow::ApplyDialog()
else else
{ // Or update associated tool with data { // Or update associated tool with data
VDrawTool * vtool= static_cast<VDrawTool *>(dialogTool->GetAssociatedTool()); VDrawTool * vtool= static_cast<VDrawTool *>(dialogTool->GetAssociatedTool());
SCASSERT(vtool != nullptr);
vtool->FullUpdateFromGuiApply(); vtool->FullUpdateFromGuiApply();
} }
} }
@ -1284,6 +1286,12 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
case Qt::Key_Escape: case Qt::Key_Escape:
ArrowTool(); ArrowTool();
break; break;
case Qt::Key_Return:
EndVisualization();
break;
case Qt::Key_Enter:
EndVisualization();
break;
default: default:
break; break;
} }
@ -1660,6 +1668,12 @@ void MainWindow::SetEnabledGUI(bool enabled)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ClickEndVisualization()
{
EndVisualization(true);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief NewPattern create new empty pattern. * @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);
}
}

View file

@ -144,6 +144,7 @@ public slots:
void EditPatternCode(); void EditPatternCode();
void FullParseFile(); void FullParseFile();
void SetEnabledGUI(bool enabled); void SetEnabledGUI(bool enabled);
void ClickEndVisualization();
signals: signals:
/** /**
* @brief ModelChosen emit after calculation all details. * @brief ModelChosen emit after calculation all details.
@ -152,9 +153,9 @@ signals:
*/ */
void ModelChosen(QVector<VItem*> listDetails, const QString &curFile, const QString &description); void ModelChosen(QVector<VItem*> listDetails, const QString &curFile, const QString &description);
protected: protected:
virtual void keyPressEvent ( QKeyEvent * event ); virtual void keyPressEvent(QKeyEvent *event);
virtual void showEvent( QShowEvent *event ); virtual void showEvent(QShowEvent *event);
virtual void closeEvent( QCloseEvent * event ); virtual void closeEvent(QCloseEvent *event);
virtual void customEvent(QEvent * event); virtual void customEvent(QEvent * event);
private: private:
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
@ -259,6 +260,10 @@ private:
template <typename Func> template <typename Func>
void SetGradationList(const QString &label, const QStringList &list, Func changeSlot); void SetGradationList(const QString &label, const QStringList &list, Func changeSlot);
void ChangePP(int index , bool zoomBestFit = true); 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 #endif // MAINWINDOW_H

View file

@ -38,6 +38,7 @@
class QString; class QString;
#define SceneSize 50000 #define SceneSize 50000
#define DefPointRadius 2.0//mm
enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail }; enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail };
enum class Tool : char enum class Tool : char

View file

@ -183,7 +183,7 @@ void VToolEndLine::FullUpdateFromFile()
typeLine = domElement.attribute(AttrTypeLine, ""); typeLine = domElement.attribute(AttrTypeLine, "");
formula = domElement.attribute(AttrLength, ""); formula = domElement.attribute(AttrLength, "");
basePointId = domElement.attribute(AttrBasePoint, "").toUInt(); basePointId = domElement.attribute(AttrBasePoint, "").toUInt();
angle = domElement.attribute(AttrAngle, "").toInt(); angle = domElement.attribute(AttrAngle, "").toDouble();
} }
RefreshGeometry(); RefreshGeometry();
} }

View file

@ -33,8 +33,6 @@
const QString VToolPoint::TagName = QStringLiteral("point"); const QString VToolPoint::TagName = QStringLiteral("point");
#define DefRadius 2.0//mm
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VToolPoint constructor. * @brief VToolPoint constructor.
@ -44,9 +42,9 @@ const QString VToolPoint::TagName = QStringLiteral("point");
* @param parent parent object. * @param parent parent object.
*/ */
VToolPoint::VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent):VDrawTool(doc, data, id), 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); namePoint = new VGraphicsSimpleTextItem(this);
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::ShowContextMenu); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::ShowContextMenu);
namePoint->setBrush(Qt::black); namePoint->setBrush(Qt::black);

View file

@ -34,7 +34,7 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisLine::VisLine(const VContainer *data, QGraphicsItem *parent) VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
:QObject(), QGraphicsLineItem(parent), data(data), factor(VDrawTool::factor), scenePos(QPointF()), :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) void VisLine::setLineStyle(const Qt::PenStyle &value)
{ {
lineStyle = 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; this->scenePos = scenePos;
RefreshGeometry(); 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;
} }

View file

@ -42,8 +42,14 @@ public:
VisLine(const VContainer *data, QGraphicsItem *parent = 0); VisLine(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisLine(); virtual ~VisLine();
void setPoint1Id(const quint32 &value);
void setLineStyle(const Qt::PenStyle &value); void setLineStyle(const Qt::PenStyle &value);
virtual void RefreshGeometry()=0; 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: public slots:
void SetFactor(qreal factor); void SetFactor(qreal factor);
void MousePos(const QPointF &scenePos); void MousePos(const QPointF &scenePos);
@ -53,6 +59,8 @@ protected:
QPointF scenePos; QPointF scenePos;
QColor color; QColor color;
Qt::PenStyle lineStyle; Qt::PenStyle lineStyle;
quint32 point1Id;
QString toolTip;
private: private:
Q_DISABLE_COPY(VisLine) Q_DISABLE_COPY(VisLine)
}; };

View 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"
<< "--------------------------------------";
}
}
}

View 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

View file

@ -34,37 +34,15 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent) VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent)
:VisLine(data, parent), point1Id(0), point2Id(0) :VisLine(data, parent), point2Id(0)
{ {
this->color = Qt::red; 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() VisToolLine::~VisToolLine()
{} {}
//---------------------------------------------------------------------------------------------------------------------
void VisToolLine::setPoint2Id(const quint32 &value)
{
point2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisToolLine::setPoint1Id(const quint32 &value)
{
point1Id = value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VisToolLine::RefreshGeometry() void VisToolLine::RefreshGeometry()
{ {
@ -80,3 +58,9 @@ void VisToolLine::RefreshGeometry()
} }
this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); this->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
} }
//---------------------------------------------------------------------------------------------------------------------
void VisToolLine::setPoint2Id(const quint32 &value)
{
point2Id = value;
}

View file

@ -36,17 +36,13 @@ class VisToolLine : public VisLine
Q_OBJECT Q_OBJECT
public: public:
VisToolLine(const VContainer *data, QGraphicsItem *parent = 0); VisToolLine(const VContainer *data, QGraphicsItem *parent = 0);
VisToolLine(const VContainer *data, const quint32 &pointId, const QPointF &scenePos,
QGraphicsItem * parent = 0);
virtual ~VisToolLine(); virtual ~VisToolLine();
void setPoint1Id(const quint32 &value);
void setPoint2Id(const quint32 &value);
virtual void RefreshGeometry(); virtual void RefreshGeometry();
void setPoint2Id(const quint32 &value);
private: private:
Q_DISABLE_COPY(VisToolLine) Q_DISABLE_COPY(VisToolLine)
quint32 point1Id; quint32 point2Id;
quint32 point2Id;
}; };
#endif // VGRAPHICSLINEITEM_H #endif // VGRAPHICSLINEITEM_H

View file

@ -4,7 +4,8 @@ HEADERS += \
visualization/vsimplesplinepath.h \ visualization/vsimplesplinepath.h \
visualization/vsimplecurve.h \ visualization/vsimplecurve.h \
visualization/visline.h \ visualization/visline.h \
visualization/vistoolline.h visualization/vistoolline.h \
visualization/vistoolendline.h
SOURCES += \ SOURCES += \
visualization/vgraphicssimpletextitem.cpp \ visualization/vgraphicssimpletextitem.cpp \
@ -12,4 +13,5 @@ SOURCES += \
visualization/vsimplesplinepath.cpp \ visualization/vsimplesplinepath.cpp \
visualization/vsimplecurve.cpp \ visualization/vsimplecurve.cpp \
visualization/visline.cpp \ visualization/visline.cpp \
visualization/vistoolline.cpp visualization/vistoolline.cpp \
visualization/vistoolendline.cpp

View file

@ -45,6 +45,7 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
this->setResizeAnchor(QGraphicsView::AnchorUnderMouse); this->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
this->setInteractive(true);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -192,13 +193,12 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress)
{ {
case Qt::ControlModifier: case Qt::ControlModifier:
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);
QGraphicsView::mousePressEvent(mousePress);
break; break;
default: default:
QGraphicsView::mousePressEvent(mousePress);
break; break;
} }
} }
QGraphicsView::mousePressEvent(mousePress);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -210,4 +210,8 @@ void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event)
{ {
QGraphicsView::mouseReleaseEvent ( event ); QGraphicsView::mouseReleaseEvent ( event );
QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag ); QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag );
if (event->button() == Qt::LeftButton)
{
emit MouseRelease();
}
} }

View file

@ -46,6 +46,12 @@ signals:
* @param factor scene scale factor. * @param factor scene scale factor.
*/ */
void NewFactor(qreal 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: public slots:
void scalingTime(qreal x); void scalingTime(qreal x);
void scrollingTime(qreal x); void scrollingTime(qreal x);

View file

@ -668,6 +668,9 @@ bool VPattern::SaveDocument(const QString &fileName)
*/ */
void VPattern::LiteParseTree() void VPattern::LiteParseTree()
{ {
// Save name current pattern piece
QString namePP = nameActivPP;
try try
{ {
emit SetEnabledGUI(true); emit SetEnabledGUI(true);
@ -725,6 +728,8 @@ void VPattern::LiteParseTree()
return; return;
} }
// Restore name current pattern piece
nameActivPP = namePP;
setCurrentData(); setCurrentData();
emit FullUpdateFromFile(); emit FullUpdateFromFile();
} }