From 198b73a40f97b3993da1bac81e74bbb677c2dd15 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 15 Aug 2014 13:48:11 +0300 Subject: [PATCH] Parent class for all visualizations. --HG-- branch : develop --- src/app/visualization/visline.cpp | 84 ++++------------ src/app/visualization/visline.h | 27 +----- src/app/visualization/vistoolalongline.cpp | 6 +- src/app/visualization/vistoolbisector.cpp | 10 +- src/app/visualization/vistoolendline.cpp | 6 +- src/app/visualization/vistoolheight.cpp | 10 +- src/app/visualization/vistoolline.cpp | 6 +- .../visualization/vistoollineintersect.cpp | 14 +-- src/app/visualization/vistoolnormal.cpp | 6 +- .../visualization/vistoolpointofcontact.cpp | 8 +- .../vistoolpointofintersection.cpp | 6 +- .../visualization/vistoolshoulderpoint.cpp | 10 +- src/app/visualization/vistooltriangle.cpp | 18 ++-- src/app/visualization/visualization.cpp | 97 +++++++++++++++++++ src/app/visualization/visualization.h | 85 ++++++++++++++++ src/app/visualization/visualization.pri | 6 +- 16 files changed, 258 insertions(+), 141 deletions(-) create mode 100644 src/app/visualization/visualization.cpp create mode 100644 src/app/visualization/visualization.h diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index 27cbf7ca9..216ded754 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -33,42 +33,16 @@ //--------------------------------------------------------------------------------------------------------------------- VisLine::VisLine(const VContainer *data, QGraphicsItem *parent) - :QObject(), QGraphicsLineItem(parent), data(data), factor(VDrawTool::factor), scenePos(QPointF()), - mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString()) + :Visualization(data), QGraphicsLineItem(parent) { this->setZValue(1);// Show on top real tool - this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); + InitPen(); } //--------------------------------------------------------------------------------------------------------------------- VisLine::~VisLine() {} -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::SetFactor(qreal factor) -{ - VApplication::CheckFactor(this->factor, factor); - RefreshGeometry(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::setLineStyle(const Qt::PenStyle &value) -{ - lineStyle = value; - this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::MousePos(const QPointF &scenePos) -{ - this->scenePos = scenePos; - RefreshGeometry(); - if (toolTip.isEmpty() == false) - { - emit ToolTip(toolTip); - } -} - //--------------------------------------------------------------------------------------------------------------------- QRectF VisLine::PointRect(const qreal &radius) { @@ -93,7 +67,7 @@ qreal VisLine::FindLength(const QString &expression) QString formula = expression; formula.replace("\n", " "); formula = qApp->FormulaFromUser(formula); - Calculator *cal = new Calculator(data); + Calculator *cal = new Calculator(Visualization::data); length = cal->EvalFormula(formula); delete cal; } @@ -127,7 +101,7 @@ qreal VisLine::FindVal(const QString &expression) QString formula = expression; formula.replace("\n", " "); formula = qApp->FormulaFromUser(formula); - Calculator *cal = new Calculator(data); + Calculator *cal = new Calculator(Visualization::data); val = cal->EvalFormula(formula); delete cal; } @@ -223,7 +197,7 @@ QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const { if(this->scene() == nullptr) { - QLineF line = QLineF(firstPoint, scenePos); + QLineF line = QLineF(firstPoint, Visualization::scenePos); line.setAngle(angle); return line.p2();// We can't find ray because item doesn't have scene. We will return cursor position on scene. } @@ -245,44 +219,10 @@ QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const //--------------------------------------------------------------------------------------------------------------------- QPointF VisLine::Ray(const QPointF &firstPoint) const { - QLineF line = QLineF(firstPoint, scenePos); + QLineF line = QLineF(firstPoint, Visualization::scenePos); return Ray(firstPoint, line.angle()); } -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::setMainColor(const QColor &value) -{ - mainColor = value; - this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::setScenePos(const QPointF &value) -{ - scenePos = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::VisualMode(const quint32 &pointId) -{ - VMainGraphicsScene *scene = qApp->getCurrentScene(); - SCASSERT(scene != nullptr); - - this->point1Id = pointId; - this->scenePos = scene->getScenePos(); - RefreshGeometry(); - - scene->addItem(this); - connect(scene, &VMainGraphicsScene::NewFactor, this, &VisLine::SetFactor); - connect(scene, &VMainGraphicsScene::mouseMove, this, &VisLine::MousePos); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::setPoint1Id(const quint32 &value) -{ - point1Id = value; -} - //--------------------------------------------------------------------------------------------------------------------- QLineF VisLine::Axis(const QPointF &p, const qreal &angle) const { @@ -297,3 +237,15 @@ QLineF VisLine::Axis(const QPointF &p1, const QPointF &p2) const QLineF line(p1, p2); return Axis(p1, line.angle()); } + +//--------------------------------------------------------------------------------------------------------------------- +void VisLine::InitPen() +{ + this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisLine::AddOnScene() +{ + AddItem(this); +} diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index 8b04ff72f..cc0d0db60 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -29,41 +29,20 @@ #ifndef VISLINE_H #define VISLINE_H -#include +#include "visualization.h" #include #include -#include "../widgets/vapplication.h" - class VContainer; -class VisLine: public QObject, public QGraphicsLineItem +class VisLine: public Visualization, public QGraphicsLineItem { Q_OBJECT 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); - void setMainColor(const QColor &value); -signals: - void ToolTip(const QString &toolTip); -public slots: - void SetFactor(qreal factor); - void MousePos(const QPointF &scenePos); protected: - const VContainer *data; - qreal factor; - QPointF scenePos; - QColor mainColor; - QColor supportColor; - Qt::PenStyle lineStyle; - quint32 point1Id; - QString toolTip; QRectF PointRect(const qreal &radius); qreal FindLength(const QString &expression); qreal FindVal(const QString &expression); @@ -89,6 +68,8 @@ protected: QPointF Ray(const QPointF &firstPoint) const; QLineF Axis(const QPointF &p, const qreal &angle) const; QLineF Axis(const QPointF &p1, const QPointF &p2) const; + virtual void InitPen(); + virtual void AddOnScene(); private: Q_DISABLE_COPY(VisLine) }; diff --git a/src/app/visualization/vistoolalongline.cpp b/src/app/visualization/vistoolalongline.cpp index 88d35c31f..2ceacbe2d 100644 --- a/src/app/visualization/vistoolalongline.cpp +++ b/src/app/visualization/vistoolalongline.cpp @@ -64,16 +64,16 @@ void VisToolAlongLine::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(lineP1, first->toQPointF(), supportColor); if (point2Id <= 0) { - DrawLine(line, QLineF(first->toQPointF(), scenePos), supportColor); + DrawLine(line, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *second = data->GeometricObject(point2Id); + const VPointF *second = Visualization::data->GeometricObject(point2Id); DrawPoint(lineP2, second->toQPointF(), supportColor); DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), supportColor); diff --git a/src/app/visualization/vistoolbisector.cpp b/src/app/visualization/vistoolbisector.cpp index c9f374aa9..bae67c682 100644 --- a/src/app/visualization/vistoolbisector.cpp +++ b/src/app/visualization/vistoolbisector.cpp @@ -73,27 +73,27 @@ void VisToolBisector::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(line1P1, first->toQPointF(), supportColor); if (point2Id <= 0) { - DrawLine(line1, QLineF(first->toQPointF(), scenePos), supportColor); + DrawLine(line1, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *second = data->GeometricObject(point2Id); + const VPointF *second = Visualization::data->GeometricObject(point2Id); DrawPoint(line1P2, second->toQPointF(), supportColor); DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); if (point3Id <= 0) { - DrawLine(line2, QLineF(second->toQPointF(), scenePos), supportColor); + DrawLine(line2, QLineF(second->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *third = data->GeometricObject(point3Id); + const VPointF *third = Visualization::data->GeometricObject(point3Id); DrawPoint(line2P2, third->toQPointF(), supportColor); DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp index dbd80ad7c..3195b07b8 100644 --- a/src/app/visualization/vistoolendline.cpp +++ b/src/app/visualization/vistoolendline.cpp @@ -50,7 +50,7 @@ VisToolEndLine::~VisToolEndLine() //--------------------------------------------------------------------------------------------------------------------- void VisToolEndLine::RefreshGeometry() { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); QLineF line; if (qFuzzyCompare(1 + length, 1 + 0)) { @@ -62,8 +62,8 @@ void VisToolEndLine::RefreshGeometry() DrawPoint(point, line.p2(), mainColor); } DrawLine(this, line, mainColor, lineStyle); - toolTip = QString(tr("Point at distance and angle: angle = %1°; Shift - sticking angle, " - "Enter - finish creation")).arg(this->line().angle()); + Visualization::toolTip = QString(tr("Point at distance and angle: angle = %1°; Shift - " + "sticking angle, Enter - finish creation")).arg(this->line().angle()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolheight.cpp b/src/app/visualization/vistoolheight.cpp index bde4a5c92..39b84c10a 100644 --- a/src/app/visualization/vistoolheight.cpp +++ b/src/app/visualization/vistoolheight.cpp @@ -53,27 +53,27 @@ void VisToolHeight::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(base_point, first->toQPointF(), supportColor); if (lineP1Id <= 0) { - DrawLine(this, QLineF(first->toQPointF(), scenePos), mainColor); + DrawLine(this, QLineF(first->toQPointF(), Visualization::scenePos), mainColor); } else { - const VPointF *second = data->GeometricObject(lineP1Id); + const VPointF *second = Visualization::data->GeometricObject(lineP1Id); DrawPoint(lineP1, second->toQPointF(), supportColor); QLineF base_line; if (lineP2Id <= 0) { - base_line = QLineF(second->toQPointF(), scenePos); + base_line = QLineF(second->toQPointF(), Visualization::scenePos); DrawLine(line, base_line, supportColor); } else { - const VPointF *third = data->GeometricObject(lineP2Id); + const VPointF *third = Visualization::data->GeometricObject(lineP2Id); DrawPoint(lineP2, third->toQPointF(), supportColor); base_line = QLineF(second->toQPointF(), third->toQPointF()); diff --git a/src/app/visualization/vistoolline.cpp b/src/app/visualization/vistoolline.cpp index 7732af60a..bcd14b4f5 100644 --- a/src/app/visualization/vistoolline.cpp +++ b/src/app/visualization/vistoolline.cpp @@ -46,14 +46,14 @@ VisToolLine::~VisToolLine() void VisToolLine::RefreshGeometry() { QLineF line; - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); if (point2Id == 0) { - line = QLineF(first->toQPointF(), scenePos); + line = QLineF(first->toQPointF(), Visualization::scenePos); } else { - const VPointF *second = data->GeometricObject(point2Id); + const VPointF *second = Visualization::data->GeometricObject(point2Id); line = QLineF(first->toQPointF(), second->toQPointF()); } DrawLine(this, line, mainColor, lineStyle); diff --git a/src/app/visualization/vistoollineintersect.cpp b/src/app/visualization/vistoollineintersect.cpp index 4743d092a..838bce2ed 100644 --- a/src/app/visualization/vistoollineintersect.cpp +++ b/src/app/visualization/vistoollineintersect.cpp @@ -54,16 +54,16 @@ void VisToolLineIntersect::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(line1P1, first->toQPointF(), supportColor); if (line1P2Id <= 0) { - DrawLine(line1, QLineF(first->toQPointF(), scenePos), supportColor); + DrawLine(line1, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *second = data->GeometricObject(line1P2Id); + const VPointF *second = Visualization::data->GeometricObject(line1P2Id); DrawPoint(line1P2, second->toQPointF(), supportColor); DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); @@ -74,15 +74,15 @@ void VisToolLineIntersect::RefreshGeometry() } else { - const VPointF *third = data->GeometricObject(line2P1Id); + const VPointF *third = Visualization::data->GeometricObject(line2P1Id); DrawPoint(line2P1, third->toQPointF(), supportColor); if (line2P2Id <= 0) { - DrawLine(this, QLineF(third->toQPointF(), scenePos), supportColor); + DrawLine(this, QLineF(third->toQPointF(), Visualization::scenePos), supportColor); QLineF l1(first->toQPointF(), second->toQPointF()); - QLineF l2(third->toQPointF(), scenePos); + QLineF l2(third->toQPointF(), Visualization::scenePos); QPointF fPoint; QLineF::IntersectType intersect = l1.intersect(l2, &fPoint); if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) @@ -92,7 +92,7 @@ void VisToolLineIntersect::RefreshGeometry() } else { - const VPointF *forth = data->GeometricObject(line2P2Id); + const VPointF *forth = Visualization::data->GeometricObject(line2P2Id); DrawPoint(line2P2, forth->toQPointF(), supportColor); DrawLine(this, QLineF(third->toQPointF(), forth->toQPointF()), supportColor); diff --git a/src/app/visualization/vistoolnormal.cpp b/src/app/visualization/vistoolnormal.cpp index 68f858759..a1b8ee4f3 100644 --- a/src/app/visualization/vistoolnormal.cpp +++ b/src/app/visualization/vistoolnormal.cpp @@ -53,12 +53,12 @@ void VisToolNormal::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(lineP1, first->toQPointF(), supportColor); if (point2Id <= 0) { - QLineF line_mouse(first->toQPointF(), scenePos); + QLineF line_mouse(first->toQPointF(), Visualization::scenePos); DrawLine(line, line_mouse, supportColor); QLineF normal = line_mouse.normalVector(); @@ -67,7 +67,7 @@ void VisToolNormal::RefreshGeometry() } else { - const VPointF *second = data->GeometricObject(point2Id); + const VPointF *second = Visualization::data->GeometricObject(point2Id); DrawPoint(lineP2, second->toQPointF(), supportColor); QLineF line_mouse(first->toQPointF(), second->toQPointF()); diff --git a/src/app/visualization/vistoolpointofcontact.cpp b/src/app/visualization/vistoolpointofcontact.cpp index 501e77d9e..f8468f058 100644 --- a/src/app/visualization/vistoolpointofcontact.cpp +++ b/src/app/visualization/vistoolpointofcontact.cpp @@ -52,16 +52,16 @@ void VisToolPointOfContact::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(lineP1, first->toQPointF(), supportColor); if (lineP2Id <= 0) { - DrawLine(this, QLineF(first->toQPointF(), scenePos), supportColor); + DrawLine(this, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *second = data->GeometricObject(lineP2Id); + const VPointF *second = Visualization::data->GeometricObject(lineP2Id); DrawPoint(lineP2, second->toQPointF(), supportColor); DrawLine(this, QLineF(first->toQPointF(), second->toQPointF()), supportColor); @@ -71,7 +71,7 @@ void VisToolPointOfContact::RefreshGeometry() } else { - const VPointF *third = data->GeometricObject(radiusId); + const VPointF *third = Visualization::data->GeometricObject(radiusId); DrawPoint(arc_point, third->toQPointF(), supportColor); if (qFuzzyCompare(1 + radius, 1 + 0) == false) diff --git a/src/app/visualization/vistoolpointofintersection.cpp b/src/app/visualization/vistoolpointofintersection.cpp index 397e7ed43..080bb31fe 100644 --- a/src/app/visualization/vistoolpointofintersection.cpp +++ b/src/app/visualization/vistoolpointofintersection.cpp @@ -50,7 +50,7 @@ void VisToolPointOfIntersection::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(axisP1, first->toQPointF(), supportColor); QLineF axisL1 = Axis(first->toQPointF(), 90); @@ -59,11 +59,11 @@ void VisToolPointOfIntersection::RefreshGeometry() QLineF axisL2; if (point2Id <= 0) { - axisL2 = Axis(scenePos, 180); + axisL2 = Axis(Visualization::scenePos, 180); } else { - const VPointF *second = data->GeometricObject(point2Id); + const VPointF *second = Visualization::data->GeometricObject(point2Id); DrawPoint(axisP2, second->toQPointF(), supportColor); axisL2 = Axis(second->toQPointF(), 180); ShowIntersection(axisL1, axisL2); diff --git a/src/app/visualization/vistoolshoulderpoint.cpp b/src/app/visualization/vistoolshoulderpoint.cpp index d2f866aee..fe7721e36 100644 --- a/src/app/visualization/vistoolshoulderpoint.cpp +++ b/src/app/visualization/vistoolshoulderpoint.cpp @@ -55,27 +55,27 @@ void VisToolShoulderPoint::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(line1P1, first->toQPointF(), supportColor); if (lineP1Id <= 0) { - DrawLine(line1, QLineF(first->toQPointF(), scenePos), supportColor); + DrawLine(line1, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *second = data->GeometricObject(lineP1Id); + const VPointF *second = Visualization::data->GeometricObject(lineP1Id); DrawPoint(line1P2, second->toQPointF(), supportColor); DrawLine(line1, QLineF(first->toQPointF(), second->toQPointF()), supportColor); if (lineP2Id <= 0) { - DrawLine(line2, QLineF(second->toQPointF(), scenePos), supportColor); + DrawLine(line2, QLineF(second->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *third = data->GeometricObject(lineP2Id); + const VPointF *third = Visualization::data->GeometricObject(lineP2Id); DrawPoint(line2P2, third->toQPointF(), supportColor); DrawLine(line2, QLineF(second->toQPointF(), third->toQPointF()), supportColor); diff --git a/src/app/visualization/vistooltriangle.cpp b/src/app/visualization/vistooltriangle.cpp index d86108c9e..1e580fbea 100644 --- a/src/app/visualization/vistooltriangle.cpp +++ b/src/app/visualization/vistooltriangle.cpp @@ -30,7 +30,7 @@ #include "../geometry/vpointf.h" #include "../container/vcontainer.h" #include "../tools/drawTools/vtooltriangle.h" -#include "QtMath" +#include //--------------------------------------------------------------------------------------------------------------------- VisToolTriangle::VisToolTriangle(const VContainer *data, QGraphicsItem *parent) @@ -57,16 +57,16 @@ void VisToolTriangle::RefreshGeometry() { if (point1Id > 0) { - const VPointF *first = data->GeometricObject(point1Id); + const VPointF *first = Visualization::data->GeometricObject(point1Id); DrawPoint(axisP1, first->toQPointF(), supportColor); if (point2Id <= 0) { - DrawAimedAxis(axis, QLineF(first->toQPointF(), scenePos), supportColor); + DrawAimedAxis(axis, QLineF(first->toQPointF(), Visualization::scenePos), supportColor); } else { - const VPointF *second = data->GeometricObject(point2Id); + const VPointF *second = Visualization::data->GeometricObject(point2Id); DrawPoint(axisP2, second->toQPointF(), supportColor); DrawAimedAxis(axis, QLineF(first->toQPointF(), second->toQPointF()), supportColor); @@ -77,23 +77,23 @@ void VisToolTriangle::RefreshGeometry() } else { - const VPointF *third = data->GeometricObject(hypotenuseP1Id); + const VPointF *third = Visualization::data->GeometricObject(hypotenuseP1Id); DrawPoint(hypotenuseP1, third->toQPointF(), supportColor); if (hypotenuseP2Id <= 0) { - DrawLine(this, QLineF(third->toQPointF(), scenePos), supportColor, Qt::DashLine); + DrawLine(this, QLineF(third->toQPointF(), Visualization::scenePos), supportColor, Qt::DashLine); QPointF trPoint = VToolTriangle::FindPoint(first->toQPointF(), second->toQPointF(), - third->toQPointF(), scenePos); + third->toQPointF(), Visualization::scenePos); DrawPoint(point, trPoint, mainColor); DrawLine(foot1, QLineF(third->toQPointF(), trPoint), supportColor, Qt::DashLine); - DrawLine(foot2, QLineF(scenePos, trPoint), supportColor, Qt::DashLine); + DrawLine(foot2, QLineF(Visualization::scenePos, trPoint), supportColor, Qt::DashLine); } else { - const VPointF *forth = data->GeometricObject(hypotenuseP2Id); + const VPointF *forth = Visualization::data->GeometricObject(hypotenuseP2Id); DrawPoint(hypotenuseP2, forth->toQPointF(), supportColor); DrawLine(this, QLineF(third->toQPointF(), forth->toQPointF()), supportColor, Qt::DashLine); diff --git a/src/app/visualization/visualization.cpp b/src/app/visualization/visualization.cpp new file mode 100644 index 000000000..2b19f9cf5 --- /dev/null +++ b/src/app/visualization/visualization.cpp @@ -0,0 +1,97 @@ +/************************************************************************ + ** + ** @file visualization.cpp + ** @author Roman Telezhynskyi + ** @date 15 8, 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 "visualization.h" +#include "../tools/drawTools/vdrawtool.h" + +//--------------------------------------------------------------------------------------------------------------------- +Visualization::Visualization(const VContainer *data) + :QObject(), data(data), factor(VDrawTool::factor), scenePos(QPointF()), + mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), point1Id(0), toolTip(QString()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +Visualization::~Visualization() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::setPoint1Id(const quint32 &value) +{ + point1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::setLineStyle(const Qt::PenStyle &value) +{ + lineStyle = value; + InitPen(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::setScenePos(const QPointF &value) +{ + scenePos = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::VisualMode(const quint32 &pointId) +{ + VMainGraphicsScene *scene = qApp->getCurrentScene(); + SCASSERT(scene != nullptr); + + this->point1Id = pointId; + this->scenePos = scene->getScenePos(); + RefreshGeometry(); + + AddOnScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::setMainColor(const QColor &value) +{ + mainColor = value; + InitPen(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::SetFactor(qreal factor) +{ + VApplication::CheckFactor(this->factor, factor); + RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::MousePos(const QPointF &scenePos) +{ + this->scenePos = scenePos; + RefreshGeometry(); + if (toolTip.isEmpty() == false) + { + emit ToolTip(toolTip); + } +} diff --git a/src/app/visualization/visualization.h b/src/app/visualization/visualization.h new file mode 100644 index 000000000..80c7feff7 --- /dev/null +++ b/src/app/visualization/visualization.h @@ -0,0 +1,85 @@ +/************************************************************************ + ** + ** @file visualization.h + ** @author Roman Telezhynskyi + ** @date 15 8, 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 VISUALIZATION_H +#define VISUALIZATION_H + +#include +#include "../widgets/vapplication.h" +#include "../widgets/vmaingraphicsscene.h" + +class VContainer; + +class Visualization : public QObject +{ + Q_OBJECT +public: + Visualization(const VContainer *data); + virtual ~Visualization(); + + virtual void RefreshGeometry()=0; + + void setPoint1Id(const quint32 &value); + void setLineStyle(const Qt::PenStyle &value); + void setScenePos(const QPointF &value); + void VisualMode(const quint32 &pointId); + void setMainColor(const QColor &value); +signals: + void ToolTip(const QString &toolTip); +public slots: + void SetFactor(qreal factor); + void MousePos(const QPointF &scenePos); +protected: + const VContainer *data; + qreal factor; + QPointF scenePos; + QColor mainColor; + QColor supportColor; + Qt::PenStyle lineStyle; + quint32 point1Id; + QString toolTip; + + virtual void InitPen()=0; + virtual void AddOnScene()=0; + + template + void AddItem(Item *item) + { + SCASSERT(item != nullptr); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + SCASSERT(scene != nullptr); + + scene->addItem(item); + connect(scene, &VMainGraphicsScene::NewFactor, item, &Visualization::SetFactor); + connect(scene, &VMainGraphicsScene::mouseMove, item, &Visualization::MousePos); + } +private: + Q_DISABLE_COPY(Visualization) +}; + +#endif // VISUALIZATION_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index c284b04ec..f3f4432f5 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -14,7 +14,8 @@ HEADERS += \ visualization/vistoolpointofintersection.h \ visualization/vistooltriangle.h \ visualization/vistoolpointofcontact.h \ - visualization/vistoollineintersect.h + visualization/vistoollineintersect.h \ + visualization/visualization.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -32,4 +33,5 @@ SOURCES += \ visualization/vistoolpointofintersection.cpp \ visualization/vistooltriangle.cpp \ visualization/vistoolpointofcontact.cpp \ - visualization/vistoollineintersect.cpp + visualization/vistoollineintersect.cpp \ + visualization/visualization.cpp