VToolDoublePoint.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-06-20 19:14:04 +03:00
parent 0097d67865
commit 9b49c5122c
21 changed files with 1121 additions and 238 deletions

View File

@ -45,7 +45,8 @@ enum class Source : char { FromGui, FromFile, FromTool };
enum class Tool : unsigned char enum class Tool : unsigned char
{ {
Arrow, Arrow,
Point, SinglePoint,
DoublePoint,
LinePoint, LinePoint,
AbstractSpline, AbstractSpline,
Cut, Cut,
@ -79,14 +80,15 @@ enum class Tool : unsigned char
PointOfIntersection, PointOfIntersection,
PointFromCircleAndTangent, PointFromCircleAndTangent,
PointFromArcAndTangent, PointFromArcAndTangent,
UnionDetails // 35 UnionDetails // 36
}; };
enum class Vis : unsigned char enum class Vis : unsigned char
{ {
ControlPointSpline = 36, // increase this value if need more positions in Tool enum ControlPointSpline = 37, // increase this value if need more positions in Tool enum
GraphicsSimpleTextItem, GraphicsSimpleTextItem,
SimpleSplinePath, SimpleSplinePath,
SimplePoint,
Line, Line,
Path, Path,
ToolAlongLine, ToolAlongLine,

View File

@ -95,6 +95,15 @@ const QSharedPointer<VGObject> VContainer::GetGObject(quint32 id)const
return GetObject(d->gObjects, id); return GetObject(d->gObjects, id);
} }
//---------------------------------------------------------------------------------------------------------------------
const QSharedPointer<VGObject> VContainer::GetFakeGObject(quint32 id) const
{
VGObject *obj = new VGObject();
obj->setId(id);
QSharedPointer<VGObject> pointer(obj);
return pointer;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GetObject return object from container * @brief GetObject return object from container

View File

@ -103,6 +103,7 @@ public:
template <typename T> template <typename T>
const QSharedPointer<T> GeometricObject(const quint32 &id) const; const QSharedPointer<T> GeometricObject(const quint32 &id) const;
const QSharedPointer<VGObject> GetGObject(quint32 id) const; const QSharedPointer<VGObject> GetGObject(quint32 id) const;
const QSharedPointer<VGObject> GetFakeGObject(quint32 id) const;
const VDetail GetDetail(quint32 id) const; const VDetail GetDetail(quint32 id) const;
qreal GetTableValue(const QString& name, MeasurementsType patternType) const; qreal GetTableValue(const QString& name, MeasurementsType patternType) const;
template <typename T> template <typename T>

View File

@ -0,0 +1,305 @@
/************************************************************************
**
** @file vtooldoublepoint.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 6, 2015
**
** @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) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vtooldoublepoint.h"
#include "../vwidgets/vsimplepoint.h"
#include "../vgeometry/vpointf.h"
#include "../../../../undocommands/movelabel.h"
//---------------------------------------------------------------------------------------------------------------------
VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 p1id, quint32 p2id,
QGraphicsItem *parent)
:VAbstractPoint(doc, data, id), QGraphicsPathItem(parent), firstPoint(nullptr), secondPoint(nullptr), p1id(p1id),
p2id(p2id)
{
firstPoint = new VSimplePoint(p1id, QColor(baseColor), *data->GetPatternUnit(), &factor);
firstPoint->setParentItem(this);
connect(firstPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point1Choosed);
connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent);
connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel);
connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition);
secondPoint = new VSimplePoint(p2id, QColor(baseColor), *data->GetPatternUnit(), &factor);
secondPoint->setParentItem(this);
connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed);
connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent);
connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel);
connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition);
}
//---------------------------------------------------------------------------------------------------------------------
VToolDoublePoint::~VToolDoublePoint()
{}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
/* From question on StackOverflow
* https://stackoverflow.com/questions/10985028/how-to-remove-border-around-qgraphicsitem-when-selected
*
* There's no interface to disable the drawing of the selection border for the build-in QGraphicsItems. The only way
* I can think of is derive your own items from the build-in ones and override the paint() function:*/
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
QGraphicsPathItem::paint(painter, &myOption, widget);
}
//---------------------------------------------------------------------------------------------------------------------
QString VToolDoublePoint::nameP1() const
{
return PointName(p1id);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::setNameP1(const QString &name)
{
SetPointName(p1id, name);
}
//---------------------------------------------------------------------------------------------------------------------
QString VToolDoublePoint::nameP2() const
{
return PointName(p2id);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::setNameP2(const QString &name)
{
SetPointName(p2id, name);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::SetEnabled(bool enabled)
{
SetToolEnabled(this, enabled);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::Label1ChangePosition(const QPointF &pos)
{
ChangePosition(this, p1id, pos);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::Label2ChangePosition(const QPointF &pos)
{
ChangePosition(this, p2id, pos);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::SetFactor(qreal factor)
{
VDrawTool::SetFactor(factor);
firstPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p1id));
secondPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p2id));
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::Disable(bool disable, const QString &namePP)
{
enabled = !CorrectDisable(disable, namePP);
this->SetEnabled(enabled);
firstPoint->setEnabled(enabled);
secondPoint->setEnabled(enabled);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::EnableToolMove(bool move)
{
firstPoint->EnableToolMove(move);
secondPoint->EnableToolMove(move);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::Point1Choosed()
{
emit ChoosedTool(p1id, SceneObject::Point);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::Point2Choosed()
{
emit ChoosedTool(p2id, SceneObject::Point);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::FullUpdateFromFile()
{
ReadAttributes();
firstPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p1id));
secondPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject<VPointF>(p2id));
SetVisualization();
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::UpdateNamePosition()
{
qApp->getUndoStack()->beginMacro("move labels");
VPointF *p1 = VAbstractTool::data.GeometricObject<VPointF>(p1id).data();
MoveLabel *moveLabel1 = new MoveLabel(doc, p1->mx(), p1->my(), p1id, this->scene());
connect(moveLabel1, &MoveLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveLabel1);
VPointF *p2 = VAbstractTool::data.GeometricObject<VPointF>(p2id).data();
MoveLabel *moveLabel2 = new MoveLabel(doc, p2->mx(), p2->my(), p2id, this->scene());
connect(moveLabel2, &MoveLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveLabel2);
qApp->getUndoStack()->endMacro();
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::RefreshLine()
{
firstPoint->RefreshLine();
secondPoint->RefreshLine();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief itemChange hadle item change.
* @param change change.
* @param value value.
* @return value.
*/
QVariant VToolDoublePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedChange)
{
if (value == true)
{
// do stuff if selected
this->setFocus();
}
else
{
// do stuff if not selected
}
}
return QGraphicsItem::itemChange(change, value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief keyReleaseEvent handle key release events.
* @param event key release event.
*/
void VToolDoublePoint::keyReleaseEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Delete:
DeleteTool();
return; //Leave this method immediately after call!!!
default:
break;
}
QGraphicsPathItem::keyReleaseEvent ( event );
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
Q_UNUSED(event)
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
{
VDrawTool::SaveOptions(tag, obj);
if (obj->id() == p1id)
{
QSharedPointer<VPointF> point = qSharedPointerDynamicCast<VPointF>(obj);
SCASSERT(point.isNull() == false);
doc->SetAttribute(tag, AttrName1, point->name());
doc->SetAttribute(tag, AttrMx1, qApp->fromPixel(point->mx()));
doc->SetAttribute(tag, AttrMy1, qApp->fromPixel(point->my()));
VPointF *p = VAbstractTool::data.GeometricObject<VPointF>(p2id).data();
doc->SetAttribute(tag, AttrName2, p->name());
doc->SetAttribute(tag, AttrMx2, qApp->fromPixel(p->mx()));
doc->SetAttribute(tag, AttrMy2, qApp->fromPixel(p->my()));
}
else if (obj->id() == p2id)
{
QSharedPointer<VPointF> point = qSharedPointerDynamicCast<VPointF>(obj);
SCASSERT(point.isNull() == false);
doc->SetAttribute(tag, AttrName2, point->name());
doc->SetAttribute(tag, AttrMx2, qApp->fromPixel(point->mx()));
doc->SetAttribute(tag, AttrMy2, qApp->fromPixel(point->my()));
VPointF *p = VAbstractTool::data.GeometricObject<VPointF>(p1id).data();
doc->SetAttribute(tag, AttrName1, p->name());
doc->SetAttribute(tag, AttrMx1, qApp->fromPixel(p->mx()));
doc->SetAttribute(tag, AttrMy1, qApp->fromPixel(p->my()));
}
else
{
VPointF *p1 = VAbstractTool::data.GeometricObject<VPointF>(p1id).data();
VPointF *p2 = VAbstractTool::data.GeometricObject<VPointF>(p1id).data();
doc->SetAttribute(tag, AttrName1, p1->name());
doc->SetAttribute(tag, AttrMx1, qApp->fromPixel(p1->mx()));
doc->SetAttribute(tag, AttrMy1, qApp->fromPixel(p1->my()));
doc->SetAttribute(tag, AttrName2, p2->name());
doc->SetAttribute(tag, AttrMx2, qApp->fromPixel(p2->mx()));
doc->SetAttribute(tag, AttrMy2, qApp->fromPixel(p2->my()));
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::AddToFile()
{
QDomElement domElement = doc->createElement(getTagName());
QSharedPointer<VGObject> obj = VAbstractTool::data.GetFakeGObject(id);
SaveOptions(domElement, obj);
AddToCalculation(domElement);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolDoublePoint::RefreshDataInFile()
{
QDomElement domElement = doc->elementById(id);
if (domElement.isElement())
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetFakeGObject(id);
SaveOptions(domElement, obj);
}
else
{
qCDebug(vTool, "Can't find tool with id = %u", id);
}
}

View File

@ -0,0 +1,91 @@
/************************************************************************
**
** @file vtooldoublepoint.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 6, 2015
**
** @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) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VTOOLDOUBLEPOINT_H
#define VTOOLDOUBLEPOINT_H
#include "../vabstractpoint.h"
#include <QGraphicsPathItem>
class VPointF;
class VGraphicsSimpleTextItem;
class VSimplePoint;
class VToolDoublePoint: public VAbstractPoint, public QGraphicsPathItem
{
Q_OBJECT
public:
VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 p1id, quint32 p2id,
QGraphicsItem * parent = nullptr);
virtual ~VToolDoublePoint();
virtual int type() const {return Type;}
enum { Type = UserType + static_cast<int>(Tool::DoublePoint)};
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
QString nameP1() const;
void setNameP1(const QString &name);
QString nameP2() const;
void setNameP2(const QString &name);
void SetEnabled(bool enabled);
public slots:
void Label1ChangePosition(const QPointF &pos);
void Label2ChangePosition(const QPointF &pos);
virtual void SetFactor(qreal factor);
virtual void Disable(bool disable, const QString &namePP);
virtual void EnableToolMove(bool move);
void Point1Choosed();
void Point2Choosed();
virtual void FullUpdateFromFile();
protected:
VSimplePoint *firstPoint;
VSimplePoint *secondPoint;
quint32 p1id;
quint32 p2id;
virtual void UpdateNamePosition();
virtual void RefreshLine();
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void keyReleaseEvent(QKeyEvent * event);
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj);
virtual void AddToFile();
virtual void RefreshDataInFile();
private:
Q_DISABLE_COPY(VToolDoublePoint)
};
#endif // VTOOLDOUBLEPOINT_H

View File

@ -36,8 +36,6 @@
Q_LOGGING_CATEGORY(vToolSinglePoint, "v.toolSinglePoint") Q_LOGGING_CATEGORY(vToolSinglePoint, "v.toolSinglePoint")
const QString VToolSinglePoint::TagName = QStringLiteral("point");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VToolSinglePoint constructor. * @brief VToolSinglePoint constructor.
@ -47,16 +45,15 @@ const QString VToolSinglePoint::TagName = QStringLiteral("point");
* @param parent parent object. * @param parent parent object.
*/ */
VToolSinglePoint::VToolSinglePoint(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent) VToolSinglePoint::VToolSinglePoint(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent)
:VAbstractPoint(doc, data, id), QGraphicsEllipseItem(parent), radius(DefPointRadius), namePoint(nullptr), :VAbstractPoint(doc, data, id), QGraphicsEllipseItem(parent), radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)),
lineName(nullptr) namePoint(nullptr), lineName(nullptr)
{ {
radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm);
namePoint = new VGraphicsSimpleTextItem(this); namePoint = new VGraphicsSimpleTextItem(this);
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolSinglePoint::contextMenuEvent); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolSinglePoint::contextMenuEvent);
connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VToolSinglePoint::DeleteFromLabel); connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VToolSinglePoint::DeleteFromLabel);
connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VToolSinglePoint::PointChoosed); connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VToolSinglePoint::PointChoosed);
lineName = new QGraphicsLineItem(this);
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolSinglePoint::NameChangePosition); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolSinglePoint::NameChangePosition);
lineName = new QGraphicsLineItem(this);
this->setBrush(QBrush(Qt::NoBrush)); this->setBrush(QBrush(Qt::NoBrush));
this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);
@ -84,31 +81,19 @@ void VToolSinglePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolSinglePoint::name() const QString VToolSinglePoint::name() const
{ {
try return PointName(id);
{
return VAbstractTool::data.GeometricObject<VPointF>(id)->name();
}
catch (const VExceptionBadId &e)
{
qCDebug(vToolSinglePoint, "Error! Couldn't get point name. %s %s", e.ErrorMessage().toUtf8().constData(),
e.DetailedInformation().toUtf8().constData());
return QString("");// Return empty string for property browser
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::setName(const QString &name) void VToolSinglePoint::setName(const QString &name)
{ {
// Don't know if need check name here. SetPointName(id, name);
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
obj->setName(name);
SaveOption(obj);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VToolSinglePoint::getTagName() const void VToolSinglePoint::SetEnabled(bool enabled)
{ {
return VToolSinglePoint::TagName; SetToolEnabled(this, enabled);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -118,13 +103,7 @@ QString VToolSinglePoint::getTagName() const
*/ */
void VToolSinglePoint::NameChangePosition(const QPointF &pos) void VToolSinglePoint::NameChangePosition(const QPointF &pos)
{ {
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(id)); ChangePosition(this, id, pos);
QPointF p = pos - this->pos();
point->setMx(p.x());
point->setMy(p.y());
RefreshLine();
UpdateNamePosition(point->mx(), point->my());
VAbstractTool::data.UpdateGObject(id, point);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -133,24 +112,14 @@ void VToolSinglePoint::NameChangePosition(const QPointF &pos)
* @param mx label bias x axis. * @param mx label bias x axis.
* @param my label bias y axis. * @param my label bias y axis.
*/ */
void VToolSinglePoint::UpdateNamePosition(qreal mx, qreal my) void VToolSinglePoint::UpdateNamePosition()
{ {
MoveLabel *moveLabel = new MoveLabel(doc, mx, my, id, this->scene()); VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(id));
MoveLabel *moveLabel = new MoveLabel(doc, point->mx(), point->my(), id, this->scene());
connect(moveLabel, &MoveLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); connect(moveLabel, &MoveLabel::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveLabel); qApp->getUndoStack()->push(moveLabel);
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowTool highlight tool.
* @param id object id in container.
* @param enable enable or disable highlight.
*/
void VToolSinglePoint::ShowTool(quint32 id, bool enable)
{
ShowItem(this, id, enable);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief SetFactor set current scale factor of scene. * @brief SetFactor set current scale factor of scene.
@ -166,16 +135,10 @@ void VToolSinglePoint::SetFactor(qreal factor)
void VToolSinglePoint::Disable(bool disable, const QString &namePP) void VToolSinglePoint::Disable(bool disable, const QString &namePP)
{ {
enabled = !CorrectDisable(disable, namePP); enabled = !CorrectDisable(disable, namePP);
this->setEnabled(enabled); this->SetEnabled(enabled);
namePoint->setEnabled(enabled); namePoint->setEnabled(enabled);
} }
//---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::DeleteFromLabel()
{
DeleteTool(); //Leave this method immediately after call!!!
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::EnableToolMove(bool move) void VToolSinglePoint::EnableToolMove(bool move)
{ {
@ -275,10 +238,10 @@ void VToolSinglePoint::RefreshLine()
nRec.translate(- scenePos()); nRec.translate(- scenePos());
if (this->rect().intersects(nRec) == false) if (this->rect().intersects(nRec) == false)
{ {
QRectF nameRec = namePoint->sceneBoundingRect(); const QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2; QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2); VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2);
QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - scenePos())); lineName->setLine(QLineF(p1, pRec - scenePos()));
lineName->setPen(QPen(CorrectColor(Qt::black), lineName->setPen(QPen(CorrectColor(Qt::black),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
@ -359,17 +322,3 @@ void VToolSinglePoint::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &o
doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx()));
doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my()));
} }
//---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::setEnabled(bool enabled)
{
QGraphicsEllipseItem::setEnabled(enabled);
if (enabled)
{
setPen(QPen(QColor(baseColor), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
}
else
{
setPen(QPen(Qt::gray, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
}
}

View File

@ -44,19 +44,20 @@ class VToolSinglePoint: public VAbstractPoint, public QGraphicsEllipseItem
public: public:
VToolSinglePoint(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); VToolSinglePoint(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr);
virtual ~VToolSinglePoint(); virtual ~VToolSinglePoint();
virtual int type() const {return Type;}
enum { Type = UserType + static_cast<int>(Tool::SinglePoint)};
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
QString name() const; QString name() const;
void setName(const QString &name); void setName(const QString &name);
virtual QString getTagName() const;
static const QString TagName;
void setEnabled(bool enabled); void SetEnabled(bool enabled);
public slots: public slots:
void NameChangePosition(const QPointF &pos); void NameChangePosition(const QPointF &pos);
virtual void ShowTool(quint32 id, bool enable);
virtual void SetFactor(qreal factor); virtual void SetFactor(qreal factor);
virtual void Disable(bool disable, const QString &namePP); virtual void Disable(bool disable, const QString &namePP);
void DeleteFromLabel();
virtual void EnableToolMove(bool move); virtual void EnableToolMove(bool move);
void PointChoosed(); void PointChoosed();
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
@ -70,41 +71,16 @@ protected:
/** @brief lineName line what we see if label moved too away from point. */ /** @brief lineName line what we see if label moved too away from point. */
QGraphicsLineItem *lineName; QGraphicsLineItem *lineName;
virtual void UpdateNamePosition(qreal mx, qreal my); virtual void UpdateNamePosition();
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
virtual void RefreshPointGeometry(const VPointF &point); virtual void RefreshPointGeometry(const VPointF &point);
void RefreshLine(); virtual void RefreshLine();
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void keyReleaseEvent(QKeyEvent * event); virtual void keyReleaseEvent(QKeyEvent * event);
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event );
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj); virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj);
template <typename T>
void ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
}
private: private:
Q_DISABLE_COPY(VToolSinglePoint) Q_DISABLE_COPY(VToolSinglePoint)
}; };

View File

@ -27,6 +27,9 @@
*************************************************************************/ *************************************************************************/
#include "vabstractpoint.h" #include "vabstractpoint.h"
#include "../vgeometry/vpointf.h"
const QString VAbstractPoint::TagName = QStringLiteral("point");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractPoint::VAbstractPoint(VAbstractPattern *doc, VContainer *data, quint32 id) VAbstractPoint::VAbstractPoint(VAbstractPattern *doc, VContainer *data, quint32 id)
@ -36,3 +39,50 @@ VAbstractPoint::VAbstractPoint(VAbstractPattern *doc, VContainer *data, quint32
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractPoint::~VAbstractPoint() VAbstractPoint::~VAbstractPoint()
{} {}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPoint::getTagName() const
{
return VAbstractPoint::TagName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowTool highlight tool.
* @param id object id in container.
* @param enable enable or disable highlight.
*/
void VAbstractPoint::ShowTool(quint32 id, bool enable)
{
ShowItem(this, id, enable);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPoint::DeleteFromLabel()
{
DeleteTool(); //Leave this method immediately after call!!!
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPoint::PointName(quint32 id) const
{
try
{
return VAbstractTool::data.GeometricObject<VPointF>(id)->name();
}
catch (const VExceptionBadId &e)
{
qCDebug(vTool, "Error! Couldn't get point name. %s %s", e.ErrorMessage().toUtf8().constData(),
e.DetailedInformation().toUtf8().constData());
return QString("");// Return empty string for property browser
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPoint::SetPointName(quint32 id, const QString &name)
{
// Don't know if need check name here.
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
obj->setName(name);
SaveOption(obj);
}

View File

@ -30,12 +30,95 @@
#define VABSTRACTPOINT_H #define VABSTRACTPOINT_H
#include "../vdrawtool.h" #include "../vdrawtool.h"
#include "../vgeometry/vpointf.h"
class VAbstractPoint: public VDrawTool class VAbstractPoint: public VDrawTool
{ {
Q_OBJECT
public: public:
VAbstractPoint(VAbstractPattern *doc, VContainer *data, quint32 id); VAbstractPoint(VAbstractPattern *doc, VContainer *data, quint32 id);
virtual ~VAbstractPoint(); virtual ~VAbstractPoint();
virtual QString getTagName() const;
static const QString TagName;
template <typename T>
void ShowToolVisualization(bool show);
public slots:
virtual void ShowTool(quint32 id, bool enable);
void DeleteFromLabel();
protected:
QString PointName(quint32 id) const;
void SetPointName(quint32 id, const QString &name);
template <typename T>
void ChangePosition(T *item, quint32 id, const QPointF &pos);
virtual void UpdateNamePosition()=0;
virtual void RefreshLine()=0;
template <typename T>
void SetToolEnabled(T *item, bool enabled);
private:
Q_DISABLE_COPY(VAbstractPoint)
}; };
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
void VAbstractPoint::ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
{
AddVisualization<T>();
SetVisualization();
}
else
{
if (T *visual = qobject_cast<T *>(vis))
{
visual->show();
}
}
}
else
{
delete vis;
vis = nullptr;
}
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
void VAbstractPoint::SetToolEnabled(T *item, bool enabled)
{
item->setEnabled(enabled);
if (enabled)
{
item->setPen(QPen(QColor(baseColor),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
}
else
{
item->setPen(QPen(Qt::gray, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
}
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
void VAbstractPoint::ChangePosition(T *item, quint32 id, const QPointF &pos)
{
VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject<VPointF>(id));
const QPointF p = pos - item->pos();
point->setMx(p.x());
point->setMy(p.y());
RefreshLine();
VAbstractTool::data.UpdateGObject(id, point);
UpdateNamePosition();
}
#endif // VABSTRACTPOINT_H #endif // VABSTRACTPOINT_H

View File

@ -105,74 +105,83 @@ protected:
virtual void ReadToolAttributes(const QDomElement &domElement)=0; virtual void ReadToolAttributes(const QDomElement &domElement)=0;
template <typename Dialog, typename Tool> template <typename Dialog, typename Tool>
/** void ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove = true);
* @brief ContextMenu show context menu for tool.
* @param tool tool.
* @param event context menu event.
* @param showRemove true - tool have option delete.
*/
void ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove = true)
{
SCASSERT(tool != nullptr);
SCASSERT(event != nullptr);
QMenu menu;
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
QAction *actionRemove = nullptr;
actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
if (showRemove)
{
if (_referens > 1)
{
actionRemove->setEnabled(false);
}
else
{
actionRemove->setEnabled(true);
}
}
else
{
actionRemove->setEnabled(false);
}
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == actionOption)
{
qApp->getSceneView()->itemClicked(nullptr);
dialog = new Dialog(getData(), id, qApp->getMainWindow());
dialog->setModal(true);
connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGuiOk);
connect(dialog, &DialogTool::DialogApplied, tool, &Tool::FullUpdateFromGuiApply);
tool->setDialog();
dialog->show();
}
if (selectedAction == actionRemove)
{
DeleteTool();
return; //Leave this method immediately after call!!!
}
}
template <typename Item> template <typename Item>
/** void ShowItem(Item *item, quint32 id, bool enable);
* @brief ShowItem highlight tool.
* @param item tool.
* @param id object id in container.
* @param enable enable or disable highlight.
*/
void ShowItem(Item *item, quint32 id, bool enable)
{
SCASSERT(item != nullptr);
if (id == item->id)
{
ShowVisualization(enable);
}
}
private: private:
Q_DISABLE_COPY(VDrawTool) Q_DISABLE_COPY(VDrawTool)
}; };
//---------------------------------------------------------------------------------------------------------------------
template <typename Dialog, typename Tool>
/**
* @brief ContextMenu show context menu for tool.
* @param tool tool.
* @param event context menu event.
* @param showRemove true - tool have option delete.
*/
void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove)
{
SCASSERT(tool != nullptr);
SCASSERT(event != nullptr);
QMenu menu;
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
QAction *actionRemove = nullptr;
actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
if (showRemove)
{
if (_referens > 1)
{
actionRemove->setEnabled(false);
}
else
{
actionRemove->setEnabled(true);
}
}
else
{
actionRemove->setEnabled(false);
}
QAction *selectedAction = menu.exec(event->screenPos());
if (selectedAction == actionOption)
{
qApp->getSceneView()->itemClicked(nullptr);
dialog = new Dialog(getData(), id, qApp->getMainWindow());
dialog->setModal(true);
connect(dialog, &DialogTool::DialogClosed, tool, &Tool::FullUpdateFromGuiOk);
connect(dialog, &DialogTool::DialogApplied, tool, &Tool::FullUpdateFromGuiApply);
tool->setDialog();
dialog->show();
}
if (selectedAction == actionRemove)
{
DeleteTool();
return; //Leave this method immediately after call!!!
}
}
//---------------------------------------------------------------------------------------------------------------------
template <typename Item>
/**
* @brief ShowItem highlight tool.
* @param item tool.
* @param id object id in container.
* @param enable enable or disable highlight.
*/
void VDrawTool::ShowItem(Item *item, quint32 id, bool enable)
{
SCASSERT(item != nullptr);
if (id == item->id)
{
ShowVisualization(enable);
}
}
#endif // VDRAWTOOL_H #endif // VDRAWTOOL_H

View File

@ -44,7 +44,8 @@ HEADERS += \
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h \
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h \
$$PWD/drawTools/toolcurve/vtoolarcwithlength.h \ $$PWD/drawTools/toolcurve/vtoolarcwithlength.h \
$$PWD/drawTools/toolpoint/vabstractpoint.h $$PWD/drawTools/toolpoint/vabstractpoint.h \
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h
SOURCES += \ SOURCES += \
$$PWD/vtooldetail.cpp \ $$PWD/vtooldetail.cpp \
@ -86,4 +87,5 @@ SOURCES += \
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp \
$$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp \
$$PWD/drawTools/toolcurve/vtoolarcwithlength.cpp \ $$PWD/drawTools/toolcurve/vtoolarcwithlength.cpp \
$$PWD/drawTools/toolpoint/vabstractpoint.cpp $$PWD/drawTools/toolpoint/vabstractpoint.cpp \
$$PWD/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp

View File

@ -44,6 +44,12 @@ const QString VAbstractTool::AttrType = QStringLiteral("type");
const QString VAbstractTool::AttrMx = QStringLiteral("mx"); const QString VAbstractTool::AttrMx = QStringLiteral("mx");
const QString VAbstractTool::AttrMy = QStringLiteral("my"); const QString VAbstractTool::AttrMy = QStringLiteral("my");
const QString VAbstractTool::AttrName = QStringLiteral("name"); const QString VAbstractTool::AttrName = QStringLiteral("name");
const QString VAbstractTool::AttrMx1 = QStringLiteral("mx1");
const QString VAbstractTool::AttrMy1 = QStringLiteral("my1");
const QString VAbstractTool::AttrName1 = QStringLiteral("name1");
const QString VAbstractTool::AttrMx2 = QStringLiteral("mx2");
const QString VAbstractTool::AttrMy2 = QStringLiteral("my2");
const QString VAbstractTool::AttrName2 = QStringLiteral("name2");
const QString VAbstractTool::AttrX = QStringLiteral("x"); const QString VAbstractTool::AttrX = QStringLiteral("x");
const QString VAbstractTool::AttrY = QStringLiteral("y"); const QString VAbstractTool::AttrY = QStringLiteral("y");
const QString VAbstractTool::AttrTypeLine = QStringLiteral("typeLine"); const QString VAbstractTool::AttrTypeLine = QStringLiteral("typeLine");

View File

@ -58,6 +58,12 @@ public:
static const QString AttrMx; static const QString AttrMx;
static const QString AttrMy; static const QString AttrMy;
static const QString AttrName; static const QString AttrName;
static const QString AttrMx1;
static const QString AttrMy1;
static const QString AttrName1;
static const QString AttrMx2;
static const QString AttrMy2;
static const QString AttrName2;
static const QString AttrX; static const QString AttrX;
static const QString AttrY; static const QString AttrY;
static const QString AttrTypeLine; static const QString AttrTypeLine;

View File

@ -20,7 +20,6 @@ HEADERS += \
$$PWD/renamepp.h \ $$PWD/renamepp.h \
$$PWD/movelabel.h $$PWD/movelabel.h
SOURCES += \ SOURCES += \
$$PWD/addtocalc.cpp \ $$PWD/addtocalc.cpp \
$$PWD/addpatternpiece.cpp \ $$PWD/addpatternpiece.cpp \
@ -39,4 +38,3 @@ SOURCES += \
$$PWD/vundocommand.cpp \ $$PWD/vundocommand.cpp \
$$PWD/renamepp.cpp \ $$PWD/renamepp.cpp \
$$PWD/movelabel.cpp $$PWD/movelabel.cpp

View File

@ -0,0 +1,52 @@
/************************************************************************
**
** @file vabstractsimple.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 6, 2015
**
** @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) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vabstractsimple.h"
//---------------------------------------------------------------------------------------------------------------------
VAbstractSimple::VAbstractSimple(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor,
QObject *parent)
:QObject(parent), id (id), factor(factor), currentColor(currentColor), enabled(true), patternUnit(patternUnit)
{}
//---------------------------------------------------------------------------------------------------------------------
VAbstractSimple::~VAbstractSimple()
{}
//---------------------------------------------------------------------------------------------------------------------
QColor VAbstractSimple::CorrectColor(const QColor &color) const
{
if (enabled)
{
return color;
}
else
{
return Qt::gray;
}
}

View File

@ -0,0 +1,82 @@
/************************************************************************
**
** @file vabstractsimple.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 6, 2015
**
** @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) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VABSTRACTSIMPLE_H
#define VABSTRACTSIMPLE_H
#include <QObject>
#include "../vmisc/def.h"
class VAbstractSimple : public QObject
{
Q_OBJECT
public:
VAbstractSimple(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor = nullptr,
QObject *parent = 0);
virtual ~VAbstractSimple();
virtual void ChangedActivDraw(const bool &flag)=0;
protected:
/** @brief id spline id. */
quint32 id;
/** @brief factor scale factor. */
qreal *factor;
/** @brief currentColor current color. */
QColor currentColor;
bool enabled;
Unit patternUnit;
QColor CorrectColor(const QColor &color) const;
template <class T>
void SetPen(T *item, const QColor &color, qreal width);
private:
Q_DISABLE_COPY(VAbstractSimple)
};
//---------------------------------------------------------------------------------------------------------------------
template <class T>
void VAbstractSimple::SetPen(T *item, const QColor &color, qreal width)
{
if (factor == nullptr)
{
item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)));
}
else
{
item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)/ *factor));
}
}
#endif // VABSTRACTSIMPLE_H

View File

@ -39,19 +39,11 @@
* @param currentColor current color. * @param currentColor current color.
* @param parent parent object. * @param parent parent object.
*/ */
VSimpleCurve::VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint pointPosition, Unit patternUnit, VSimpleCurve::VSimpleCurve(quint32 id, const QColor &currentColor, SimpleCurvePoint pointPosition, Unit patternUnit,
qreal *factor, QObject *parent) qreal *factor, QObject *parent)
:QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor), :VAbstractSimple(id, currentColor, patternUnit, factor, parent), QGraphicsPathItem(), curvePosition(pointPosition)
curvePosition(pointPosition), enabled(true), patternUnit(patternUnit)
{ {
if (factor == nullptr) SetPen(this, currentColor, WidthHairLine(patternUnit));
{
setPen(QPen(currentColor, ToPixel(WidthHairLine(patternUnit), patternUnit)));
}
else
{
setPen(QPen(currentColor, ToPixel(WidthHairLine(patternUnit), patternUnit)/ *factor));
}
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
} }
@ -61,7 +53,7 @@ void VSimpleCurve::ChangedActivDraw(const bool &flag)
{ {
enabled = flag; enabled = flag;
setEnabled(enabled); setEnabled(enabled);
setPen(QPen(CorrectColor(currentColor), ToPixel(WidthHairLine(patternUnit), patternUnit)/ *factor)); SetPen(this, currentColor, WidthHairLine(patternUnit));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -93,20 +85,13 @@ void VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief hoverMoveEvent handle hover move events. * @brief hoverEnterEvent handle hover enter events.
* @param event hover move event. * @param event hover move event.
*/ */
void VSimpleCurve::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
if (factor == nullptr) SetPen(this, currentColor, WidthMainLine(patternUnit));
{
this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthMainLine(patternUnit), patternUnit)));
}
else
{
this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthMainLine(patternUnit), patternUnit)/ *factor));
}
emit HoverPath(id, curvePosition, PathDirection::Show); emit HoverPath(id, curvePosition, PathDirection::Show);
} }
@ -118,18 +103,16 @@ void VSimpleCurve::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
if (factor == nullptr) SetPen(this, currentColor, WidthHairLine(patternUnit));
{
this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthHairLine(patternUnit), patternUnit)));
}
else
{
this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthHairLine(patternUnit), patternUnit)/ *factor));
}
emit HoverPath(id, curvePosition, PathDirection::Hide); emit HoverPath(id, curvePosition, PathDirection::Hide);
} }
//---------------------------------------------------------------------------------------------------------------------
void VSimpleCurve::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->ignore();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
QColor VSimpleCurve::GetCurrentColor() const QColor VSimpleCurve::GetCurrentColor() const
@ -141,24 +124,5 @@ QColor VSimpleCurve::GetCurrentColor() const
void VSimpleCurve::SetCurrentColor(const QColor &value) void VSimpleCurve::SetCurrentColor(const QColor &value)
{ {
currentColor = value; currentColor = value;
setPen(QPen(CorrectColor(currentColor), pen().widthF())); SetPen(this, CorrectColor(currentColor), pen().widthF());
}
//---------------------------------------------------------------------------------------------------------------------
void VSimpleCurve::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->ignore();
}
//---------------------------------------------------------------------------------------------------------------------
QColor VSimpleCurve::CorrectColor(const QColor &color) const
{
if (enabled)
{
return color;
}
else
{
return Qt::gray;
}
} }

