Salome HOME
Merge branch 'BR_1328' into BR_DEMO
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Overview.cxx
index a72155b62fffcc03271496c5e44263e6c2fa8e8a..8b53cfeb87a713e091175a169c44ec2f3c14e11d 100644 (file)
@@ -23,6 +23,7 @@
 #include <QApplication>
 #include <QPainter>
 #include <QMouseEvent>
+#include <QLayout>
 
 class HYDROGUI_OverviewBand : public QtxPolyRubberBand
 {
@@ -172,11 +173,15 @@ void HYDROGUI_OverviewBand::update( bool isFromMain )
     int h = main->height();
 
     QPolygon poly;
-    poly.append( myOverview->fromMain( 0, 0 ) );
-    poly.append( myOverview->fromMain( w, 0 ) );
-    poly.append( myOverview->fromMain( w, h ) );
-    poly.append( myOverview->fromMain( 0, h ) );
-    poly.append( myOverview->fromMain( 0, 0 ) );
+    QPoint p1 = myOverview->fromMain( 0, 0 );
+    QPoint p2 = myOverview->fromMain( w, 0 );
+    QPoint p3 = myOverview->fromMain( w, h );
+    QPoint p4 = myOverview->fromMain( 0, h );
+    poly.append( p1 );
+    poly.append( p2 );
+    poly.append( p3 );
+    poly.append( p4 );
+    poly.append( p1 );
     initGeometry( poly );
   }
   else
@@ -213,10 +218,15 @@ void HYDROGUI_OverviewBand::paintEvent( QPaintEvent* thePaintEvent )
 
 
 HYDROGUI_Overview::HYDROGUI_Overview( const QString& theTitle, int theMargin, QWidget* theParent )
-  : QDockWidget( theParent ), myMargin( theMargin ),
+  : QFrame( theParent ), myMargin( theMargin ),
     myMainView( 0 ), myViewPort( 0 ), myBand( 0 )
 {
   setWindowTitle( theTitle );
+  myLayout = new QGridLayout( this );
+  myLayout->setMargin( 0 );
+  myLayout->setSpacing( 0 );
+  myLayout->setRowStretch( 0, 1 );
+  myLayout->setColumnStretch( 0, 1 );
 }
 
 HYDROGUI_Overview::~HYDROGUI_Overview()
@@ -272,23 +282,32 @@ void HYDROGUI_Overview::setMainView( OCCViewer_ViewFrame* theMainView )
   connect( aMainView->getViewPort(), SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ),
            this,       SLOT( OnTransformation() ) );
 
-  myViewPort = new OCCViewer_ViewPort3d( this, myMainView->getViewPort()->getViewer(), V3d_ORTHOGRAPHIC );
-  myViewPort->setBackgroundColor( Qt::white );
+  if( !myViewPort )
+  {
+    myViewPort = new OCCViewer_ViewPort3d( this, myMainView->getViewPort()->getViewer(), V3d_ORTHOGRAPHIC );
+    //myViewPort->setBackgroundColor( Qt::white );
 
-  connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), 
-           this,       SLOT( OnMouseEvent( QMouseEvent* ) ) );
-  connect( myViewPort, SIGNAL( vpResizeEvent( QResizeEvent* ) ),
-           this,       SLOT( OnResizeEvent( QResizeEvent* ) ) );
+    connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), 
+            this,       SLOT( OnMouseEvent( QMouseEvent* ) ) );
+    connect( myViewPort, SIGNAL( vpResizeEvent( QResizeEvent* ) ),
+            this,       SLOT( OnResizeEvent( QResizeEvent* ) ) );
+
+    myLayout->addWidget( myViewPort, 0, 0 );
+  }
 
 #if defined(TEST_MODE) || defined(_DEBUG)
   //qApp->installEventFilter( this );
 #endif
 
-  setWidget( myViewPort );
+  qApp->processEvents();
+
   setTopView();
 
   qApp->processEvents();
-  myBand = new HYDROGUI_OverviewBand( this );
+
+  if( !myBand )
+    myBand = new HYDROGUI_OverviewBand( this );
+
   myBand->update( true );
 }
 
@@ -300,8 +319,11 @@ void HYDROGUI_Overview::setTopView()
   myViewPort->fitAll();
 
   // Apply margins for internal area in the view port
-  QRect aRect( -myMargin, -myMargin, myViewPort->width()+2*myMargin, myViewPort->height()+2*myMargin );
-  myViewPort->fitRect( aRect );
+  if( myMargin>0 )
+  {
+    QRect aRect( -myMargin, -myMargin, myViewPort->width()+2*myMargin, myViewPort->height()+2*myMargin );
+    myViewPort->fitRect( aRect );
+  }
 
   if( myBand )
     myBand->update( true );
@@ -309,7 +331,8 @@ void HYDROGUI_Overview::setTopView()
 
 void HYDROGUI_Overview::OnTransformation()
 {
-  myBand->update( true );
+  if( myBand )
+    myBand->update( true );
 }
 
 QPoint HYDROGUI_Overview::fromMain( int xp, int yp ) const
@@ -378,7 +401,7 @@ bool HYDROGUI_Overview::eventFilter( QObject* theObject, QEvent* theEvent )
     break;
   }*/
 #endif
-  return QDockWidget::eventFilter( theObject, theEvent );
+  return QFrame::eventFilter( theObject, theEvent );
 }
 
 void HYDROGUI_Overview::OnResizeEvent( QResizeEvent* )