Use different colors for different parts of tool.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-02-06 13:41:30 +02:00
parent 16662a34d5
commit 5f49394236
18 changed files with 78 additions and 51 deletions

View file

@ -86,6 +86,8 @@ void VAbstractSpline::ChangedActivDraw(const QString &newName)
{ {
VDrawTool::ChangedActivDraw(newName); VDrawTool::ChangedActivDraw(newName);
this->setEnabled(enabled); this->setEnabled(enabled);
this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthMainLine())/factor, Qt::SolidLine,
Qt::RoundCap));
emit setEnabledPoint(enabled); emit setEnabledPoint(enabled);
} }
@ -121,7 +123,8 @@ void VAbstractSpline::SetFactor(qreal factor)
void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, Qt::SolidLine, Qt::RoundCap)); this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthMainLine())/factor, Qt::SolidLine,
Qt::RoundCap));
this->setPath(ToolPath(PathDirection::Show)); this->setPath(ToolPath(PathDirection::Show));
isHovered = true; isHovered = true;
QGraphicsPathItem::hoverEnterEvent(event); QGraphicsPathItem::hoverEnterEvent(event);
@ -136,7 +139,7 @@ void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor));
this->setPath(ToolPath()); this->setPath(ToolPath());
isHovered = false; isHovered = false;
QGraphicsPathItem::hoverLeaveEvent(event); QGraphicsPathItem::hoverLeaveEvent(event);

View file

@ -164,32 +164,32 @@ protected:
void ShowItem(Item *item, quint32 id, Qt::GlobalColor color, bool enable) void ShowItem(Item *item, quint32 id, Qt::GlobalColor color, bool enable)
{ {
SCASSERT(item != nullptr); SCASSERT(item != nullptr);
if (id == item->id) // if (id == item->id)
{ // {
if (enable == false) // if (enable == false)
{ // {
currentColor = baseColor; // currentColor = baseColor;
} // }
else // else
{ // {
currentColor = color; // currentColor = color;
} // }
item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); // item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
} // }
} }
template <typename Item> template <typename Item>
void DisableItem(Item *item, bool disable) void DisableItem(Item *item, bool disable)
{ {
SCASSERT(item != nullptr); SCASSERT(item != nullptr);
if (disable) // if (disable)
{ // {
currentColor = Qt::gray; // currentColor = Qt::gray;
} // }
else // else
{ // {
currentColor = baseColor; // currentColor = baseColor;
} // }
item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); // item->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
} }
private: private:
Q_DISABLE_COPY(VDrawTool) Q_DISABLE_COPY(VDrawTool)

View file

@ -373,7 +373,7 @@ void VToolArc::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
*/ */
void VToolArc::RefreshGeometry() void VToolArc::RefreshGeometry()
{ {
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor));
this->setPath(ToolPath()); this->setPath(ToolPath());
if (vis != nullptr) if (vis != nullptr)

View file

@ -41,12 +41,12 @@ VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QSt
Q_ASSERT_X(curve1id > 0, Q_FUNC_INFO, "curve1id <= 0"); Q_ASSERT_X(curve1id > 0, Q_FUNC_INFO, "curve1id <= 0");
Q_ASSERT_X(curve2id > 0, Q_FUNC_INFO, "curve2id <= 0"); Q_ASSERT_X(curve2id > 0, Q_FUNC_INFO, "curve2id <= 0");
firstCurve = new VSimpleCurve(curve1id, &currentColor, SimpleCurvePoint::ForthPoint, &factor); firstCurve = new VSimpleCurve(curve1id, QColor(lineColor), SimpleCurvePoint::ForthPoint, &factor);
firstCurve->setParentItem(this); firstCurve->setParentItem(this);
connect(firstCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed); connect(firstCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
connect(firstCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath); connect(firstCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath);
secondCurve = new VSimpleCurve(curve2id, &currentColor, SimpleCurvePoint::FirstPoint, &factor); secondCurve = new VSimpleCurve(curve2id, QColor(lineColor), SimpleCurvePoint::FirstPoint, &factor);
secondCurve->setParentItem(this); secondCurve->setParentItem(this);
connect(secondCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed); connect(secondCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed);
connect(secondCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath); connect(secondCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath);

View file

@ -296,6 +296,7 @@ void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurve
{ {
path.translate(-arc->GetP2().x(), -arc->GetP2().y()); path.translate(-arc->GetP2().x(), -arc->GetP2().y());
} }
curve->SetCurrentColor(QColor(lineColor));
curve->setPath(path); curve->setPath(path);
} }

View file

@ -307,6 +307,7 @@ void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCu
{ {
path.translate(-spl->GetP4().toQPointF().x(), -spl->GetP4().toQPointF().y()); path.translate(-spl->GetP4().toQPointF().x(), -spl->GetP4().toQPointF().y());
} }
curve->SetCurrentColor(QColor(lineColor));
curve->setPath(path); curve->setPath(path);
} }

View file

