]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Interface for changing view name position
authorouv <ouv@opencascade.com>
Fri, 25 Feb 2011 11:05:02 +0000 (11:05 +0000)
committerouv <ouv@opencascade.com>
Fri, 25 Feb 2011 11:05:02 +0000 (11:05 +0000)
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/GraphicsView_ViewPort.h

index 158c436c4627f8a44ad0c807e06bc123591db398..2258de9c20788b7d0bf2889eb29f7005373fdbbd 100644 (file)
 
 #include <QCursor>
 #include <QGraphicsSceneMouseEvent>
+#include <QGridLayout>
 #include <QLabel>
 #include <QMoveEvent>
 #include <QRectF>
 #include <QRubberBand>
 #include <QScrollBar>
-#include <QVBoxLayout>
 
 #include <math.h>
 
@@ -121,6 +121,8 @@ void GraphicsView_ViewPort::destroyCursors()
 GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
 : QGraphicsView( theParent ),
   myNameLabel( 0 ),
+  myNamePosition( NP_None ),
+  myNameLayout( 0 ),
   myForegroundItem( 0 ),
   myIsTransforming( false ),
   myHighlightedObject( 0 ),
@@ -344,22 +346,43 @@ void GraphicsView_ViewPort::setFitAllGap( double theFitAllGap )
 // Function : setViewNameEnabled
 // Purpose  : 
 //================================================================
-void GraphicsView_ViewPort::setViewNameEnabled( bool theState,
-                                                bool theIsForced )
+void GraphicsView_ViewPort::setViewNamePosition( NamePosition thePosition,
+                                                 bool theIsForced )
 {
   if( theIsForced && !myNameLabel )
-  {
     myNameLabel = new NameLabel( viewport() );
 
-    QBoxLayout* aLayout = new QVBoxLayout( viewport() );
-    aLayout->setMargin( 10 );
-    aLayout->setSpacing( 0 );
-    aLayout->addStretch();
-    aLayout->addWidget( myNameLabel );
+  if( !myNameLabel )
+    return;
+
+  if( thePosition == NP_None )
+  {
+    myNameLabel->setVisible( false );
+    return;
   }
 
-  if( myNameLabel )
-    myNameLabel->setVisible( theState );
+  if( myNameLayout )
+    delete myNameLayout;
+
+  myNameLayout = new QGridLayout( viewport() );
+  myNameLayout->setMargin( 10 );
+  myNameLayout->setSpacing( 0 );
+
+  int aRow = 0, aColumn = 0;
+  switch( thePosition )
+  {
+    case NP_TopLeft:     aRow = 0; aColumn = 0; break;
+    case NP_TopRight:    aRow = 0; aColumn = 1; break;
+    case NP_BottomLeft:  aRow = 1; aColumn = 0; break;
+    case NP_BottomRight: aRow = 1; aColumn = 1; break;
+    default: break;
+  }
+
+  myNameLayout->addWidget( myNameLabel, aRow, aColumn );
+  myNameLayout->setRowStretch( 1 - aRow, 1 );
+  myNameLayout->setColumnStretch( 1 - aColumn, 1 );
+
+  myNameLabel->setVisible( true );
 }
 
 //================================================================
index 63da84203c573689ea995eeceb084f34e52a77a0..45a0ce15be04c0964ad3054cb91acc3ebbd25ec8 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <QGraphicsView>
 
+class QGridLayout;
 class QRubberBand;
 
 class GraphicsView_Object;
@@ -52,6 +53,15 @@ public:
     BS_Dragging  = 0x0002  // currently unused
   };
 
+  enum NamePosition
+  {
+    NP_None         = 0,
+    NP_TopLeft      = 1,
+    NP_TopRight     = 2,
+    NP_BottomLeft   = 3,
+    NP_BottomRight  = 4
+  };
+
 public:
   GraphicsView_ViewPort( QWidget* theParent );
   ~GraphicsView_ViewPort();
@@ -73,7 +83,8 @@ public:
   void                             setFitAllGap( double theFitAllGap );
 
   // view name
-  void                             setViewNameEnabled( bool theState, bool theIsForced = false );
+  void                             setViewNamePosition( NamePosition thePosition,
+                                                        bool theIsForced = false );
   void                             setViewName( const QString& theName );
 
   // background / foreground
@@ -197,6 +208,8 @@ private:
 
   // view name
   NameLabel*                       myNameLabel;
+  NamePosition                     myNamePosition;
+  QGridLayout*                     myNameLayout;
 
   // foreground
   bool                             myIsForegroundEnabled;