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 );