@ -358,6 +358,7 @@ void VToolCutSplinePath::RefreshCurve(VSimpleCurve *curve, quint32 curveId, Simp
VSpline spl = splPath->GetSpline(splPath->Count()); VSpline spl = splPath->GetSpline(splPath->Count());
path.translate(-spl.GetP4().toQPointF().x(), -spl.GetP4().toQPointF().y()); path.translate(-spl.GetP4().toQPointF().x(), -spl.GetP4().toQPointF().y());
} }
curve->SetCurrentColor(QColor(lineColor));
curve->setPath(path); curve->setPath(path);
} }

View file

@ -239,6 +239,7 @@ void VToolLine::ChangedActivDraw(const QString &newName)
{ {
VDrawTool::ChangedActivDraw(newName); VDrawTool::ChangedActivDraw(newName);
this->setEnabled(enabled); this->setEnabled(enabled);
this->setPen(QPen(QColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine)));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -289,7 +290,8 @@ void VToolLine::RefreshDataInFile()
void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, LineStyleToPenStyle(typeLine))); this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthMainLine())/factor,
LineStyleToPenStyle(typeLine)));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -300,7 +302,8 @@ void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine))); this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor,
LineStyleToPenStyle(typeLine)));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -476,6 +479,6 @@ void VToolLine::RefreshGeometry()
const QSharedPointer<VPointF> first = VAbstractTool::data.GeometricObject<VPointF>(firstPoint); const QSharedPointer<VPointF> first = VAbstractTool::data.GeometricObject<VPointF>(firstPoint);
const QSharedPointer<VPointF> second = VAbstractTool::data.GeometricObject<VPointF>(secondPoint); const QSharedPointer<VPointF> second = VAbstractTool::data.GeometricObject<VPointF>(secondPoint);
this->setLine(QLineF(first->toQPointF(), second->toQPointF())); this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor, this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor,
LineStyleToPenStyle(typeLine))); LineStyleToPenStyle(typeLine)));
} }

View file

@ -71,6 +71,8 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName)
{ {
VToolPoint::ChangedActivDraw(newName); VToolPoint::ChangedActivDraw(newName);
this->setEnabled(enabled); this->setEnabled(enabled);
mainLine->setPen(QPen(QColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor,
LineStyleToPenStyle(typeLine)));
mainLine->setEnabled(enabled); mainLine->setEnabled(enabled);
} }
@ -80,7 +82,7 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName)
*/ */
void VToolLinePoint::RefreshGeometry() void VToolLinePoint::RefreshGeometry()
{ {
mainLine->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor, mainLine->setPen(QPen(CorrectColor(QColor(lineColor)), qApp->toPixel(qApp->widthHairLine())/factor,
LineStyleToPenStyle(typeLine))); LineStyleToPenStyle(typeLine)));
VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<VPointF>(id)); VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject<VPointF>(id));
QPointF point = VDrawTool::data.GeometricObject<VPointF>(id)->toQPointF(); QPointF point = VDrawTool::data.GeometricObject<VPointF>(id)->toQPointF();

View file

@ -204,7 +204,7 @@ void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void VToolPoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VToolPoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor)); this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthMainLine())/factor));
QGraphicsEllipseItem::hoverEnterEvent(event); QGraphicsEllipseItem::hoverEnterEvent(event);
} }
@ -216,7 +216,7 @@ void VToolPoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -227,7 +227,7 @@ void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void VToolPoint::RefreshPointGeometry(const VPointF &point) void VToolPoint::RefreshPointGeometry(const VPointF &point)
{ {
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor)); this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor));
QRectF rec = QRectF(0, 0, radius*2, radius*2); QRectF rec = QRectF(0, 0, radius*2, radius*2);
rec.translate(-rec.center().x(), -rec.center().y()); rec.translate(-rec.center().x(), -rec.center().y());
this->setRect(rec); this->setRect(rec);

View file

@ -52,8 +52,7 @@ VToolSinglePoint::VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id,
:VToolPoint(doc, data, id, parent), namePP(namePP), mPath(mPath) :VToolPoint(doc, data, id, parent), namePP(namePP), mPath(mPath)
{ {
baseColor = Qt::red; baseColor = Qt::red;
currentColor = baseColor; this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine())/factor));
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
ignoreFullUpdate = true; ignoreFullUpdate = true;
this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

View file

