From e4de046db54ef351cc2a25ff9bd353b19a3ba141 Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 5 Nov 2014 21:37:25 +0000 Subject: [PATCH] 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 --- sources/editor/esevent/eseventaddline.cpp | 5 +--- sources/editor/esevent/eseventaddline.h | 4 +++ sources/editor/partline.cpp | 18 +++++++++++++ sources/editor/partline.h | 31 +++++++++++++++++------ 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/sources/editor/esevent/eseventaddline.cpp b/sources/editor/esevent/eseventaddline.cpp index b935e537c..7f201ff00 100644 --- a/sources/editor/esevent/eseventaddline.cpp +++ b/sources/editor/esevent/eseventaddline.cpp @@ -63,7 +63,6 @@ bool ESEventAddLine::mousePressEvent(QGraphicsSceneMouseEvent *event) { } //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)); //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) { updateHelpCross (event -> scenePos()); - if (!m_line) return false; - QPointF pos = m_scene -> snapToGrid(event -> scenePos()); - m_line -> setLine(QLineF(m_line->line().p1(), pos)); + m_line -> setP2(m_scene -> snapToGrid(event -> scenePos())); return true; } diff --git a/sources/editor/esevent/eseventaddline.h b/sources/editor/esevent/eseventaddline.h index 4a0903546..692af12c1 100644 --- a/sources/editor/esevent/eseventaddline.h +++ b/sources/editor/esevent/eseventaddline.h @@ -24,6 +24,10 @@ class ElementScene; class PartLine; class QGraphicsSceneMouseEvent; +/** + * @brief The ESEventAddLine class + * This ESEvent manage creation of line in a ElementScene + */ class ESEventAddLine : public ESEventInterface { public: diff --git a/sources/editor/partline.cpp b/sources/editor/partline.cpp index 23f5f8e6d..0b9637d5b 100644 --- a/sources/editor/partline.cpp +++ b/sources/editor/partline.cpp @@ -223,6 +223,15 @@ void PartLine::setY1(qreal y1) { 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 * set x of P2 @@ -245,6 +254,15 @@ void PartLine::setY2(qreal y2) { 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 @param change Type de changement diff --git a/sources/editor/partline.h b/sources/editor/partline.h index 1880383e3..1133226eb 100644 --- a/sources/editor/partline.h +++ b/sources/editor/partline.h @@ -74,35 +74,50 @@ class PartLine : public CustomElementGraphicPart, public QGraphicsLineItem { static QList fourEndPoints(const QPointF &, const QPointF &, const qreal &); ///PROPERTY - // X value of the first point + // X value of the first point Q_PROPERTY(qreal x1 READ x1 WRITE setX1) qreal x1() const {return sceneP1().x();} void setX1(qreal x1); - // Y value of the first point + + // Y value of the first point Q_PROPERTY(qreal y1 READ y1 WRITE setY1) qreal y1() const {return sceneP1().y();} void setY1(qreal y1); - // X value of the second point + + //pos of firts point + Q_PROPERTY(QPointF p1 READ sceneP1 WRITE setP1) + void setP1 (QPointF p1); + + // X value of the second point Q_PROPERTY(qreal x2 READ x2 WRITE setX2) qreal x2() const {return sceneP2().x();} void setX2(qreal x2); - // Y value of the second point + + // Y value of the second point Q_PROPERTY(qreal y2 READ y2 WRITE setY2) qreal y2() const {return sceneP2().y();} void setY2(qreal y2); - // End type of the first point + + //pos of second point + Q_PROPERTY(QPointF p2 READ sceneP2 WRITE setP2) + void setP2 (QPointF p2); + + // End type of the first point Q_PROPERTY(Qet::EndType end1 READ firstEndType WRITE setFirstEndType) Qet::EndType firstEndType() const {return first_end;} 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) Qet::EndType secondEndType() const {return second_end;} 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) qreal firstEndLength() const {return first_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) qreal secondEndLength() const {return second_length;} void setSecondEndLength(const qreal &l) {second_length = qMin(qAbs(l), line().length());}