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.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5004 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-08-03 17:04:08 +00:00
parent fec5c95682
commit 0df5391491
3 changed files with 77 additions and 39 deletions

View File

@@ -968,7 +968,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
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 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
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);
}

View File

@@ -140,6 +140,41 @@ void ConductorTextItem::forceRotateByUser(bool rotate_by_user) {
}
}
/**
* @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

View File

@@ -26,7 +26,8 @@ class Conductor;
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
@@ -37,27 +38,23 @@ class ConductorTextItem : public DiagramTextItem {
private:
ConductorTextItem(const ConductorTextItem &);
// attributes
public:
enum { Type = UserType + 1006 };
Conductor *parentConductor() const;
virtual void fromXml(const QDomElement &);
virtual void toXml (QDomElement &xml) const;
// methods
public:
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);
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 *);