@ -356,7 +356,7 @@ void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
*/ */
void VToolSpline::RefreshGeometry() void VToolSpline::RefreshGeometry()
{ {
this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/factor)); this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor));
if (isHovered) if (isHovered)
{ {
this->setPath(ToolPath(PathDirection::Show)); this->setPath(ToolPath(PathDirection::Show));

View file

@ -47,7 +47,7 @@ const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool");
*/ */
VAbstractNode::VAbstractNode(VPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode, VAbstractNode::VAbstractNode(VPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode,
const quint32 &idTool, QObject *parent) const quint32 &idTool, QObject *parent)
: VAbstractTool(doc, data, id, parent), idNode(idNode), idTool(idTool) : VAbstractTool(doc, data, id, parent), idNode(idNode), idTool(idTool), currentColor(Qt::black)
{ {
_referens = 0; _referens = 0;
} }

View file

@ -53,6 +53,9 @@ protected:
/** @brief idTool id tool. */ /** @brief idTool id tool. */
quint32 idTool; quint32 idTool;
/** @brief currentColor current tool color. */
QColor currentColor;
void AddToModeling(const QDomElement &domElement); void AddToModeling(const QDomElement &domElement);
virtual void decrementReferens(); virtual void decrementReferens();
virtual void RemoveReferens(); virtual void RemoveReferens();

View file

@ -97,7 +97,7 @@ const QString VAbstractTool::ColorYellow = QStringLiteral("yellow");
* @param parent parent object. * @param parent parent object.
*/ */
VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent) VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent)
:VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), vis(nullptr) :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), vis(nullptr)
{ {
SCASSERT(doc != nullptr); SCASSERT(doc != nullptr);
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange);

View file

@ -147,9 +147,6 @@ protected:
/** @brief baseColor base color for tool. */ /** @brief baseColor base color for tool. */
Qt::GlobalColor baseColor; Qt::GlobalColor baseColor;
/** @brief currentColor current tool color. */
Qt::GlobalColor currentColor;
Visualization *vis; Visualization *vis;
/** /**

View file

@ -40,18 +40,18 @@
* @param currentColor current color. * @param currentColor current color.
* @param parent parent object. * @param parent parent object.
*/ */
VSimpleCurve::VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, SimpleCurvePoint pointPosition, qreal *factor, VSimpleCurve::VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint pointPosition, qreal *factor,
QObject *parent) QObject *parent)
:QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor), :QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor),
curvePosition(pointPosition), enabled(true) curvePosition(pointPosition), enabled(true)
{ {
if (factor == nullptr) if (factor == nullptr)
{ {
setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())));
} }
else else
{ {
setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/ *factor)); setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor));
} }
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
@ -62,7 +62,7 @@ void VSimpleCurve::ChangedActivDraw(const bool &flag)
{ {
enabled = flag; enabled = flag;
setEnabled(enabled); setEnabled(enabled);
setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor)); setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -102,11 +102,11 @@ void VSimpleCurve::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Q_UNUSED(event); Q_UNUSED(event);
if (factor == nullptr) if (factor == nullptr)
{ {
this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthMainLine()))); this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthMainLine())));
} }
else else
{ {
this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthMainLine())/ *factor)); this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthMainLine())/ *factor));
} }
emit HoverPath(id, curvePosition, PathDirection::Show); emit HoverPath(id, curvePosition, PathDirection::Show);
} }
@ -121,16 +121,29 @@ void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_UNUSED(event); Q_UNUSED(event);
if (factor == nullptr) if (factor == nullptr)
{ {
this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthHairLine()))); this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())));
} }
else else
{ {
this->setPen(QPen(CorrectColor(*currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor)); this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor));
} }
emit HoverPath(id, curvePosition, PathDirection::Hide); emit HoverPath(id, curvePosition, PathDirection::Hide);
} }
//---------------------------------------------------------------------------------------------------------------------
QColor VSimpleCurve::GetCurrentColor() const
{
return currentColor;
}
//---------------------------------------------------------------------------------------------------------------------
void VSimpleCurve::SetCurrentColor(const QColor &value)
{
currentColor = value;
setPen(QPen(CorrectColor(currentColor), pen().widthF()));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QColor VSimpleCurve::CorrectColor(const QColor &color) const QColor VSimpleCurve::CorrectColor(const QColor &color) const
{ {

View file

@ -41,13 +41,17 @@ class VSimpleCurve : public QObject, public QGraphicsPathItem
{ {
Q_OBJECT Q_OBJECT
public: public:
VSimpleCurve(quint32 id, Qt::GlobalColor *currentColor, SimpleCurvePoint curvePosition, VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint curvePosition,
qreal *factor = nullptr, QObject *parent = 0); qreal *factor = nullptr, QObject *parent = 0);
void ChangedActivDraw(const bool &flag); void ChangedActivDraw(const bool &flag);
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
virtual int type() const {return Type;} virtual int type() const {return Type;}
enum { Type = UserType + static_cast<int>(Vis::SimpleSplinePath)}; enum { Type = UserType + static_cast<int>(Vis::SimpleSplinePath)};
QColor GetCurrentColor() const;
void SetCurrentColor(const QColor &value);
signals: signals:
/** /**
* @brief Choosed send id when clicked. * @brief Choosed send id when clicked.
@ -68,7 +72,7 @@ private:
qreal *factor; qreal *factor;
/** @brief currentColor current color. */ /** @brief currentColor current color. */
Qt::GlobalColor *currentColor; QColor currentColor;
SimpleCurvePoint curvePosition; SimpleCurvePoint curvePosition;