View File

@ -31,27 +31,27 @@
#include <QGraphicsPathItem> #include <QGraphicsPathItem>
#include "../vgeometry/vabstractcurve.h" #include "../vgeometry/vabstractcurve.h"
#include "../vmisc/def.h" #include "vabstractsimple.h"
enum class SimpleCurvePoint : char { FirstPoint, ForthPoint }; enum class SimpleCurvePoint : char { FirstPoint, ForthPoint };
/** /**
* @brief The VSimpleSpline class for simple spline. This object used when we cut spline and want show peaces. * @brief The VSimpleSpline class for simple spline. This object used when we cut spline and want show peaces.
*/ */
class VSimpleCurve : public QObject, public QGraphicsPathItem class VSimpleCurve : public VAbstractSimple, public QGraphicsPathItem
{ {
Q_OBJECT Q_OBJECT
public: public:
VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint curvePosition, Unit patternUnit, VSimpleCurve(quint32 id, const QColor &currentColor, SimpleCurvePoint curvePosition, Unit patternUnit,
qreal *factor = nullptr, QObject *parent = 0); qreal *factor = nullptr, QObject *parent = 0);
void ChangedActivDraw(const bool &flag); virtual 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; QColor GetCurrentColor() const;
void SetCurrentColor(const QColor &value); void SetCurrentColor(const QColor &value);
signals: signals:
/** /**
@ -63,26 +63,15 @@ signals:
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event); virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
private: private:
Q_DISABLE_COPY(VSimpleCurve) Q_DISABLE_COPY(VSimpleCurve)
/** @brief id spline id. */
quint32 id;
/** @brief factor scale factor. */
qreal *factor;
/** @brief currentColor current color. */
QColor currentColor;
SimpleCurvePoint curvePosition; SimpleCurvePoint curvePosition;
bool enabled;
Unit patternUnit;
QColor CorrectColor(const QColor &color) const;
}; };
#endif // VSIMPLECURVE_H #endif // VSIMPLECURVE_H

