From: ouv Date: Fri, 19 Nov 2010 14:05:58 +0000 (+0000) Subject: Added possibility of displaying name of view inside viewport itself X-Git-Tag: DIAGRAM_0_1~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=507dca8c3260c87f1ba243c15703dc6712fe4458;p=modules%2Fgui.git Added possibility of displaying name of view inside viewport itself --- diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 8db01df0b..6559b44a9 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -31,9 +31,12 @@ #include #include +#include +#include #include #include #include +#include #include @@ -44,6 +47,40 @@ QCursor* GraphicsView_ViewPort::panCursor = 0; QCursor* GraphicsView_ViewPort::panglCursor = 0; QCursor* GraphicsView_ViewPort::zoomCursor = 0; +//======================================================================= +// Name : GraphicsView_ViewPort::NameLabel +// Purpose : Wrapper for label, which can ignore move events sent from +// QGraphicsView::scrollContentsBy() method, which, +// in its turn, called from GraphicsView_ViewPort::pan() +//======================================================================= +class GraphicsView_ViewPort::NameLabel : public QLabel +{ +public: + NameLabel( QWidget* theParent ) : QLabel( theParent ) {} + ~NameLabel() {} + + void setAcceptMoveEvents( bool theFlag ) + { + myAcceptMoveEvents = theFlag; + } + +protected: + virtual void moveEvent( QMoveEvent* theEvent ) + { + if( myAcceptMoveEvents ) + QLabel::moveEvent( theEvent ); + else // return the label to the initial position + { + myAcceptMoveEvents = true; + move( theEvent->oldPos() ); + myAcceptMoveEvents = false; + } + } + +private: + bool myAcceptMoveEvents; +}; + //================================================================ // Function : createCursors // Purpose : @@ -95,6 +132,14 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myScene = new GraphicsView_Scene( this ); setScene( myScene ); + // view name + myNameLabel = new NameLabel( viewport() ); + myNameLabel->setVisible( false ); + + QBoxLayout* aLayout = new QVBoxLayout( viewport() ); + aLayout->addStretch(); + aLayout->addWidget( myNameLabel ); + // background setBackgroundBrush( QBrush( Qt::white ) ); @@ -258,6 +303,24 @@ QImage GraphicsView_ViewPort::dumpView( bool theWholeScene ) return anImage; } +//================================================================ +// Function : setViewName +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setViewName( const QString& theName ) +{ + myNameLabel->setText( theName ); +} + +//================================================================ +// Function : setViewNameEnabled +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setViewNameEnabled( bool theState ) +{ + myNameLabel->setVisible( theState ); +} + //================================================================ // Function : backgroundColor // Purpose : @@ -384,11 +447,15 @@ void GraphicsView_ViewPort::pan( double theDX, double theDY ) { myIsTransforming = true; + myNameLabel->setAcceptMoveEvents( false ); + if( QScrollBar* aHBar = horizontalScrollBar() ) aHBar->setValue( aHBar->value() - theDX ); if( QScrollBar* aVBar = verticalScrollBar() ) aVBar->setValue( aVBar->value() + theDY ); + myNameLabel->setAcceptMoveEvents( true ); + myIsTransforming = false; } diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index a20583892..93ea6f62c 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -43,6 +43,8 @@ class GRAPHICSVIEW_API GraphicsView_ViewPort : public QGraphicsView Q_OBJECT public: + class NameLabel; + enum BlockStatus { BS_NoBlock = 0x0000, @@ -64,6 +66,10 @@ public: QImage dumpView( bool theWholeScene = false ); public: + // view name + void setViewName( const QString& theName ); + void setViewNameEnabled( bool theState ); + // background / foreground QColor backgroundColor() const; void setBackgroundColor( const QColor& theColor ); @@ -171,8 +177,12 @@ private: static QCursor* zoomCursor; private: + // scene GraphicsView_Scene* myScene; + // view name + NameLabel* myNameLabel; + // foreground bool myIsForegroundEnabled; QSizeF myForegroundSize;