#include <QCursor>
#include <QGraphicsSceneMouseEvent>
+#include <QLabel>
+#include <QMoveEvent>
#include <QRectF>
#include <QRubberBand>
#include <QScrollBar>
+#include <QVBoxLayout>
#include <math.h>
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 :
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 ) );
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 :
{
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;
}
Q_OBJECT
public:
+ class NameLabel;
+
enum BlockStatus
{
BS_NoBlock = 0x0000,
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 );
static QCursor* zoomCursor;
private:
+ // scene
GraphicsView_Scene* myScene;
+ // view name
+ NameLabel* myNameLabel;
+
// foreground
bool myIsForegroundEnabled;
QSizeF myForegroundSize;