View File

@ -0,0 +1,210 @@
/************************************************************************
**
** @file vsimplepoint.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 6, 2015
**
** @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) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vsimplepoint.h"
#include "vgraphicssimpletextitem.h"
#include "../ifc/ifcdef.h"
#include "../vgeometry/vgobject.h"
#include "../vgeometry/vpointf.h"
#include <QGraphicsSceneMouseEvent>
#include <QStyleOptionGraphicsItem>
//---------------------------------------------------------------------------------------------------------------------
VSimplePoint::VSimplePoint(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor, QObject *parent)
:VAbstractSimple(id, currentColor, patternUnit, factor, parent), QGraphicsEllipseItem(),
radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), namePoint(nullptr), lineName(nullptr)
{
namePoint = new VGraphicsSimpleTextItem(this);
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu);
connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel);
connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed);
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VSimplePoint::ChangedPosition);
lineName = new QGraphicsLineItem(this);
this->setBrush(QBrush(Qt::NoBrush));
SetPen(this, currentColor, WidthHairLine(patternUnit));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
this->setAcceptHoverEvents(true);
}
//---------------------------------------------------------------------------------------------------------------------
VSimplePoint::~VSimplePoint()
{}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::ChangedActivDraw(const bool &flag)
{
enabled = flag;
setEnabled(enabled);
SetPen(this, currentColor, WidthHairLine(patternUnit));
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
/* From question on StackOverflow
* https://stackoverflow.com/questions/10985028/how-to-remove-border-around-qgraphicsitem-when-selected
*
* There's no interface to disable the drawing of the selection border for the build-in QGraphicsItems. The only way
* I can think of is derive your own items from the build-in ones and override the paint() function:*/
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
QGraphicsEllipseItem::paint(painter, &myOption, widget);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::RefreshLine()
{
QRectF nRec = namePoint->sceneBoundingRect();
nRec.translate(- scenePos());
if (this->rect().intersects(nRec) == false)
{
const QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2);
const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - scenePos()));
SetPen(lineName, QColor(Qt::black), WidthHairLine(patternUnit));
if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm))
{
lineName->setVisible(false);
}
else
{
lineName->setVisible(true);
}
}
else
{
lineName->setVisible(false);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::RefreshGeometry(const VPointF &point)
{
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
SetPen(this, currentColor, WidthHairLine(patternUnit));
QRectF rec = QRectF(0, 0, radius*2, radius*2);
rec.translate(-rec.center().x(), -rec.center().y());
this->setRect(rec);
this->setPos(point.toQPointF());
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
namePoint->blockSignals(true);
QFont font = namePoint->font();
if (factor == nullptr)
{
font.setPointSize(static_cast<qint32>(namePoint->FontSize()));
}
else
{
font.setPointSize(static_cast<qint32>(namePoint->FontSize()/ *factor));
}
namePoint->setFont(font);
namePoint->setText(point.name());
namePoint->setPos(QPointF(point.mx(), point.my()));
namePoint->blockSignals(false);
RefreshLine();
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::SetEnabled(bool enabled)
{
namePoint->setEnabled(enabled);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::EnableToolMove(bool move)
{
namePoint->setFlag(QGraphicsItem::ItemIsMovable, move);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::DeleteFromLabel()
{
emit Delete();
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::PointChoosed()
{
emit Choosed(id);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::ChangedPosition(const QPointF &pos)
{
emit NameChangedPosition(pos);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::ContextMenu(QGraphicsSceneContextMenuEvent *event)
{
emit ShowContextMenu(event);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
emit Choosed(id);
}
QGraphicsEllipseItem::mouseReleaseEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
SetPen(this, currentColor, WidthMainLine(patternUnit));
QGraphicsEllipseItem::hoverEnterEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
SetPen(this, currentColor, WidthHairLine(patternUnit));
QGraphicsEllipseItem::hoverLeaveEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
QColor VSimplePoint::GetCurrentColor() const
{
return currentColor;
}
//---------------------------------------------------------------------------------------------------------------------
void VSimplePoint::SetCurrentColor(const QColor &value)
{
currentColor = value;
SetPen(this, CorrectColor(currentColor), pen().widthF());
}

View File

@ -0,0 +1,95 @@
/************************************************************************
**
** @file vsimplepoint.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 6, 2015
**
** @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) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VSIMPLEPOINT_H
#define VSIMPLEPOINT_H
#include <QGraphicsEllipseItem>
#include "vabstractsimple.h"
class VPointF;
class VGraphicsSimpleTextItem;
class VSimplePoint : public VAbstractSimple, public QGraphicsEllipseItem
{
Q_OBJECT
public:
VSimplePoint(quint32 id, const QColor &currentColor, Unit patternUnit, qreal *factor = nullptr,
QObject *parent = nullptr);
virtual ~VSimplePoint();
virtual void ChangedActivDraw(const bool &flag);
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
virtual int type() const {return Type;}
enum { Type = UserType + static_cast<int>(Vis::SimplePoint)};
void RefreshLine();
void RefreshGeometry(const VPointF &point);
void SetEnabled(bool enabled);
void EnableToolMove(bool move);
QColor GetCurrentColor() const;
void SetCurrentColor(const QColor &value);
signals:
/**
* @brief Choosed send id when clicked.
* @param id point id.
*/
void Choosed(quint32 id);
void ShowContextMenu(QGraphicsSceneContextMenuEvent * event);
void Delete();
void NameChangedPosition(const QPointF &pos);
public slots:
void DeleteFromLabel();
void PointChoosed();
void ChangedPosition(const QPointF &pos);
void ContextMenu(QGraphicsSceneContextMenuEvent * event);
protected:
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
private:
Q_DISABLE_COPY(VSimplePoint)
/** @brief radius radius circle. */
qreal radius;
/** @brief namePoint point label. */
VGraphicsSimpleTextItem *namePoint;
/** @brief lineName line what we see if label moved too away from point. */
QGraphicsLineItem *lineName;
};
#endif // VSIMPLEPOINT_H

View File

@ -10,7 +10,9 @@ SOURCES += \
$$PWD/vsimplecurve.cpp \ $$PWD/vsimplecurve.cpp \
$$PWD/vwidgetpopup.cpp \ $$PWD/vwidgetpopup.cpp \
$$PWD/vcontrolpointspline.cpp \ $$PWD/vcontrolpointspline.cpp \
$$PWD/vgraphicssimpletextitem.cpp $$PWD/vgraphicssimpletextitem.cpp \
$$PWD/vsimplepoint.cpp \
$$PWD/vabstractsimple.cpp
HEADERS += \ HEADERS += \
$$PWD/stable.h \ $$PWD/stable.h \
@ -21,4 +23,6 @@ HEADERS += \
$$PWD/vsimplecurve.h \ $$PWD/vsimplecurve.h \
$$PWD/vwidgetpopup.h \ $$PWD/vwidgetpopup.h \
$$PWD/vcontrolpointspline.h \ $$PWD/vcontrolpointspline.h \
$$PWD/vgraphicssimpletextitem.h $$PWD/vgraphicssimpletextitem.h \
$$PWD/vsimplepoint.h \
$$PWD/vabstractsimple.h