[qet] [3861] Diagram view :

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


Revision: 3861
Author:   blacksun
Date:     2015-03-27 10:45:19 +0100 (Fri, 27 Mar 2015)
Log Message:
-----------
Diagram view :
-Set maximum Visualized scene to diagram scene rect*2.
-At first activation, view call zoom fit to see all of the diagram

Modified Paths:
--------------
    trunk/sources/bordertitleblock.cpp
    trunk/sources/diagram.cpp
    trunk/sources/diagramview.cpp
    trunk/sources/diagramview.h

Modified: trunk/sources/bordertitleblock.cpp
===================================================================
--- trunk/sources/bordertitleblock.cpp	2015-03-26 19:56:25 UTC (rev 3860)
+++ trunk/sources/bordertitleblock.cpp	2015-03-27 09:45:19 UTC (rev 3861)
@@ -199,6 +199,7 @@
 	@param xml_elmt the XML element values will be read from
 */
 void BorderTitleBlock::borderFromXml(const QDomElement &xml_elmt) {
+	QRectF old_rect = diagram_rect_;
 	bool ok;
 	// columns count
 	int cols_count = xml_elmt.attribute("cols").toInt(&ok);
@@ -228,6 +229,11 @@
 	displayRows(xml_elmt.attribute("displayrows") != "false");
 
 	updateRectangles();
+
+		//We emit signal even if diagram_rect not change
+		//For calcul the scene rect when diagram load the first time the border.
+	if (old_rect == diagram_rect_)
+		emit(borderChanged(old_rect, old_rect));
 }
 
 /**

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2015-03-26 19:56:25 UTC (rev 3860)
+++ trunk/sources/diagram.cpp	2015-03-27 09:45:19 UTC (rev 3861)
@@ -67,7 +67,6 @@
 	QPen pen(Qt::NoBrush, 1.5, Qt::DashLine);
 	pen.setColor(Qt::black);
 	conductor_setter_ -> setPen(pen);
-	//conductor_setter_ -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0)));
 	
 		//Init object for manage movement
 	elements_mover_      = new ElementsMover();
@@ -75,6 +74,11 @@
 
 	connect(&border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)), this, SLOT(setTitleBlockTemplate(const QString &)));
 	connect(&border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)),    this, SLOT(titleChanged(const QString &)));
+	connect(&border_and_titleblock, &BorderTitleBlock::borderChanged, [this]() {
+		QRectF old_rect = this->sceneRect();
+		this->setSceneRect(border_and_titleblock.borderAndTitleBlockRect().united(this->itemsBoundingRect()));
+		this->update(old_rect.united(this->sceneRect()));
+	});
 }
 
 /**

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2015-03-26 19:56:25 UTC (rev 3860)
+++ trunk/sources/diagramview.cpp	2015-03-27 09:45:19 UTC (rev 3861)
@@ -52,7 +52,8 @@
 DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
 	QGraphicsView     (parent),
 	scene             (diagram),
-	m_event_interface (nullptr)
+	m_event_interface (nullptr),
+	m_first_activation (true)
 {
 	grabGesture(Qt::PinchGesture);
 	setAttribute(Qt::WA_DeleteOnClose, true);
@@ -87,8 +88,7 @@
 	
 	connect(scene, SIGNAL(showDiagram(Diagram*)), this, SIGNAL(showDiagram(Diagram*)));
 	connect(scene, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
-	connect(&(scene -> border_and_titleblock), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
-	connect(&(scene -> border_and_titleblock), SIGNAL(displayChanged()),              this, SLOT(adjustSceneRect()));
+	connect(scene, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(adjustSceneRect()));
 	connect(&(scene -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
 	connect(diagram, SIGNAL(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation)));
 	connect(diagram, SIGNAL(findElementRequired(ElementsLocation)), this, SIGNAL(findElementRequired(ElementsLocation)));
@@ -395,7 +395,7 @@
 */
 void DiagramView::zoomFit() {
 	adjustSceneRect();
-	fitInView(sceneRect(), Qt::KeepAspectRatio);
+	fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
 	adjustGridToZoom();
 }
 
@@ -772,25 +772,17 @@
 }
 
 /**
-	Ajuste le sceneRect (zone du schema visualisee par le DiagramView) afin que
-	celui inclut a la fois les elements dans et en dehors du cadre et le cadre
-	lui-meme.
-*/
-void DiagramView::adjustSceneRect() {
-	QRectF old_scene_rect = sceneRect();
-	
-	// rectangle delimitant l'ensemble des elements
-	QRectF elements_bounding_rect = scene -> itemsBoundingRect();
-	
-	// rectangle contenant le cadre = colonnes + cartouche
-	QRectF border_bounding_rect = scene -> border_and_titleblock.borderAndTitleBlockRect().adjusted(-Diagram::margin, -Diagram::margin, Diagram::margin, Diagram::margin);
-	
-	// ajuste la sceneRect
-	QRectF new_scene_rect = elements_bounding_rect.united(border_bounding_rect);
-	setSceneRect(new_scene_rect);
-	
-	// met a jour la scene
-	scene -> update(old_scene_rect.united(new_scene_rect));
+ * @brief DiagramView::adjustSceneRect
+ * Calcul and set the area of the scene visualized by this view
+ * The area are diagram sceneRect * 2.
+ */
+void DiagramView::adjustSceneRect()
+{
+	QRectF scene_rect = scene->sceneRect();
+	scene_rect.adjust(-Diagram::margin, -Diagram::margin, Diagram::margin, Diagram::margin);
+	scene_rect.setWidth(scene_rect.width()*2);
+	scene_rect.setHeight(scene_rect.height()*2);
+	setSceneRect(scene_rect);
 }
 
 /**
@@ -1013,7 +1005,22 @@
 	Gere les evenements de la DiagramView
 	@param e Evenement
 */
+/**
+ * @brief DiagramView::event
+ * Manage the event on this diagram view.
+ * -At first activation (QEvent::WindowActivate or QEvent::Show) we zoomFit.
+ * -Convert event interpreted to mouse event to gesture event if needed.
+ * -send Shortcut to view (by default send to QMenu /QAction)
+ * @param e the event.
+ * @return
+ */
 bool DiagramView::event(QEvent *e) {
+	if (Q_UNLIKELY(m_first_activation)) {
+		if (e -> type() == QEvent::Show) {
+			zoomFit();
+			m_first_activation = false;
+		}
+	}
 	// By default touch events are converted to mouse events. So
 	// after this event we will get a mouse event also but we want
 	// to handle touch events as gestures only. So we need this safeguard

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2015-03-26 19:56:25 UTC (rev 3860)
+++ trunk/sources/diagramview.h	2015-03-27 09:45:19 UTC (rev 3861)
@@ -53,6 +53,7 @@
 		QPointF           rubber_band_origin;
 		bool              fresh_focus_in_;    ///< Indicate the focus was freshly gained
 		ElementsLocation  next_location_;
+		bool m_first_activation;
 
 
 	// methods


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