diff --git a/sources/bordertitleblock.cpp b/sources/bordertitleblock.cpp index e7faa97cb..18b3b4cd5 100644 --- a/sources/bordertitleblock.cpp +++ b/sources/bordertitleblock.cpp @@ -199,6 +199,7 @@ void BorderTitleBlock::borderToXml(QDomElement &xml_elmt) { @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 @@ void BorderTitleBlock::borderFromXml(const QDomElement &xml_elmt) { 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)); } /** diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 273cc2932..ea57394d9 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -67,7 +67,6 @@ Diagram::Diagram(QETProject *project) : 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 @@ Diagram::Diagram(QETProject *project) : 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())); + }); } /** diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index e2e27922e..e5bf4d14a 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -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 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : 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::zoomOutSlowly() { */ void DiagramView::zoomFit() { adjustSceneRect(); - fitInView(sceneRect(), Qt::KeepAspectRatio); + fitInView(scene->sceneRect(), Qt::KeepAspectRatio); adjustGridToZoom(); } @@ -772,25 +772,17 @@ void DiagramView::removeRow() { } /** - 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 @@ void DiagramView::resetConductors() { 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 diff --git a/sources/diagramview.h b/sources/diagramview.h index e9305cc0f..793047a90 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -53,6 +53,7 @@ class DiagramView : public QGraphicsView { QPointF rubber_band_origin; bool fresh_focus_in_; ///< Indicate the focus was freshly gained ElementsLocation next_location_; + bool m_first_activation; // methods