From: mpa Date: Fri, 7 Nov 2014 07:33:47 +0000 (+0300) Subject: 0022379: EDF 2276 GEOM: Dependency Tree - added resize event for view and new method... X-Git-Tag: V7_5_0rc1~8^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5bc218e9c82ed4e0ec75a712a411c22e9b5f2aca;p=modules%2Fgeom.git 0022379: EDF 2276 GEOM: Dependency Tree - added resize event for view and new method of showing tree considering a size of scene --- diff --git a/src/DependencyTree/DependencyTree_View.cxx b/src/DependencyTree/DependencyTree_View.cxx index b1afd4085..1ccb309f1 100644 --- a/src/DependencyTree/DependencyTree_View.cxx +++ b/src/DependencyTree/DependencyTree_View.cxx @@ -351,6 +351,18 @@ void DependencyTree_View::onRebuildModel() updateModel( true, false ); } +//================================================================================= +// function : resizeEvent() +// purpose : reimplemented from QGraphicsView::resizeEvent() +//================================================================================= +void DependencyTree_View::resizeEvent(QResizeEvent *event) +{ + QPointF aCenter = mapToScene( event->oldSize().width()/2, + event->oldSize().height()/2 ); + QGraphicsView::resizeEvent( event ); + centerOn( aCenter.x(),aCenter.y() ); +} + //================================================================================= // function : onUpdateModel() // purpose : slot for updating tree model for main objects in viewer @@ -689,7 +701,7 @@ void DependencyTree_View::updateView() return; drawTree(); - fitAll(); + fitWindow(); } //================================================================================= @@ -734,6 +746,23 @@ void DependencyTree_View::clearView( bool isClearModel ) } } +//================================================================================= +// function : fitWindow() +// purpose : scale the window considering a size of scene +//================================================================================= +void DependencyTree_View::fitWindow() +{ + int sizeFactor = 4; + if( objectsBoundingRect(true).width() > sizeFactor*size().width() || + objectsBoundingRect(true).height() > sizeFactor*size().width() ) { + QRectF aRect = QRectF( -sizeFactor*size().width()/2, -sizeFactor*size().height()/2, + sizeFactor*size().width(), sizeFactor*size().height() ); + fitInView( aRect, Qt::KeepAspectRatio ); + } + else + fitAll(); +} + //================================================================================= // function : getNewTreeModel() // purpose : get dependency tree model from engine diff --git a/src/DependencyTree/DependencyTree_View.h b/src/DependencyTree/DependencyTree_View.h index 298933729..94e924749 100644 --- a/src/DependencyTree/DependencyTree_View.h +++ b/src/DependencyTree/DependencyTree_View.h @@ -68,6 +68,10 @@ public slots: void onRebuildModel(); +protected: + + void resizeEvent( QResizeEvent *event ); + private slots: void onUpdateModel(); @@ -93,6 +97,8 @@ private: void updateView(); void clearView( bool ); + void fitWindow(); + int checkMaxLevelsNumber(); void getNewTreeModel( bool = true, bool = true );