From e94c5070dc99adb8bb7f2afe12f2851fbefc74de Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 6 Feb 2015 11:53:36 +0200 Subject: [PATCH] If pattern piece disabled need correct tool color. --HG-- branch : feature --- src/app/tools/drawTools/vdrawtool.cpp | 24 ++++++++++++------- src/app/tools/drawTools/vdrawtool.h | 3 +++ src/app/tools/drawTools/vtoolline.cpp | 3 ++- src/app/tools/drawTools/vtoollinepoint.cpp | 3 ++- src/app/tools/drawTools/vtoolpoint.cpp | 25 ++++++++++++------- src/app/tools/drawTools/vtoolpoint.h | 2 ++ src/app/tools/drawTools/vtoolspline.cpp | 2 +- src/app/visualization/vsimplecurve.cpp | 28 ++++++++++++++++------ src/app/visualization/vsimplecurve.h | 4 ++++ 9 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index a510b940e..e993e0b07 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -47,7 +47,7 @@ qreal VDrawTool::factor = 1; */ VDrawTool::VDrawTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent) :VAbstractTool(doc, data, id, parent), ignoreFullUpdate(false), nameActivDraw(doc->GetNameActivPP()), - dialog(nullptr), typeLine(TypeLineLine), lineColor(ColorBlack) + dialog(nullptr), typeLine(TypeLineLine), lineColor(ColorBlack), enabled(true) { connect(this->doc, &VPattern::ChangedActivPP, this, &VDrawTool::ChangedActivDraw); connect(this->doc, &VPattern::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); @@ -81,14 +81,7 @@ void VDrawTool::ShowTool(quint32 id, Qt::GlobalColor color, bool enable) */ void VDrawTool::ChangedActivDraw(const QString &newName) { - if (nameActivDraw == newName) - { - currentColor = baseColor; - } - else - { - currentColor = Qt::gray; - } + enabled = nameActivDraw == newName; } //--------------------------------------------------------------------------------------------------------------------- @@ -179,6 +172,19 @@ void VDrawTool::RefreshDataInFile() } } +//--------------------------------------------------------------------------------------------------------------------- +QColor VDrawTool::CorrectColor(const QColor &color) const +{ + if (enabled) + { + return color; + } + else + { + return Qt::gray; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogLinkDestroy removes dialog pointer diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index 0f7576568..2ecd28f20 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -86,6 +86,8 @@ protected: /** @brief lineColor color line or curve, but not a point. */ QString lineColor; + bool enabled; + void AddToCalculation(const QDomElement &domElement); /** @brief SaveDialog save options into file after change in dialog. */ @@ -93,6 +95,7 @@ protected: void SaveDialogChange(); virtual void AddToFile(); virtual void RefreshDataInFile(); + QColor CorrectColor(const QColor &color) const; template /** diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index 42b3bce4d..a14e2d399 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -476,5 +476,6 @@ void VToolLine::RefreshGeometry() const QSharedPointer first = VAbstractTool::data.GeometricObject(firstPoint); const QSharedPointer second = VAbstractTool::data.GeometricObject(secondPoint); this->setLine(QLineF(first->toQPointF(), second->toQPointF())); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine))); + this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor, + LineStyleToPenStyle(typeLine))); } diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 598c84c32..6066602af 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -80,7 +80,8 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName) */ void VToolLinePoint::RefreshGeometry() { - mainLine->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine))); + mainLine->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor, + LineStyleToPenStyle(typeLine))); VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); QPointF point = VDrawTool::data.GeometricObject(id)->toQPointF(); QPointF basePoint = VDrawTool::data.GeometricObject(basePointId)->toQPointF(); diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 99bae27da..0b9b202ed 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -227,7 +227,7 @@ void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VToolPoint::RefreshPointGeometry(const VPointF &point) { this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor)); QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); @@ -259,14 +259,7 @@ void VToolPoint::RefreshLine() VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2); QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - if (currentColor == Qt::gray) - { - lineName->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); - } - else - { - lineName->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); - } + lineName->setPen(QPen(CorrectColor(Qt::black), qApp->toPixel(qApp->widthHairLine())/factor)); if (QLineF(p1, pRec - scenePos()).length() <= qApp->toPixel(4, Unit::Mm)) { @@ -325,3 +318,17 @@ void VToolPoint::keyReleaseEvent(QKeyEvent *event) } QGraphicsEllipseItem::keyReleaseEvent ( event ); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPoint::setEnabled(bool enabled) +{ + QGraphicsEllipseItem::setEnabled(enabled); + if (enabled) + { + setPen(QPen(QColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor)); + } + else + { + setPen(QPen(Qt::gray, qApp->toPixel(qApp->widthHairLine())/factor)); + } +} diff --git a/src/app/tools/drawTools/vtoolpoint.h b/src/app/tools/drawTools/vtoolpoint.h index 218753e31..8601e6c47 100644 --- a/src/app/tools/drawTools/vtoolpoint.h +++ b/src/app/tools/drawTools/vtoolpoint.h @@ -49,6 +49,8 @@ public: void setName(const QString &name); virtual QString getTagName() const; static const QString TagName; + + void setEnabled(bool enabled); public slots: void NameChangePosition(const QPointF &pos); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 979c51751..16a6ff4ce 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -356,7 +356,7 @@ void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj) */ void VToolSpline::RefreshGeometry() { - //this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor)); if (isHovered) { this->setPath(ToolPath(PathDirection::Show)); diff --git a/src/app/visualization/vsimplecurve.cpp b/src/app/visualization/vsimplecurve.cpp index 10c3927b0..de572b3e2 100644 --- a/src/app/visualization/vsimplecurve.cpp +++ b/src/app/visualization/vsimplecurve.cpp @@ -43,7 +43,7 @@ VSimpleCurve::VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, SimpleCurvePoint pointPosition, qreal *factor, QObject *parent) :QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor), - curvePosition(pointPosition) + curvePosition(pointPosition), enabled(true) { if (factor == nullptr) { @@ -60,8 +60,9 @@ VSimpleCurve::VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, SimpleCurv //--------------------------------------------------------------------------------------------------------------------- void VSimpleCurve::ChangedActivDraw(const bool &flag) { - setEnabled(flag); - setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); + enabled = flag; + setEnabled(enabled); + setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor)); } //--------------------------------------------------------------------------------------------------------------------- @@ -101,11 +102,11 @@ void VSimpleCurve::hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); if (factor == nullptr) { - this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine()))); + this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthMainLine()))); } else { - this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor)); + this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthMainLine())/ *factor)); } emit HoverPath(id, curvePosition, PathDirection::Show); } @@ -120,12 +121,25 @@ void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); if (factor == nullptr) { - this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthHairLine()))); } else { - this->setPen(QPen(*currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); + this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor)); } emit HoverPath(id, curvePosition, PathDirection::Hide); } + +//--------------------------------------------------------------------------------------------------------------------- +QColor VSimpleCurve::CorrectColor(const QColor &color) const +{ + if (enabled) + { + return color; + } + else + { + return Qt::gray; + } +} diff --git a/src/app/visualization/vsimplecurve.h b/src/app/visualization/vsimplecurve.h index d33afb269..a9b34c2db 100644 --- a/src/app/visualization/vsimplecurve.h +++ b/src/app/visualization/vsimplecurve.h @@ -71,6 +71,10 @@ private: Qt::GlobalColor *currentColor; SimpleCurvePoint curvePosition; + + bool enabled; + + QColor CorrectColor(const QColor &color) const; }; #endif // VSIMPLECURVE_H