[qet] qet/qet: [5004] Fix the left margin of the diagram : In some condition, ( most of time when use copy and paste) a margin appear in the left of the folio. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
- To: qet@xxxxxxxxxxxxxxxxxxx
- Subject: [qet] qet/qet: [5004] Fix the left margin of the diagram : In some condition, ( most of time when use copy and paste) a margin appear in the left of the folio.
- From: subversion@xxxxxxxxxxxxx
- Date: Thu, 03 Aug 2017 19:04:09 +0200
Revision: 5004
Author: blacksun
Date: 2017-08-03 19:04:08 +0200 (Thu, 03 Aug 2017)
Log Message:
-----------
Fix the left margin of the diagram : In some condition, (most of time when use copy and paste) a margin appear in the left of the folio.
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/qetgraphicsitem/conductortextitem.cpp
trunk/sources/qetgraphicsitem/conductortextitem.h
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2017-08-03 16:53:43 UTC (rev 5003)
+++ trunk/sources/diagram.cpp 2017-08-03 17:04:08 UTC (rev 5004)
@@ -968,7 +968,7 @@
qgi -> setPos( qgi -> pos() += pos_);
}
- // remplissage des listes facultatives
+ //Filling of optional lists
if (content_ptr) {
content_ptr -> elements = added_elements.toSet();
content_ptr -> conductorsToMove = added_conductors.toSet();
@@ -976,6 +976,12 @@
content_ptr -> images = added_images.toSet();
content_ptr -> shapes = added_shapes.toSet();
}
+
+ //Ensure the texts of conductor are inside the border of the folio
+ //and so don't cause the annoying margin on the left border of the folio.
+ for(Conductor *cond : added_conductors)
+ cond->textItem()->setPos(cond->textItem()->pos());
+
adjustSceneRect();
return(true);
}
Modified: trunk/sources/qetgraphicsitem/conductortextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductortextitem.cpp 2017-08-03 16:53:43 UTC (rev 5003)
+++ trunk/sources/qetgraphicsitem/conductortextitem.cpp 2017-08-03 17:04:08 UTC (rev 5004)
@@ -137,10 +137,45 @@
rotate_by_user_ = rotate_by_user;
if (!rotate_by_user && parent_conductor_) {
parent_conductor_ -> calculateTextItemPosition();
- }
+ }
}
/**
+ * @brief ConductorTextItem::setPos
+ * @param pos
+ */
+void ConductorTextItem::setPos(const QPointF &pos)
+{
+ /*
+ * In some condition the conductor text item is outside the border of folio in the left.
+ * They cause a margin on the left of folio and in most case this margin is unwanted and annoying the user.
+ * If the text is empty and the scene position is outside the border (left and top),
+ * we can say that this position, is unwanted by user.
+ * So we move this text item to the top left of the bounding rect of parent conductors, because we sure this position is wanted by user.
+ */
+ DiagramTextItem::setPos(pos);
+ if(toPlainText().isEmpty() && (scenePos().x() < 0 || scenePos().y() < 0))
+ {
+ Conductor *cond = parentConductor();
+ if(cond)
+ DiagramTextItem::setPos(cond->boundingRect().topLeft());
+ else
+ DiagramTextItem::setPos(0,0);
+ }
+}
+
+/**
+ * @brief ConductorTextItem::setPos
+ * @param x
+ * @param y
+ */
+void ConductorTextItem::setPos(qreal x, qreal y)
+{
+ QPointF p(x,y);
+ setPos(p);
+}
+
+/**
* @brief ConductorTextItem::mousePressEvent
* @param event
*/
@@ -238,5 +273,5 @@
*/
void ConductorTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
Q_UNUSED(e);
- QGraphicsTextItem::hoverMoveEvent(e);
+ QGraphicsTextItem::hoverMoveEvent(e);
}
Modified: trunk/sources/qetgraphicsitem/conductortextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductortextitem.h 2017-08-03 16:53:43 UTC (rev 5003)
+++ trunk/sources/qetgraphicsitem/conductortextitem.h 2017-08-03 17:04:08 UTC (rev 5004)
@@ -26,47 +26,44 @@
Its movements are however limited to a particular distance around its
parent conductor.
*/
-class ConductorTextItem : public DiagramTextItem {
+class ConductorTextItem : public DiagramTextItem
+{
Q_OBJECT
- // constructors, destructor
+ // constructors, destructor
public:
- ConductorTextItem(Conductor * = 0);
- ConductorTextItem(const QString &, Conductor * = 0);
- virtual ~ConductorTextItem();
+ ConductorTextItem(Conductor * = 0);
+ ConductorTextItem(const QString &, Conductor * = 0);
+ virtual ~ConductorTextItem();
private:
- ConductorTextItem(const ConductorTextItem &);
-
- // attributes
+ ConductorTextItem(const ConductorTextItem &);
+
public:
- enum { Type = UserType + 1006 };
- Conductor *parentConductor() const;
- virtual void fromXml(const QDomElement &);
- virtual void toXml (QDomElement &xml) const;
+ enum { Type = UserType + 1006 };
+ Conductor *parentConductor() const;
+ virtual void fromXml(const QDomElement &);
+ virtual void toXml (QDomElement &xml) const;
+ virtual int type() const { return Type; }
+ virtual bool wasMovedByUser() const;
+ virtual bool wasRotateByUser() const;
+ virtual void forceMovedByUser(bool);
+ virtual void forceRotateByUser(bool);
+ virtual void setPos(const QPointF &pos);
+ virtual void setPos(qreal x, qreal y);
- // methods
- public:
- virtual int type() const { return Type; }
- virtual bool wasMovedByUser() const;
- virtual bool wasRotateByUser() const;
- virtual void forceMovedByUser(bool);
- virtual void forceRotateByUser(bool);
-
protected:
- virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
- virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
- virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
-
- protected:
- virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
- virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
- virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
+ virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
+ virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
+ virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
+ virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
+ virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *);
- // attributes
+ // attributes
private:
- Conductor *parent_conductor_;
- bool moved_by_user_;
- bool rotate_by_user_;
- QPointF before_mov_pos_;
+ Conductor *parent_conductor_;
+ bool moved_by_user_;
+ bool rotate_by_user_;
+ QPointF before_mov_pos_;
};
#endif