From 3953d6fb22480e8e9270eeee1eb72296040dd16e Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 23 Jul 2014 11:56:32 +0300 Subject: [PATCH] Visualization for VToolEndLine. --HG-- branch : develop --- src/app/dialogs/tools/dialogendline.cpp | 87 ++++++++++- src/app/dialogs/tools/dialogendline.h | 13 +- src/app/dialogs/tools/dialogendline.ui | 21 ++- src/app/dialogs/tools/dialogline.cpp | 9 +- src/app/dialogs/tools/dialogline.h | 2 +- src/app/dialogs/tools/dialogtool.cpp | 12 ++ src/app/dialogs/tools/dialogtool.h | 7 +- src/app/mainwindow.cpp | 23 +++ src/app/mainwindow.h | 11 +- src/app/options.h | 1 + src/app/tools/drawTools/vtoolendline.cpp | 2 +- src/app/tools/drawTools/vtoolpoint.cpp | 6 +- src/app/visualization/visline.cpp | 32 +++- src/app/visualization/visline.h | 8 + src/app/visualization/vistoolendline.cpp | 191 +++++++++++++++++++++++ src/app/visualization/vistoolendline.h | 56 +++++++ src/app/visualization/vistoolline.cpp | 30 +--- src/app/visualization/vistoolline.h | 8 +- src/app/visualization/visualization.pri | 6 +- src/app/widgets/vmaingraphicsview.cpp | 8 +- src/app/widgets/vmaingraphicsview.h | 6 + src/app/xml/vpattern.cpp | 5 + 22 files changed, 482 insertions(+), 62 deletions(-) create mode 100644 src/app/visualization/vistoolendline.cpp create mode 100644 src/app/visualization/vistoolendline.h diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 2d6b3a2c8..4d84ba70b 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -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 (type == SceneObject::Point) + if (prepare == false)// After first choose we ignore all objects { - const VPointF *point = data->GeometricObject(id); - ChangeCurrentText(ui->comboBoxBasePoint, point->name()); - emit ToolTip(""); - this->setModal(true); - this->show(); + if (type == SceneObject::Point) + { + const VPointF *point = data->GeometricObject(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(""); + 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(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; } diff --git a/src/app/dialogs/tools/dialogendline.h b/src/app/dialogs/tools/dialogendline.h index b462cd128..d986a4d6e 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -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) @@ -94,10 +99,16 @@ private: qreal angle; /** @brief basePointId id base point of line */ - quint32 basePointId; + 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 */ diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 9db253c80..87d667548 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -319,8 +319,14 @@ QLayout::SetMinimumSize + + 0 + + + 0 + - 29 + 28 6 @@ -393,7 +399,7 @@ - + @@ -416,7 +422,7 @@ - + ... @@ -467,17 +473,17 @@ - + - + 0 0 - 57 + 72 0 @@ -487,6 +493,9 @@ 360.000000000000000 + + 360.000000000000000 + diff --git a/src/app/dialogs/tools/dialogline.cpp b/src/app/dialogs/tools/dialogline.cpp index 1acb37ef8..3ce595cd1 100644 --- a/src/app/dialogs/tools/dialogline.cpp +++ b/src/app/dialogs/tools/dialogline.cpp @@ -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(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); diff --git a/src/app/dialogs/tools/dialogline.h b/src/app/dialogs/tools/dialogline.h index 5f266f3f2..0be7ca272 100644 --- a/src/app/dialogs/tools/dialogline.h +++ b/src/app/dialogs/tools/dialogline.h @@ -84,7 +84,7 @@ private: /** @brief typeLine type of line */ QString typeLine; - VisToolLine *line; + VisToolLine *line; /** * @brief SaveData Put dialog data in local variables */ diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 7dcb8ca03..9f2f9bca5 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -1081,3 +1081,15 @@ void DialogTool::DialogApply() { } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::ShowVisToolTip(const QString &toolTip) +{ + emit ToolTip(toolTip); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::ShowDialog(bool click) +{ + Q_UNUSED(click); +} diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 6105c1428..dd73ec852 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -57,8 +57,9 @@ class DialogTool : public QDialog public: DialogTool(const VContainer *data, QWidget *parent = nullptr); virtual ~DialogTool() {} - VAbstractTool* GetAssociatedTool(); - void SetAssociatedTool(VAbstractTool* tool); + 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) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 1aa1fa82d..207496c20 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -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(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); + } +} diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 87ed9beac..6a5107336 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -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 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 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 diff --git a/src/app/options.h b/src/app/options.h index 46a4011b1..7dee201cb 100644 --- a/src/app/options.h +++ b/src/app/options.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 diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 7d5e060ea..0fe997ebd 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -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(); } diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 7f967652f..5760b86cc 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -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); diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index e857925ec..ffc9f8999 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -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; } diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index 39ef9f132..b8de6d7ea 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -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) }; diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp new file mode 100644 index 000000000..ad729930b --- /dev/null +++ b/src/app/visualization/vistoolendline.cpp @@ -0,0 +1,191 @@ +/************************************************************************ + ** + ** @file vistoolendline.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#include "vistoolendline.h" +#include "../geometry/vpointf.h" +#include "../container/vcontainer.h" +#include "../widgets/vapplication.h" +#include "../tools/vabstracttool.h" +#include "../container/calculator.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +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(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("Point at distance and angle: angle = %1°; Shift - sticking angle, " + "Enter - 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" + << "--------------------------------------"; + } + } +} diff --git a/src/app/visualization/vistoolendline.h b/src/app/visualization/vistoolendline.h new file mode 100644 index 000000000..a0a5cbda7 --- /dev/null +++ b/src/app/visualization/vistoolendline.h @@ -0,0 +1,56 @@ +/************************************************************************ + ** + ** @file vistoolendline.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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 diff --git a/src/app/visualization/vistoolline.cpp b/src/app/visualization/vistoolline.cpp index ecda8e0d7..d5407614a 100644 --- a/src/app/visualization/vistoolline.cpp +++ b/src/app/visualization/vistoolline.cpp @@ -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; +} diff --git a/src/app/visualization/vistoolline.h b/src/app/visualization/vistoolline.h index d3341354f..d28e6be49 100644 --- a/src/app/visualization/vistoolline.h +++ b/src/app/visualization/vistoolline.h @@ -36,17 +36,13 @@ 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; + quint32 point2Id; }; #endif // VGRAPHICSLINEITEM_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 8cd8463ca..98e2d68d7 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -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 diff --git a/src/app/widgets/vmaingraphicsview.cpp b/src/app/widgets/vmaingraphicsview.cpp index 04d5f850d..04bc465d6 100644 --- a/src/app/widgets/vmaingraphicsview.cpp +++ b/src/app/widgets/vmaingraphicsview.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(); + } } diff --git a/src/app/widgets/vmaingraphicsview.h b/src/app/widgets/vmaingraphicsview.h index d67981bf9..531fec782 100644 --- a/src/app/widgets/vmaingraphicsview.h +++ b/src/app/widgets/vmaingraphicsview.h @@ -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); diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 114196813..98b1c4ce2 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -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(); }