If pattern piece disabled need correct tool color.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-02-06 11:53:36 +02:00
parent 8b7567c32a
commit e94c5070dc
9 changed files with 66 additions and 28 deletions

View File

@ -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

View File

@ -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 <typename Dialog, typename Tool>
/**

View File

@ -476,5 +476,6 @@ void VToolLine::RefreshGeometry()
const QSharedPointer<VPointF> first = VAbstractTool::data.GeometricObject<VPointF>(firstPoint);
const QSharedPointer<VPointF> second = VAbstractTool::data.GeometricObject<VPointF>(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)));
}

View File

@ -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<VPointF>(id));
QPointF point = VDrawTool::data.GeometricObject<VPointF>(id)->toQPointF();
QPointF basePoint = VDrawTool::data.GeometricObject<VPointF>(basePointId)->toQPointF();

View File

@ -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));
}
}

View File

@ -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);

View File

@ -356,7 +356,7 @@ void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &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));

View File

@ -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;
}
}

View File

@ -71,6 +71,10 @@ private:
Qt::GlobalColor *currentColor;
SimpleCurvePoint curvePosition;
bool enabled;
QColor CorrectColor(const QColor &color) const;
};
#endif // VSIMPLECURVE_H