element editor: minor improvement about line creation

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3455 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-11-05 21:37:25 +00:00
parent c81b4fb07c
commit e4de046db5
4 changed files with 46 additions and 12 deletions

View File

@@ -63,7 +63,6 @@ bool ESEventAddLine::mousePressEvent(QGraphicsSceneMouseEvent *event) {
} }
//Add new line to scene //Add new line to scene
m_line -> setLine(QLineF(m_line->line().p1(), pos));
m_scene -> undoStack().push(new AddPartCommand(QObject::tr("ligne"), m_scene, m_line)); m_scene -> undoStack().push(new AddPartCommand(QObject::tr("ligne"), m_scene, m_line));
//Set m_line to nullptr for create new line at next mouse press //Set m_line to nullptr for create new line at next mouse press
@@ -82,11 +81,9 @@ bool ESEventAddLine::mousePressEvent(QGraphicsSceneMouseEvent *event) {
*/ */
bool ESEventAddLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { bool ESEventAddLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
updateHelpCross (event -> scenePos()); updateHelpCross (event -> scenePos());
if (!m_line) return false; if (!m_line) return false;
QPointF pos = m_scene -> snapToGrid(event -> scenePos()); m_line -> setP2(m_scene -> snapToGrid(event -> scenePos()));
m_line -> setLine(QLineF(m_line->line().p1(), pos));
return true; return true;
} }

View File

@@ -24,6 +24,10 @@ class ElementScene;
class PartLine; class PartLine;
class QGraphicsSceneMouseEvent; class QGraphicsSceneMouseEvent;
/**
* @brief The ESEventAddLine class
* This ESEvent manage creation of line in a ElementScene
*/
class ESEventAddLine : public ESEventInterface class ESEventAddLine : public ESEventInterface
{ {
public: public:

View File

@@ -223,6 +223,15 @@ void PartLine::setY1(qreal y1) {
setLine(QLineF(p, line().p2())); setLine(QLineF(p, line().p2()));
} }
/**
* @brief PartLine::setP1
* set first point to P1
* @param p1
*/
void PartLine::setP1(QPointF p1) {
setLine(QLineF(p1, line().p2()));
}
/** /**
* @brief PartLine::setX2 * @brief PartLine::setX2
* set x of P2 * set x of P2
@@ -245,6 +254,15 @@ void PartLine::setY2(qreal y2) {
setLine(QLineF(line().p1(), p)); setLine(QLineF(line().p1(), p));
} }
/**
* @brief PartLine::setP2
* set second point to P2
* @param p2
*/
void PartLine::setP2(QPointF p2) {
setLine(QLineF(line().p1(), p2));
}
/** /**
Gere les changements intervenant sur cette partie Gere les changements intervenant sur cette partie
@param change Type de changement @param change Type de changement

View File

@@ -78,30 +78,45 @@ class PartLine : public CustomElementGraphicPart, public QGraphicsLineItem {
Q_PROPERTY(qreal x1 READ x1 WRITE setX1) Q_PROPERTY(qreal x1 READ x1 WRITE setX1)
qreal x1() const {return sceneP1().x();} qreal x1() const {return sceneP1().x();}
void setX1(qreal x1); void setX1(qreal x1);
// Y value of the first point // Y value of the first point
Q_PROPERTY(qreal y1 READ y1 WRITE setY1) Q_PROPERTY(qreal y1 READ y1 WRITE setY1)
qreal y1() const {return sceneP1().y();} qreal y1() const {return sceneP1().y();}
void setY1(qreal y1); void setY1(qreal y1);
//pos of firts point
Q_PROPERTY(QPointF p1 READ sceneP1 WRITE setP1)
void setP1 (QPointF p1);
// X value of the second point // X value of the second point
Q_PROPERTY(qreal x2 READ x2 WRITE setX2) Q_PROPERTY(qreal x2 READ x2 WRITE setX2)
qreal x2() const {return sceneP2().x();} qreal x2() const {return sceneP2().x();}
void setX2(qreal x2); void setX2(qreal x2);
// Y value of the second point // Y value of the second point
Q_PROPERTY(qreal y2 READ y2 WRITE setY2) Q_PROPERTY(qreal y2 READ y2 WRITE setY2)
qreal y2() const {return sceneP2().y();} qreal y2() const {return sceneP2().y();}
void setY2(qreal y2); void setY2(qreal y2);
//pos of second point
Q_PROPERTY(QPointF p2 READ sceneP2 WRITE setP2)
void setP2 (QPointF p2);
// End type of the first point // End type of the first point
Q_PROPERTY(Qet::EndType end1 READ firstEndType WRITE setFirstEndType) Q_PROPERTY(Qet::EndType end1 READ firstEndType WRITE setFirstEndType)
Qet::EndType firstEndType() const {return first_end;} Qet::EndType firstEndType() const {return first_end;}
void setFirstEndType(const Qet::EndType &et) {first_end = et;} void setFirstEndType(const Qet::EndType &et) {first_end = et;}
// End type of the second point // End type of the second point
Q_PROPERTY(Qet::EndType end2 READ secondEndType WRITE setSecondEndType) Q_PROPERTY(Qet::EndType end2 READ secondEndType WRITE setSecondEndType)
Qet::EndType secondEndType() const {return second_end;} Qet::EndType secondEndType() const {return second_end;}
void setSecondEndType(const Qet::EndType &et) {second_end = et;} void setSecondEndType(const Qet::EndType &et) {second_end = et;}
// Size of end type of first point // Size of end type of first point
Q_PROPERTY(qreal length1 READ firstEndLength WRITE setFirstEndLength) Q_PROPERTY(qreal length1 READ firstEndLength WRITE setFirstEndLength)
qreal firstEndLength() const {return first_length;} qreal firstEndLength() const {return first_length;}
void setFirstEndLength(const qreal &l) {first_length = qMin(qAbs(l), line().length());} void setFirstEndLength(const qreal &l) {first_length = qMin(qAbs(l), line().length());}
// Size of end type of the second point // Size of end type of the second point
Q_PROPERTY(qreal length2 READ secondEndLength WRITE setSecondEndLength) Q_PROPERTY(qreal length2 READ secondEndLength WRITE setSecondEndLength)
qreal secondEndLength() const {return second_length;} qreal secondEndLength() const {return second_length;}