mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 06:20:53 +01:00
Element text item -> mouse double click : If parent element is linked to other element,
show the other element (only work for report and salve element) git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3546 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -174,23 +174,42 @@ void ElementTextItem::adjustItemPosition(int new_block_count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Effetue la rotation du texte en elle-meme
|
* @brief ElementTextItem::mouseDoubleClickEvent
|
||||||
Pour les ElementTextItem, la rotation s'effectue autour du milieu du bord
|
* @param event
|
||||||
gauche du champ de texte.
|
*/
|
||||||
@param angle Angle de la rotation a effectuer
|
void ElementTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
*/
|
//If parent is linked, show the linked element
|
||||||
void ElementTextItem::applyRotation(const qreal &angle) {
|
if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_ -> isFree()) {
|
||||||
QGraphicsTextItem::setRotation(QGraphicsTextItem::rotation() + angle);
|
//Unselect and ungrab mouse to prevent unwanted
|
||||||
|
//move when linked element is in the same scene of this.
|
||||||
|
setSelected(false);
|
||||||
|
ungrabMouse();
|
||||||
|
|
||||||
|
//Show and select the linked element
|
||||||
|
Element *linked = parent_element_ -> linkedElements().first();
|
||||||
|
if (scene() != linked -> scene()) linked -> diagram() -> showMe();
|
||||||
|
linked -> setSelected(true);
|
||||||
|
|
||||||
|
//Zoom to the linked element
|
||||||
|
foreach(QGraphicsView *view, linked -> diagram() -> views()) {
|
||||||
|
QRectF fit = linked -> sceneBoundingRect();
|
||||||
|
fit.adjust(-200, -200, 200, 200);
|
||||||
|
view -> fitInView(fit, Qt::KeepAspectRatioByExpanding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DiagramTextItem::mouseDoubleClickEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementTextItem::mouseMoveEvent
|
* @brief ElementTextItem::mouseMoveEvent
|
||||||
* @param e
|
* @param e
|
||||||
*/
|
*/
|
||||||
void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
if (textInteractionFlags() & Qt::TextEditable) {
|
if (textInteractionFlags() & Qt::TextEditable) {
|
||||||
DiagramTextItem::mouseMoveEvent(e);
|
DiagramTextItem::mouseMoveEvent(event);
|
||||||
} else if ((flags() & QGraphicsItem::ItemIsMovable) && (e -> buttons() & Qt::LeftButton)) {
|
} else if ((flags() & QGraphicsItem::ItemIsMovable) && (event -> buttons() & Qt::LeftButton)) {
|
||||||
QPointF old_pos = pos();
|
QPointF old_pos = pos();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -199,7 +218,7 @@ void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
* Instead of this, we apply to the actual pos,
|
* Instead of this, we apply to the actual pos,
|
||||||
* the vector defined by the movement of cursor since the last pos clicked by left button
|
* the vector defined by the movement of cursor since the last pos clicked by left button
|
||||||
*/
|
*/
|
||||||
QPointF movement = e -> pos() - e -> buttonDownPos(Qt::LeftButton);
|
QPointF movement = event -> pos() - event -> buttonDownPos(Qt::LeftButton);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the method pos() and setPos() always work with coordinate of parent item
|
* the method pos() and setPos() always work with coordinate of parent item
|
||||||
@@ -207,7 +226,7 @@ void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
* before applyRotation
|
* before applyRotation
|
||||||
*/
|
*/
|
||||||
QPointF new_pos = pos() + mapMovementToParent(movement);
|
QPointF new_pos = pos() + mapMovementToParent(movement);
|
||||||
e -> modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
|
event -> modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
|
||||||
|
|
||||||
Diagram *diagram_ptr = diagram();
|
Diagram *diagram_ptr = diagram();
|
||||||
if (diagram_ptr) {
|
if (diagram_ptr) {
|
||||||
@@ -233,7 +252,7 @@ void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
// on applique le mouvement subi aux autres textes a deplacer
|
// on applique le mouvement subi aux autres textes a deplacer
|
||||||
diagram_ptr -> continueMoveElementTexts(scene_effective_movement);
|
diagram_ptr -> continueMoveElementTexts(scene_effective_movement);
|
||||||
}
|
}
|
||||||
} else e -> ignore();
|
} else event -> ignore();
|
||||||
|
|
||||||
if (m_first_move) {
|
if (m_first_move) {
|
||||||
m_first_move = false;
|
m_first_move = false;
|
||||||
@@ -244,7 +263,7 @@ void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
* @brief ElementTextItem::mouseReleaseEvent
|
* @brief ElementTextItem::mouseReleaseEvent
|
||||||
* @param e
|
* @param e
|
||||||
*/
|
*/
|
||||||
void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
if (Diagram *diagram_ptr = diagram()) {
|
if (Diagram *diagram_ptr = diagram()) {
|
||||||
if (parent_element_) {
|
if (parent_element_) {
|
||||||
if (parent_element_ -> isHighlighted()) {
|
if (parent_element_ -> isHighlighted()) {
|
||||||
@@ -254,7 +273,47 @@ void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
|
|
||||||
diagram_ptr -> endMoveElementTexts();
|
diagram_ptr -> endMoveElementTexts();
|
||||||
}
|
}
|
||||||
if (!(e -> modifiers() & Qt::ControlModifier)) {
|
if (!(event -> modifiers() & Qt::ControlModifier)) {
|
||||||
QGraphicsTextItem::mouseReleaseEvent(e);
|
QGraphicsTextItem::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementTextItem::hoverEnterEvent
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
void ElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
|
if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_->isFree()) {
|
||||||
|
setDefaultTextColor(Qt::blue);
|
||||||
|
|
||||||
|
//Also color the child text if parent is a slave and linked
|
||||||
|
if (parent_element_-> linkType() == Element::Slave && !parent_element_ -> isFree()) {
|
||||||
|
foreach (QGraphicsItem *qgi, childItems()) {
|
||||||
|
if (QGraphicsTextItem *qgti = qgraphicsitem_cast<QGraphicsTextItem *> (qgi))
|
||||||
|
qgti->setDefaultTextColor(Qt::blue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DiagramTextItem::hoverEnterEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementTextItem::hoverLeaveEvent
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
void ElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
|
if (defaultTextColor() != Qt::black)
|
||||||
|
setDefaultTextColor(Qt::black);
|
||||||
|
|
||||||
|
//Also color the child text if parent is a slave and linked
|
||||||
|
if (parent_element_-> linkType() == Element::Slave && !parent_element_ -> isFree()) {
|
||||||
|
foreach (QGraphicsItem *qgi, childItems()) {
|
||||||
|
if (QGraphicsTextItem *qgti = qgraphicsitem_cast<QGraphicsTextItem *> (qgi))
|
||||||
|
qgti->setDefaultTextColor(Qt::black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagramTextItem::hoverLeaveEvent(event);
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,52 +30,51 @@ class Element;
|
|||||||
*/
|
*/
|
||||||
class ElementTextItem : public DiagramTextItem {
|
class ElementTextItem : public DiagramTextItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
public:
|
public:
|
||||||
ElementTextItem(Element * = 0, Diagram * = 0);
|
ElementTextItem(Element * = 0, Diagram * = 0);
|
||||||
ElementTextItem(const QString &, Element * = 0, Diagram * = 0);
|
ElementTextItem(const QString &, Element * = 0, Diagram * = 0);
|
||||||
virtual ~ElementTextItem();
|
virtual ~ElementTextItem();
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1003 };
|
enum { Type = UserType + 1003 };
|
||||||
|
virtual int type () const { return Type; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Element *parent_element_;
|
Element *parent_element_;
|
||||||
bool follow_parent_rotations;
|
bool follow_parent_rotations;
|
||||||
QPointF original_position;
|
QPointF original_position;
|
||||||
qreal original_rotation_angle_;
|
qreal original_rotation_angle_;
|
||||||
QString tagg_;
|
QString tagg_;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
virtual int type() const { return Type; }
|
Element *parentElement () const;
|
||||||
Element *parentElement() const;
|
void fromXml ( const QDomElement & );
|
||||||
/// @return the rectangle defining the bounds of this text item
|
QDomElement toXml ( QDomDocument & ) const;
|
||||||
virtual QRectF boundingRect() const { return(QGraphicsTextItem::boundingRect().adjusted(0.0, -1.1, 0.0, 0.0)); }
|
void setOriginalPos ( const QPointF & );
|
||||||
bool followParentRotations() const;
|
QPointF originalPos () const;
|
||||||
void setFollowParentRotations(bool);
|
void setOriginalRotationAngle ( const qreal & );
|
||||||
void fromXml(const QDomElement &);
|
qreal originalRotationAngle () const;
|
||||||
QDomElement toXml(QDomDocument &) const;
|
virtual void setFont ( const QFont & );
|
||||||
void setOriginalPos(const QPointF &);
|
void setTagg ( const QString &str ) {tagg_ = str;}
|
||||||
QPointF originalPos() const;
|
QString tagg () const {return tagg_;}
|
||||||
void setOriginalRotationAngle(const qreal &);
|
void setFollowParentRotations ( bool fpr);
|
||||||
qreal originalRotationAngle() const;
|
bool followParentRotations () const;
|
||||||
virtual void setFont(const QFont &);
|
|
||||||
void setTagg(const QString &str) {tagg_ = str;}
|
|
||||||
QString tagg() const {return tagg_;}
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void adjustItemPosition(int = 0);
|
void adjustItemPosition(int = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void applyRotation(const qreal &);
|
virtual void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *event );
|
||||||
|
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent *event );
|
||||||
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *e);
|
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event );
|
||||||
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *e);
|
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent *event );
|
||||||
|
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent *event );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void build();
|
void build ();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user