[qet] [3546] Element text item -> mouse double click : If parent element is linked to other element,

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 3546
Author:   blacksun
Date:     2014-12-13 15:01:09 +0100 (Sat, 13 Dec 2014)
Log Message:
-----------
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)

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/elementtextitem.cpp
    trunk/sources/qetgraphicsitem/elementtextitem.h

Modified: trunk/sources/qetgraphicsitem/elementtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitem.cpp	2014-12-12 18:39:12 UTC (rev 3545)
+++ trunk/sources/qetgraphicsitem/elementtextitem.cpp	2014-12-13 14:01:09 UTC (rev 3546)
@@ -174,23 +174,42 @@
 }
 
 /**
-	Effetue la rotation du texte en elle-meme
-	Pour les ElementTextItem, la rotation s'effectue autour du milieu du bord
-	gauche du champ de texte.
-	@param angle Angle de la rotation a effectuer
-*/
-void ElementTextItem::applyRotation(const qreal &angle) {
-	QGraphicsTextItem::setRotation(QGraphicsTextItem::rotation() + angle);
+ * @brief ElementTextItem::mouseDoubleClickEvent
+ * @param event
+ */
+void ElementTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
+		//If parent is linked, show the linked element
+	if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_ -> isFree()) {
+			//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
  * @param e
  */
-void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
+void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 	if (textInteractionFlags() & Qt::TextEditable) {
-		DiagramTextItem::mouseMoveEvent(e);
-	} else if ((flags() & QGraphicsItem::ItemIsMovable) && (e -> buttons() & Qt::LeftButton)) {
+		DiagramTextItem::mouseMoveEvent(event);
+	} else if ((flags() & QGraphicsItem::ItemIsMovable) && (event -> buttons() & Qt::LeftButton)) {
 		QPointF old_pos = pos();
 
 		/*
@@ -199,7 +218,7 @@
 		 * 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
 		 */
-		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
@@ -207,7 +226,7 @@
 		 * before applyRotation
 		 */
 		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();
 		if (diagram_ptr) {
@@ -233,7 +252,7 @@
 			// on applique le mouvement subi aux autres textes a deplacer
 			diagram_ptr -> continueMoveElementTexts(scene_effective_movement);
 		}
-	} else e -> ignore();
+	} else event -> ignore();
 
 	if (m_first_move) {
 		m_first_move = false;
@@ -244,7 +263,7 @@
  * @brief ElementTextItem::mouseReleaseEvent
  * @param e
  */
-void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
+void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
 	if (Diagram *diagram_ptr = diagram()) {
 		if (parent_element_) {
 			if (parent_element_ -> isHighlighted()) {
@@ -254,7 +273,47 @@
 
 		diagram_ptr -> endMoveElementTexts();
 	}
-	if (!(e -> modifiers() & Qt::ControlModifier)) {
-		QGraphicsTextItem::mouseReleaseEvent(e);
+	if (!(event -> modifiers() & Qt::ControlModifier)) {
+		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);
+}

Modified: trunk/sources/qetgraphicsitem/elementtextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitem.h	2014-12-12 18:39:12 UTC (rev 3545)
+++ trunk/sources/qetgraphicsitem/elementtextitem.h	2014-12-13 14:01:09 UTC (rev 3546)
@@ -30,52 +30,51 @@
 */
 class ElementTextItem : public DiagramTextItem {
 	Q_OBJECT
-	// constructors, destructor
+		// constructors, destructor
 	public:
-	ElementTextItem(Element * = 0, Diagram * = 0);
-	ElementTextItem(const QString &, Element * = 0, Diagram * = 0);
-	virtual ~ElementTextItem();
+		ElementTextItem(Element * = 0, Diagram * = 0);
+		ElementTextItem(const QString &, Element * = 0, Diagram * = 0);
+		virtual ~ElementTextItem();
 	
-	// attributes
+		// attributes
 	public:
-	enum { Type = UserType + 1003 };
+		enum { Type = UserType + 1003 };
+		virtual int type () const { return Type; }
 	
 	private:
-	Element *parent_element_;
-	bool follow_parent_rotations;
-	QPointF original_position;
-	qreal original_rotation_angle_;
-	QString tagg_;
+		Element *parent_element_;
+		bool     follow_parent_rotations;
+		QPointF  original_position;
+		qreal    original_rotation_angle_;
+		QString  tagg_;
 	
-	// methods
-	public:
-	virtual int type() const { return Type; }
-	Element *parentElement() const;
-	/// @return the rectangle defining the bounds of this text item
-	virtual QRectF boundingRect() const { return(QGraphicsTextItem::boundingRect().adjusted(0.0, -1.1, 0.0, 0.0)); }
-	bool followParentRotations() const;
-	void setFollowParentRotations(bool);
-	void fromXml(const QDomElement &);
-	QDomElement toXml(QDomDocument &) const;
-	void setOriginalPos(const QPointF &);
-	QPointF originalPos() const;
-	void setOriginalRotationAngle(const qreal &);
-	qreal originalRotationAngle() const;
-	virtual void setFont(const QFont &);
-	void setTagg(const QString &str) {tagg_ = str;}
-	QString tagg() const {return tagg_;}
+		// methods
+	public:	
+		Element     *parentElement            () const;
+		void         fromXml                  ( const QDomElement & );
+		QDomElement  toXml                    ( QDomDocument & ) const;
+		void         setOriginalPos           ( const QPointF & );
+		QPointF      originalPos              () const;
+		void         setOriginalRotationAngle ( const qreal & );
+		qreal        originalRotationAngle    () const;
+		virtual void setFont                  ( const QFont & );
+		void         setTagg                  ( const QString &str ) {tagg_ = str;}
+		QString      tagg                     () const               {return tagg_;}
+		void         setFollowParentRotations ( bool fpr);
+		bool         followParentRotations    () const;
 	
 	public slots:
-	void adjustItemPosition(int = 0);
+		void adjustItemPosition(int = 0);
 	
 	protected:
-	virtual void applyRotation(const qreal &);
+		virtual void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *event );
+		virtual void mouseMoveEvent        ( QGraphicsSceneMouseEvent *event );
+		virtual void mouseReleaseEvent     ( QGraphicsSceneMouseEvent *event );
+		virtual void hoverEnterEvent       ( QGraphicsSceneHoverEvent *event );
+		virtual void hoverLeaveEvent       ( QGraphicsSceneHoverEvent *event );
 
-	virtual void mouseMoveEvent    (QGraphicsSceneMouseEvent *e);
-	virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *e);
-
 	private:
-	void build();
+		void build ();
 };
 
 /**


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/