--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifdef WIN32
+
+#ifdef GRAPHICSVIEW_EXPORTS
+#define GRAPHICSVIEW_API __declspec(dllexport)
+#else
+#define GRAPHICSVIEW_API __declspec(dllimport)
+#endif
+
+#else
+#define GRAPHICSVIEW_API
+#endif // WIN32
+
--- /dev/null
+#ifndef GRAPHICSVIEW_DEFS_H
+#define GRAPHICSVIEW_DEFS_H
+
+#include <QList>
+
+class GraphicsView_Object;
+typedef QList<GraphicsView_Object*> GraphicsView_ObjectList;
+typedef QListIterator<GraphicsView_Object*> GraphicsView_ObjectListIterator;
+
+enum GV_SelectionChangeStatus
+{
+ GVSCS_Invalid,
+ GVSCS_Local,
+ GVSCS_Global
+};
+
+enum GV_SelectionStatus
+{
+ GVSS_Invalid,
+ GVSS_LocalChanged,
+ GVSS_GlobalChanged,
+ GVSS_NoChanged
+};
+
+#endif
--- /dev/null
+#ifndef GRAPHICSVIEW_GEOM_H
+#define GRAPHICSVIEW_GEOM_H
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Object.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_Object.h"
+
+//=======================================================================
+// Name : GraphicsView_Object
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent )
+: QGraphicsItemGroup( theParent ),
+ myIsHighlighted( false ),
+ myIsSelected( false )
+{
+}
+
+//=======================================================================
+// Name : GraphicsView_Object
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_Object::~GraphicsView_Object()
+{
+}
+
+//================================================================
+// Function : setName
+// Purpose :
+//================================================================
+void GraphicsView_Object::setName( const QString& theName )
+{
+ myName = theName;
+}
+
+//================================================================
+// Function : getRect
+// Purpose :
+//================================================================
+QRectF GraphicsView_Object::getRect() const
+{
+ return sceneBoundingRect();
+}
+
+//================================================================
+// Function : checkHighlight
+// Purpose :
+//================================================================
+bool GraphicsView_Object::checkHighlight( double theX, double theY ) const
+{
+ return getRect().contains( theX, theY );
+}
+
+//================================================================
+// Function : highlight
+// Purpose :
+//================================================================
+bool GraphicsView_Object::highlight( double theX, double theY )
+{
+ if( myIsHighlighted = isVisible() )
+ myIsHighlighted = checkHighlight( theX, theY );
+ return myIsHighlighted;
+}
+
+//================================================================
+// Function : unhighlight
+// Purpose :
+//================================================================
+void GraphicsView_Object::unhighlight()
+{
+ myIsHighlighted = false;
+}
+
+//================================================================
+// Function : select
+// Purpose :
+//================================================================
+bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect )
+{
+ if( myIsSelected = isVisible() )
+ {
+ if( !theRect.isNull() )
+ myIsSelected = theRect.contains( getRect() );
+ else
+ myIsSelected = checkHighlight( theX, theY );
+ }
+ return myIsSelected;
+}
+
+//================================================================
+// Function : unselect
+// Purpose :
+//================================================================
+void GraphicsView_Object::unselect()
+{
+ myIsSelected = false;
+}
+
+//================================================================
+// Function : move
+// Purpose :
+//================================================================
+void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
+{
+ moveBy( theDX, theDY );
+ if( theIsAtOnce )
+ finishMove();
+}
+
+//================================================================
+// Function : finishMove
+// Purpose :
+//================================================================
+bool GraphicsView_Object::finishMove()
+{
+ return true;
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Object.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_OBJECT_H
+#define GRAPHICSVIEW_OBJECT_H
+
+#include "GraphicsView.h"
+
+#include <QGraphicsItemGroup>
+
+/*
+ Class : GraphicsView_Object
+ Description : Base class for all objects displayed at the scene
+*/
+class GRAPHICSVIEW_API GraphicsView_Object : public QGraphicsItemGroup
+{
+public:
+ GraphicsView_Object( QGraphicsItem* theParent = 0 );
+ ~GraphicsView_Object();
+
+ virtual void compute() = 0;
+
+ const QString& getName() const { return myName; }
+ void setName( const QString& theName );
+
+ virtual bool isSelectable() const { return true; }
+ virtual bool isMovable() const { return true; }
+
+ virtual QRectF getRect() const;
+
+ virtual bool highlight( double theX, double theY );
+ virtual void unhighlight();
+ virtual bool isHighlighted() const { return myIsHighlighted; }
+
+ virtual bool select( double theX, double theY, const QRectF& theRect );
+ virtual void unselect();
+ virtual bool isSelected() const { return myIsSelected; }
+ virtual void setSelected( bool theState ) { myIsSelected = theState; }
+
+ virtual void move( double theDX, double theDY, bool theIsAtOnce = false );
+ virtual bool finishMove();
+ virtual bool isMovingByXAllowed( double theDX ) { return true; }
+ virtual bool isMovingByYAllowed( double theDY ) { return true; }
+
+ virtual QRectF getPullingRect() const { return getRect(); }
+ virtual bool portContains( const QPointF& ) { return false; }
+ virtual bool startPulling( const QPointF& ) { return false; }
+ virtual void pull( const QPointF&, GraphicsView_Object* ) {}
+ virtual void finishPulling() {}
+ virtual bool isPulling() { return false; }
+
+protected:
+ virtual bool checkHighlight( double theX, double theY ) const;
+
+protected:
+ QString myName;
+
+ bool myIsHighlighted;
+ bool myIsSelected;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Scene.cxx
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_Scene.h"
+
+//=======================================================================
+// Name : GraphicsView_Scene
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_Scene::GraphicsView_Scene( QObject* theParent )
+: QGraphicsScene( theParent )
+{
+}
+
+//=======================================================================
+// Name : GraphicsView_Scene
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_Scene::~GraphicsView_Scene()
+{
+}
+
+//================================================================
+// Function : mousePressEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mousePressEvent( e );
+}
+
+//================================================================
+// Function : mouseMoveEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mouseMoveEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mouseMoveEvent( e );
+}
+
+//================================================================
+// Function : mouseReleaseEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mouseReleaseEvent( e );
+}
+
+//================================================================
+// Function : mouseDoubleClickEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit gsMouseEvent( e );
+ QGraphicsScene::mouseDoubleClickEvent( e );
+}
+
+//================================================================
+// Function : contextMenuEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
+{
+ emit gsContextMenuEvent( e );
+ QGraphicsScene::contextMenuEvent( e );
+}
+
+//================================================================
+// Function : dragEnterEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dragEnterEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dragEnterEvent( e ); // don't uncomment
+}
+
+//================================================================
+// Function : dragLeaveEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dragLeaveEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dragLeaveEvent( e ); // don't uncomment
+}
+
+//================================================================
+// Function : dragMoveEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dragMoveEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dragMoveEvent( e ); // don't uncomment
+}
+
+//================================================================
+// Function : dropEvent
+// Purpose :
+//================================================================
+void GraphicsView_Scene::dropEvent( QGraphicsSceneDragDropEvent* e )
+{
+ //QGraphicsScene::dropEvent( e ); // don't uncomment
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Scene.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_SCENE_H
+#define GRAPHICSVIEW_SCENE_H
+
+#include "GraphicsView.h"
+
+#include <QGraphicsScene>
+
+/*
+ Class : GraphicsView_Scene
+ Description : Scene of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_Scene : public QGraphicsScene
+{
+ Q_OBJECT
+
+public:
+ GraphicsView_Scene( QObject* theParent = 0 );
+ ~GraphicsView_Scene();
+
+protected:
+ virtual void mousePressEvent( QGraphicsSceneMouseEvent* );
+ virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* );
+ virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* );
+ virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* );
+ virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+ virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* );
+ virtual void dragLeaveEvent( QGraphicsSceneDragDropEvent* );
+ virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* );
+ virtual void dropEvent( QGraphicsSceneDragDropEvent* );
+
+signals:
+ void gsMouseEvent( QGraphicsSceneMouseEvent* );
+ void gsWheelEvent( QGraphicsSceneWheelEvent* );
+ void gsContextMenuEvent( QGraphicsSceneContextMenuEvent* );
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Selector.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_Selector.h"
+#include "GraphicsView_Viewer.h"
+#include "GraphicsView_ViewPort.h"
+#include "GraphicsView_ViewFrame.h"
+
+int GraphicsView_Selector::appendKey = Qt::ShiftModifier;
+
+//=======================================================================
+// Name : GraphicsView_Selector
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_Selector::GraphicsView_Selector( GraphicsView_Viewer* theViewer )
+: QObject( 0 ),
+ myViewer( theViewer ),
+ myLocked( false )
+{
+}
+
+//=======================================================================
+// Name : GraphicsView_Selector
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_Selector::~GraphicsView_Selector()
+{
+}
+
+//================================================================
+// Function : detect
+// Purpose :
+//================================================================
+void GraphicsView_Selector::detect( double x, double y )
+{
+ if ( myLocked )
+ return;
+
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ aViewPort->highlight( x, y );
+}
+
+//================================================================
+// Function : undetectAll
+// Purpose :
+//================================================================
+void GraphicsView_Selector::undetectAll()
+{
+ if ( myLocked )
+ return;
+
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ aViewPort->clearHighlighted();
+}
+
+//================================================================
+// Function : select
+// Purpose :
+//================================================================
+void GraphicsView_Selector::select( const QRectF& selRect, bool append )
+{
+ if ( myLocked )
+ return;
+
+ int selBefore = numSelected();
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ {
+ int aStatus = aViewPort->select( selRect, append );
+ checkSelection( selBefore, append, aStatus );
+ }
+}
+
+//================================================================
+// Function : unselectAll
+// Purpose :
+//================================================================
+void GraphicsView_Selector::unselectAll()
+{
+ if ( myLocked )
+ return;
+
+ if ( numSelected() > 0 )
+ emit selSelectionCancel();
+}
+
+//================================================================
+// Function : checkSelection
+// Purpose :
+//================================================================
+void GraphicsView_Selector::checkSelection( int selBefore, bool append, int theStatus )
+{
+ int selAfter = numSelected();
+ if ( selBefore > 0 && selAfter < 1 )
+ emit selSelectionCancel();
+ else if ( selAfter > 0 )
+ {
+ switch( theStatus )
+ {
+ case GVSS_LocalChanged:
+ emit selSelectionDone( GVSCS_Local );
+ break;
+ case GVSS_GlobalChanged:
+ emit selSelectionDone( GVSCS_Global );
+ break;
+ }
+ }
+}
+
+//================================================================
+// Function : numSelected
+// Purpose :
+//================================================================
+int GraphicsView_Selector::numSelected() const
+{
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ return aViewPort->nbSelected();
+ return 0;
+}
+
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Selector.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_SELECTOR_H
+#define GRAPHICSVIEW_SELECTOR_H
+
+#include "GraphicsView.h"
+
+#include "GraphicsView_Defs.h"
+
+#include <QObject>
+#include <QRectF>
+
+class GraphicsView_Viewer;
+
+/*
+ Class : GraphicsView_Selector
+ Description : Selector of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_Selector : public QObject
+{
+ Q_OBJECT
+
+public:
+ GraphicsView_Selector( GraphicsView_Viewer* );
+ ~GraphicsView_Selector();
+
+public:
+ void lock( bool theState ) { myLocked = theState; }
+
+ static int getAppendKey() { return appendKey; }
+ static void setAppendKey( int k ) { appendKey = k; }
+
+public:
+ virtual void detect( double, double );
+ virtual void undetectAll();
+
+ virtual void select( const QRectF&, bool append = false );
+ virtual void unselectAll();
+ virtual int numSelected() const;
+
+ virtual void checkSelection( int, bool, int );
+
+signals:
+ void selSelectionDone( GV_SelectionChangeStatus );
+ void selSelectionCancel();
+
+protected:
+ GraphicsView_Viewer* myViewer;
+ bool myLocked;
+
+private:
+ static int appendKey;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewFrame.cxx
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_ViewFrame.h"
+
+#include "GraphicsView_Viewer.h"
+#include "GraphicsView_ViewPort.h"
+
+#include <QtxAction.h>
+#include <QtxActionToolMgr.h>
+#include <QtxMultiAction.h>
+#include <QtxToolBar.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+
+#include <QColor>
+#include <QFrame>
+#include <QFileDialog>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsSceneWheelEvent>
+#include <QHBoxLayout>
+#include <QImage>
+#include <QMouseEvent>
+#include <QString>
+#include <QWheelEvent>
+
+//=======================================================================
+// Name : GraphicsView_ViewFrame
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Viewer* vw )
+: SUIT_ViewWindow( d ),
+ myViewer( vw )
+{
+ QFrame* aFrame = new QFrame( this );
+ setCentralWidget( aFrame );
+
+ QBoxLayout* aLayout = new QHBoxLayout( aFrame );
+ aLayout->setMargin( 0 );
+ aLayout->setSpacing( 0 );
+
+ myViewPort = new GraphicsView_ViewPort( aFrame );
+ aLayout->addWidget( myViewPort );
+
+ createActions();
+ createToolBar();
+
+ connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( mouseEvent( QGraphicsSceneMouseEvent* ) ) );
+ connect( myViewPort, SIGNAL( vpWheelEvent( QGraphicsSceneWheelEvent* ) ),
+ this, SLOT( wheelEvent( QGraphicsSceneWheelEvent* ) ) );
+ connect( myViewPort, SIGNAL( vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
+ this, SLOT( contextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) );
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewFrame
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_ViewFrame::~GraphicsView_ViewFrame()
+{
+}
+
+//================================================================
+// Function : createActions
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::createActions()
+{
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ QtxAction* anAction;
+
+ // Dump view
+ anAction = new QtxAction( tr( "MNU_DUMP_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_DUMP" ) ),
+ tr( "MNU_DUMP_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) );
+ toolMgr()->registerAction( anAction, DumpId );
+
+ // FitAll
+ anAction = new QtxAction( tr( "MNU_FITALL" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITALL" ) ),
+ tr( "MNU_FITALL" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_FITALL" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) );
+ toolMgr()->registerAction( anAction, FitAllId );
+
+ // FitRect
+ anAction = new QtxAction( tr( "MNU_FITRECT" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITAREA" ) ),
+ tr( "MNU_FITRECT" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_FITRECT" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) );
+ toolMgr()->registerAction( anAction, FitRectId );
+
+ // FitSelect
+ anAction = new QtxAction( tr( "MNU_FITSELECT" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_FITSELECT" ) ),
+ tr( "MNU_FITSELECT" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_FITSELECT" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitSelect() ) );
+ toolMgr()->registerAction( anAction, FitSelectId );
+
+ // Zoom
+ anAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_ZOOM" ) ),
+ tr( "MNU_ZOOM_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) );
+ toolMgr()->registerAction( anAction, ZoomId );
+
+ // Panning
+ anAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_PAN" ) ),
+ tr( "MNU_PAN_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) );
+ toolMgr()->registerAction( anAction, PanId );
+
+ // Global Panning
+ anAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_GLOBALPAN" ) ),
+ tr( "MNU_GLOBALPAN_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) );
+ toolMgr()->registerAction( anAction, GlobalPanId );
+
+ // Reset (obsolete)
+ /*
+ anAction = new QtxAction( tr( "MNU_RESET_VIEW" ),
+ aResMgr->loadPixmap( "GraphicsView", tr( "ICON_GV_RESET" ) ),
+ tr( "MNU_RESET_VIEW" ), 0, this );
+ anAction->setStatusTip( tr( "DSC_RESET_VIEW" ) );
+ connect( anAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) );
+ toolMgr()->registerAction( anAction, ResetId );
+ */
+}
+
+//================================================================
+// Function : createToolBar
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::createToolBar()
+{
+ int tid = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL") );
+ toolMgr()->append( DumpId, tid );
+
+ QtxMultiAction* aScaleAction = new QtxMultiAction( this );
+ aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
+ aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
+ aScaleAction->insertAction( toolMgr()->action( FitSelectId ) );
+ aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
+ toolMgr()->append( aScaleAction, tid );
+
+ QtxMultiAction* aPanAction = new QtxMultiAction( this );
+ aPanAction->insertAction( toolMgr()->action( PanId ) );
+ aPanAction->insertAction( toolMgr()->action( GlobalPanId ) );
+ toolMgr()->append( aPanAction, tid );
+
+ toolMgr()->append( toolMgr()->action( ResetId ), tid );
+}
+
+//================================================================
+// Function : dumpView
+// Purpose :
+//================================================================
+QImage GraphicsView_ViewFrame::dumpView()
+{
+ return myViewPort->dumpView();
+}
+
+//================================================================
+// Function : onViewPan
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewPan()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::Pan );
+}
+
+//================================================================
+// Function : onViewZoom
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewZoom()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::Zoom );
+}
+
+//================================================================
+// Function : onViewFitAll
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewFitAll()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::FitAll );
+}
+
+//================================================================
+// Function : onViewFitArea
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewFitArea()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::FitRect );
+}
+
+//================================================================
+// Function : onViewFitSelect
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewFitSelect()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::FitSelect );
+}
+
+//================================================================
+// Function : onViewGlobalPan
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewGlobalPan()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::PanGlobal );
+}
+
+//================================================================
+// Function : onViewReset
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::onViewReset()
+{
+ myViewer->activateTransform( GraphicsView_Viewer::Reset );
+}
+
+//================================================================
+// Function : mouseEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::mouseEvent( QGraphicsSceneMouseEvent* e )
+{
+ switch ( e->type() )
+ {
+ case QEvent::GraphicsSceneMousePress:
+ emit mousePressed( e );
+ break;
+ case QEvent::GraphicsSceneMouseMove:
+ emit mouseMoving( e );
+ break;
+ case QEvent::GraphicsSceneMouseRelease:
+ emit mouseReleased( e );
+ break;
+ case QEvent::GraphicsSceneMouseDoubleClick:
+ emit mouseDoubleClicked( e );
+ break;
+ default:
+ break;
+ }
+}
+
+//================================================================
+// Function : wheelEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e )
+{
+ switch ( e->type() )
+ {
+ case QEvent::Wheel:
+ emit wheeling( e );
+ break;
+ default:
+ break;
+ }
+}
+
+//================================================================
+// Function : contextMenuEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewFrame::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
+{
+ QPoint aPos = myViewPort->mapFromScene( e->scenePos() );
+ QContextMenuEvent* anEvent = new QContextMenuEvent( (QContextMenuEvent::Reason)e->reason(),
+ aPos, e->screenPos(), e->modifiers() );
+ emit contextMenuRequested( anEvent );
+ delete anEvent;
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewFrame.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_VIEWFRAME_H
+#define GRAPHICSVIEW_VIEWFRAME_H
+
+#include "GraphicsView.h"
+
+#include <SUIT_ViewWindow.h>
+
+class QGraphicsSceneContextMenuEvent;
+class QGraphicsSceneMouseEvent;
+class QGraphicsSceneWheelEvent;
+
+class SUIT_Desktop;
+
+class GraphicsView_Viewer;
+class GraphicsView_ViewPort;
+
+/*
+ Class : GraphicsView_ViewFrame
+ Description : View frame of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_ViewFrame : public SUIT_ViewWindow
+{
+ Q_OBJECT
+
+public:
+ enum { DumpId, FitAllId, FitRectId, FitSelectId, ZoomId, PanId, GlobalPanId, ResetId };
+
+public:
+ GraphicsView_ViewFrame( SUIT_Desktop*, GraphicsView_Viewer* );
+ ~GraphicsView_ViewFrame();
+
+public:
+ GraphicsView_Viewer* getViewer() const { return myViewer; }
+ GraphicsView_ViewPort* getViewPort() const { return myViewPort; }
+
+ virtual QImage dumpView();
+
+protected slots:
+ void onViewPan();
+ void onViewZoom();
+ void onViewFitAll();
+ void onViewFitArea();
+ void onViewFitSelect();
+ void onViewGlobalPan();
+ void onViewReset();
+
+private slots:
+ void mouseEvent( QGraphicsSceneMouseEvent* );
+ void wheelEvent( QGraphicsSceneWheelEvent* );
+ void contextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+signals:
+ void mousePressed( QGraphicsSceneMouseEvent* );
+ void mouseMoving( QGraphicsSceneMouseEvent* );
+ void mouseReleased( QGraphicsSceneMouseEvent* );
+ void mouseDoubleClicked( QGraphicsSceneMouseEvent* );
+ void wheeling( QGraphicsSceneWheelEvent* );
+
+private:
+ void createActions();
+ void createToolBar();
+
+private:
+ GraphicsView_Viewer* myViewer;
+ GraphicsView_ViewPort* myViewPort;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewManager.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_ViewManager.h"
+#include "GraphicsView_Viewer.h"
+
+//=======================================================================
+// Name : GraphicsView_ViewManager
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_ViewManager::GraphicsView_ViewManager( SUIT_Study* theStudy,
+ SUIT_Desktop* theDesktop )
+: SUIT_ViewManager( theStudy, theDesktop, new GraphicsView_Viewer( "GraphicsView" ) )
+{
+ setTitle( tr( "GRAPHICS_VIEW_TITLE" ) );
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewManager
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_ViewManager::~GraphicsView_ViewManager()
+{
+}
+
+//================================================================
+// Function : getViewer
+// Purpose :
+//================================================================
+GraphicsView_Viewer* GraphicsView_ViewManager::getViewer()
+{
+ return dynamic_cast<GraphicsView_Viewer*>( getViewModel() );
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewManager.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_VIEWMANAGER_H
+#define GRAPHICSVIEW_VIEWMANAGER_H
+
+#include "GraphicsView.h"
+
+#include <SUIT_ViewManager.h>
+
+class GraphicsView_Viewer;
+
+/*
+ Class : GraphicsView_ViewManager
+ Description : View manager of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_ViewManager : public SUIT_ViewManager
+{
+ Q_OBJECT
+
+public:
+ GraphicsView_ViewManager( SUIT_Study* theStudy,
+ SUIT_Desktop* theDesktop );
+ virtual ~GraphicsView_ViewManager();
+
+ GraphicsView_Viewer* getViewer();
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewPort.cxx
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_ViewPort.h"
+
+#include "GraphicsView_Object.h"
+#include "GraphicsView_Scene.h"
+#include "GraphicsView_ViewTransformer.h"
+
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+
+#include <QCursor>
+#include <QGraphicsSceneMouseEvent>
+#include <QRectF>
+#include <QRubberBand>
+#include <QScrollBar>
+
+#include <math.h>
+
+int GraphicsView_ViewPort::nCounter = 0;
+QCursor* GraphicsView_ViewPort::defCursor = 0;
+QCursor* GraphicsView_ViewPort::handCursor = 0;
+QCursor* GraphicsView_ViewPort::panCursor = 0;
+QCursor* GraphicsView_ViewPort::panglCursor = 0;
+QCursor* GraphicsView_ViewPort::zoomCursor = 0;
+
+//================================================================
+// Function : createCursors
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::createCursors ()
+{
+ defCursor = new QCursor( Qt::ArrowCursor );
+ handCursor = new QCursor( Qt::PointingHandCursor );
+ panCursor = new QCursor( Qt::SizeAllCursor );
+ panglCursor = new QCursor( Qt::CrossCursor );
+
+ SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
+ zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) );
+}
+
+//================================================================
+// Function : destroyCursors
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::destroyCursors()
+{
+ delete defCursor; defCursor = 0;
+ delete handCursor; handCursor = 0;
+ delete panCursor; panCursor = 0;
+ delete panglCursor; panglCursor = 0;
+ delete zoomCursor; zoomCursor = 0;
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewPort
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
+: QGraphicsView( theParent ),
+ myForegroundItem( 0 ),
+ myIsTransforming( false ),
+ myHighlightedObject( 0 ),
+ myHighlightX( 0 ),
+ myHighlightY( 0 ),
+ mySelectionIterator( 0 ),
+ myRectBand( 0 ),
+ myAreSelectionPointsInitialized( false ),
+ myIsDragging( false ),
+ myIsDragPositionInitialized( false ),
+ myIsPulling( false ),
+ myPullingObject( 0 )
+{
+ // scene
+ myScene = new GraphicsView_Scene( this );
+ setScene( myScene );
+
+ // background
+ setBackgroundBrush( QBrush( Qt::white ) );
+
+ // foreground
+ myIsForegroundEnabled = false;
+ myForegroundSize = QSizeF( 100, 30 );
+ myForegroundMargin = 0.0;
+ myForegroundColor = Qt::white;
+ myForegroundFrameColor = Qt::black;
+ myForegroundFrameLineWidth = 1.0;
+
+ // render hints (default - TextAntialiasing only)
+ setRenderHints( QPainter::Antialiasing |
+ QPainter::TextAntialiasing |
+ QPainter::SmoothPixmapTransform |
+ QPainter::HighQualityAntialiasing );
+
+ connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+ connect( myScene, SIGNAL( gsWheelEvent( QGraphicsSceneWheelEvent* ) ),
+ this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
+ connect( myScene, SIGNAL( gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
+ this, SLOT( onContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) );
+
+ initialize();
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewPort
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_ViewPort::~GraphicsView_ViewPort()
+{
+ cleanup();
+
+ if( myScene )
+ {
+ delete myScene;
+ myScene = 0;
+ }
+}
+
+//================================================================
+// Function : initialize
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::initialize()
+{
+ if ( nCounter++ == 0 )
+ createCursors();
+
+ setMouseTracking( true );
+ setFocusPolicy( Qt::StrongFocus );
+}
+
+//================================================================
+// Function : cleanup
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::cleanup()
+{
+ if ( --nCounter == 0 )
+ destroyCursors();
+}
+
+//================================================================
+// Function : addItem
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem )
+{
+ myScene->addItem( theItem );
+}
+
+//================================================================
+// Function : removeItem
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem )
+{
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
+ {
+ if( myHighlightedObject == anObject )
+ myHighlightedObject = 0;
+ mySelectedObjects.removeAll( anObject );
+ }
+ myScene->removeItem( theItem );
+}
+
+//================================================================
+// Function : dumpView
+// Purpose :
+//================================================================
+QImage GraphicsView_ViewPort::dumpView( bool theWholeScene )
+{
+ if( !theWholeScene ) // just grab the view contents
+ {
+ QPixmap aPixmap = QPixmap::grabWindow( viewport()->winId() );
+ return aPixmap.toImage();
+ }
+
+ // get a bounding rect of all presented objects
+ // (itemsBoundingRect() method is unsuitable)
+ QRectF aRect;
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ if( aRect.isNull() )
+ aRect = anObject->getRect();
+ else
+ aRect |= anObject->getRect();
+ }
+ }
+
+ if( aRect.isNull() )
+ return QImage();
+
+ // store a list of selected objects
+ GraphicsView_ObjectList aSelectedObjects = mySelectedObjects;
+
+ // unhighlight and unselect all objects
+ clearHighlighted();
+ clearSelected();
+
+ // render the scene to an image
+ QImage anImage( aRect.toRect().size(), QImage::Format_RGB32 );
+ QPainter aPainter( &anImage );
+ QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() );
+ myScene->render( &aPainter, aTargetRect, aRect );
+
+ // restore selection
+ GraphicsView_ObjectListIterator aSelectedIter( aSelectedObjects );
+ while( aSelectedIter.hasNext() )
+ if( GraphicsView_Object* anObject = aSelectedIter.next() )
+ {
+ setSelected( anObject );
+ anObject->compute();
+ }
+
+ return anImage;
+}
+
+//================================================================
+// Function : backgroundColor
+// Purpose :
+//================================================================
+QColor GraphicsView_ViewPort::backgroundColor() const
+{
+ return backgroundBrush().color();
+}
+
+//================================================================
+// Function : setBackgroundColor
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setBackgroundColor( const QColor& theColor )
+{
+ setBackgroundBrush( QBrush( theColor ) );
+}
+
+//================================================================
+// Function : setForegroundEnabled
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundEnabled( bool theState )
+{
+ myIsForegroundEnabled = theState;
+}
+
+//================================================================
+// Function : setForegroundSize
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundSize( const QSizeF& theSize )
+{
+ myForegroundSize = theSize;
+}
+
+//================================================================
+// Function : setForegroundMargin
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundMargin( double theMargin )
+{
+ myForegroundMargin = theMargin;
+}
+
+//================================================================
+// Function : setForegroundColor
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundColor( const QColor& theColor )
+{
+ myForegroundColor = theColor;
+}
+
+//================================================================
+// Function : setForegroundFrameColor
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundFrameColor( const QColor& theColor )
+{
+ myForegroundFrameColor = theColor;
+}
+
+//================================================================
+// Function : setForegroundFrameLineWidth
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setForegroundFrameLineWidth( double theLineWidth )
+{
+ myForegroundFrameLineWidth = theLineWidth;
+}
+
+//================================================================
+// Function : updateForeground
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::updateForeground()
+{
+ if( myIsForegroundEnabled )
+ {
+ if( !myForegroundItem )
+ myForegroundItem = myScene->addRect( QRectF(), QPen(), QBrush( Qt::white ) );
+ myForegroundItem->setZValue( -1 );
+
+ QRectF aRect( QPointF(), myForegroundSize );
+ aRect.adjust( -myForegroundMargin, -myForegroundMargin,
+ myForegroundMargin, myForegroundMargin );
+ myForegroundItem->setRect( aRect );
+
+ QBrush aBrush = myForegroundItem->brush();
+ aBrush.setColor( myForegroundColor );
+ myForegroundItem->setBrush( aBrush );
+
+ QPen aPen = myForegroundItem->pen();
+ aPen.setColor( myForegroundFrameColor );
+ aPen.setWidthF( myForegroundFrameLineWidth );
+ myForegroundItem->setPen( aPen );
+
+ myForegroundItem->setVisible( true );
+
+ myScene->setSceneRect( aRect.adjusted( -20, -20, 20, 20 ) );
+ }
+ else
+ {
+ if( myForegroundItem )
+ myForegroundItem->setVisible( false );
+ }
+}
+
+//================================================================
+// Function : reset
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::reset()
+{
+ fitAll();
+}
+
+//================================================================
+// Function : pan
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::pan( double theDX, double theDY )
+{
+ myIsTransforming = true;
+
+ if( QScrollBar* aHBar = horizontalScrollBar() )
+ aHBar->setValue( aHBar->value() - theDX );
+ if( QScrollBar* aVBar = verticalScrollBar() )
+ aVBar->setValue( aVBar->value() + theDY );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : setCenter
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setCenter( double theX, double theY )
+{
+ myIsTransforming = true;
+
+ setTransform( myCurrentTransform );
+ centerOn( theX, theY );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : zoom
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, double theY2 )
+{
+ myIsTransforming = true;
+
+ double aDX = theX2 - theX1;
+ double aDY = theY2 - theY1;
+ double aZoom = sqrt( aDX * aDX + aDY * aDY ) / 100 + 1;
+ aZoom = ( aDX > 0 ) ? aZoom : 1 / aZoom;
+
+ QTransform aTransform = transform();
+ aTransform.scale( aZoom, aZoom );
+ double aM11 = aTransform.m11();
+ double aM22 = aTransform.m22();
+ if( qMax( aM11, aM22 ) < 400 ) // to prevent a crash at the value of 500
+ setTransform( aTransform );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : fitRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::fitRect( const QRectF& theRect )
+{
+ myIsTransforming = true;
+
+ fitInView( theRect, Qt::KeepAspectRatio );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : fitSelect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::fitSelect()
+{
+ myIsTransforming = true;
+
+ QRectF aGlobalRect;
+ for( initSelected(); moreSelected(); nextSelected() )
+ {
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ {
+ QRectF aRect = aMovingObject->getRect();
+ if( aGlobalRect.isNull() )
+ aGlobalRect = aRect;
+ else
+ aGlobalRect |= aRect;
+ }
+ }
+
+ if( !aGlobalRect.isNull() )
+ {
+ double aGap = qMax( aGlobalRect.width(), aGlobalRect.height() ) / 5;
+ aGlobalRect.adjust( -aGap, -aGap, aGap, aGap );
+ fitInView( aGlobalRect, Qt::KeepAspectRatio );
+ }
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : fitAll
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::fitAll( bool theKeepScale )
+{
+ myIsTransforming = true;
+
+ if( theKeepScale )
+ myCurrentTransform = transform();
+
+ fitInView( sceneRect(), Qt::KeepAspectRatio );
+
+ myIsTransforming = false;
+}
+
+//================================================================
+// Function : currentBlock
+// Purpose :
+//================================================================
+GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock()
+{
+ if( isDragging() && !myDragPosition.isNull() )
+ return BlockStatus( BS_Selection );
+
+ if( myAreSelectionPointsInitialized && ( myFirstSelectionPoint != myLastSelectionPoint ) )
+ return BlockStatus( BS_Selection );
+
+ if( isPulling() )
+ return BlockStatus( BS_Selection );
+
+ return BS_NoBlock;
+}
+
+//================================================================
+// Function : highlight
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::highlight( double theX, double theY )
+{
+ myHighlightX = theX;
+ myHighlightY = theY;
+
+ bool anIsHighlighted = false;
+ bool anIsOnObject = false;
+
+ GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject;
+ GraphicsView_Object* aHighlightedObject = 0;
+
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ if( anObject->isSelectable() )
+ {
+ QRectF aRect = anObject->getRect();
+ if( !aRect.isNull() && aRect.contains( theX, theY ) )
+ {
+ anIsOnObject = true;
+ anIsHighlighted = anObject->highlight( theX, theY );
+ }
+
+ if( anIsHighlighted )
+ {
+ aHighlightedObject = anObject;
+ break;
+ }
+ }
+ }
+ }
+
+ if( !anIsOnObject )
+ {
+ anIter = items();
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ anObject->unhighlight();
+
+ myHighlightedObject = 0;
+ return;
+ }
+ else if( !myHighlightedObject && anIsHighlighted )
+ {
+ myHighlightedObject = aHighlightedObject;
+ }
+ else if( myHighlightedObject && !anIsHighlighted )
+ {
+ myHighlightedObject->unhighlight();
+ myHighlightedObject = 0;
+ }
+ else if( myHighlightedObject && anIsHighlighted )
+ {
+ myHighlightedObject->highlight( theX, theY );
+ if( myHighlightedObject != aHighlightedObject )
+ {
+ myHighlightedObject->unhighlight();
+ myHighlightedObject = aHighlightedObject;
+ }
+ }
+}
+
+//================================================================
+// Function : clearHighlighted
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::clearHighlighted()
+{
+ if( myHighlightedObject )
+ {
+ myHighlightedObject->unhighlight();
+ myHighlightedObject = 0;
+ }
+}
+
+//================================================================
+// Function : select
+// Purpose :
+//================================================================
+int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend )
+{
+ GV_SelectionStatus aStatus = GVSS_Invalid;
+ if( theRect.isNull() ) // point selection
+ {
+ if( myHighlightedObject )
+ {
+ if( mySelectedObjects.count() == 1 &&
+ mySelectedObjects.first() == myHighlightedObject )
+ aStatus = GVSS_LocalChanged;
+
+ if( !theIsAppend )
+ {
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ if( myHighlightedObject != anObject )
+ anObject->unselect();
+
+ if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
+ aStatus = GVSS_GlobalChanged;
+ mySelectedObjects.clear();
+ }
+ else if( myHighlightedObject->isSelected() && aStatus != GVSS_LocalChanged )
+ {
+ mySelectedObjects.removeAll( myHighlightedObject );
+ myHighlightedObject->unselect();
+
+ if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
+ aStatus = GVSS_GlobalChanged;
+
+ return aStatus;
+ }
+
+ if( myHighlightedObject->select( myHighlightX, myHighlightY, QRectF() ) &&
+ mySelectedObjects.indexOf( myHighlightedObject ) == -1 )
+ {
+ mySelectedObjects.append( myHighlightedObject );
+ if( aStatus == GVSS_Invalid )
+ aStatus = GVSS_GlobalChanged;
+ }
+ else if( aStatus == GVSS_LocalChanged )
+ aStatus = GVSS_GlobalChanged;
+
+ return aStatus;
+ }
+
+ if( !myHighlightedObject )
+ {
+ if( !theIsAppend )
+ {
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ if( myHighlightedObject != anObject )
+ anObject->unselect();
+
+ if( !mySelectedObjects.isEmpty() )
+ aStatus = GVSS_GlobalChanged;
+ mySelectedObjects.clear();
+ }
+ return aStatus;
+ }
+
+ return GVSS_NoChanged;
+ }
+ else // rectangle selection
+ {
+ aStatus = GVSS_NoChanged;
+
+ bool updateAll = false;
+ if( !theIsAppend )
+ {
+ if( !mySelectedObjects.isEmpty() )
+ aStatus = GVSS_GlobalChanged;
+
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ if( myHighlightedObject != anObject )
+ anObject->unselect();
+ mySelectedObjects.clear();
+ }
+
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ if( anObject->isSelectable() )
+ {
+ bool anIsSelected = false;
+ QRectF aRect = anObject->getRect();
+ if( theRect.contains( aRect ) )
+ anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect );
+
+ if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 )
+ {
+ mySelectedObjects.append( anObject );
+ aStatus = GVSS_GlobalChanged;
+ }
+ }
+ }
+ }
+ }
+ return aStatus;
+}
+
+//================================================================
+// Function : clearSelected
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::clearSelected()
+{
+ GraphicsView_ObjectListIterator anIter( mySelectedObjects );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* anObject = anIter.next() )
+ anObject->unselect();
+ mySelectedObjects.clear();
+}
+
+//================================================================
+// Function : setSelected
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::setSelected( GraphicsView_Object* theObject )
+{
+ if( theObject )
+ {
+ theObject->setSelected( true );
+ mySelectedObjects.append( theObject );
+ }
+}
+
+//================================================================
+// Function : nbSelected
+// Purpose :
+//================================================================
+int GraphicsView_ViewPort::nbSelected() const
+{
+ return mySelectedObjects.count();
+}
+
+//================================================================
+// Function : initSelected
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::initSelected()
+{
+ mySelectionIterator = 0;
+}
+
+//================================================================
+// Function : moreSelected
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::moreSelected()
+{
+ return mySelectionIterator < nbSelected();
+}
+
+//================================================================
+// Function : nextSelected
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::nextSelected()
+{
+ if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() )
+ {
+ mySelectionIterator++;
+ return true;
+ }
+ return false;
+}
+
+//================================================================
+// Function : selectedObject
+// Purpose :
+//================================================================
+GraphicsView_Object* GraphicsView_ViewPort::selectedObject()
+{
+ return mySelectedObjects[ mySelectionIterator ];
+}
+
+//================================================================
+// Function : startSelectByRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::startSelectByRect( int x, int y )
+{
+ if( !myAreSelectionPointsInitialized )
+ {
+ myFirstSelectionPoint = QPoint( x, y );
+ myLastSelectionPoint = QPoint( x, y );
+ myAreSelectionPointsInitialized = true;
+ }
+
+ if( !myRectBand )
+ {
+ myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
+ QPalette palette;
+ palette.setColor( myRectBand->foregroundRole(), Qt::white );
+ myRectBand->setPalette( palette );
+ }
+ myRectBand->hide();
+}
+
+//================================================================
+// Function : drawSelectByRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::drawSelectByRect( int x, int y )
+{
+ if( myAreSelectionPointsInitialized )
+ {
+ myRectBand->hide();
+
+ myLastSelectionPoint.setX( x );
+ myLastSelectionPoint.setY( y );
+
+ QRect aRect = selectionRect();
+ myRectBand->setGeometry( aRect );
+ myRectBand->setVisible( aRect.isValid() );
+ }
+}
+
+//================================================================
+// Function : isSelectByRect
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::isSelectByRect() const
+{
+ return myAreSelectionPointsInitialized;
+}
+
+//================================================================
+// Function : finishSelectByRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::finishSelectByRect()
+{
+ if( myAreSelectionPointsInitialized )
+ {
+ if( myRectBand )
+ {
+ myRectBand->hide();
+ delete myRectBand;
+ myRectBand = 0;
+ }
+
+ myAreSelectionPointsInitialized = false;
+ }
+}
+
+//================================================================
+// Function : selectionRect
+// Purpose :
+//================================================================
+QRect GraphicsView_ViewPort::selectionRect()
+{
+ QRect aRect;
+ if( myAreSelectionPointsInitialized )
+ {
+ aRect.setLeft( qMin( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
+ aRect.setTop( qMin( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
+ aRect.setRight( qMax( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
+ aRect.setBottom( qMax( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
+ }
+ return aRect;
+}
+
+//================================================================
+// Function : dragObjects
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e )
+{
+ GraphicsView_Object* anObject = getHighlightedObject();
+
+ if( myDragPosition.isNull() )
+ {
+ myDragPosition = e->scenePos();
+ return;
+ }
+
+ GraphicsView_ObjectList anObjectsToMove;
+ if( anObject && anObject->isMovable() && ( e->buttons() & Qt::LeftButton ) )
+ {
+ if( anObject->isSelected() )
+ {
+ for( initSelected(); moreSelected(); nextSelected() )
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ if( aMovingObject->isMovable() )
+ anObjectsToMove.append( aMovingObject );
+ }
+ else
+ anObjectsToMove.append( anObject );
+ }
+ else if( nbSelected() && ( e->buttons() & Qt::MidButton ) )
+ {
+ for( initSelected(); moreSelected(); nextSelected() )
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ if( aMovingObject->isMovable() )
+ anObjectsToMove.append( aMovingObject );
+ }
+
+ if( anObjectsToMove.isEmpty() )
+ return;
+
+ double aDX = e->scenePos().x() - myDragPosition.x();
+ double aDY = e->scenePos().y() - myDragPosition.y();
+
+ bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true;
+ GraphicsView_ObjectListIterator anIter( anObjectsToMove );
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* aMovingObject = anIter.next() )
+ {
+ if( !aMovingObject->isMovingByXAllowed( aDX ) )
+ anIsMovingByXAllowed = false;
+ if( !aMovingObject->isMovingByYAllowed( aDY ) )
+ anIsMovingByYAllowed = false;
+ }
+
+ if( !anIsMovingByXAllowed && !anIsMovingByYAllowed )
+ return; // myDragPosition shouldn't be changed
+
+ if( !anIsMovingByXAllowed )
+ aDX = 0;
+
+ if( !anIsMovingByYAllowed )
+ aDY = 0;
+
+ anIter = anObjectsToMove;
+ while( anIter.hasNext() )
+ if( GraphicsView_Object* aMovingObject = anIter.next() )
+ aMovingObject->move( aDX, aDY );
+
+ if( anIsMovingByXAllowed )
+ myDragPosition.setX( e->scenePos().x() );
+
+ if( anIsMovingByYAllowed )
+ myDragPosition.setY( e->scenePos().y() );
+}
+
+//================================================================
+// Function : startPulling
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::startPulling( const QPointF& thePoint )
+{
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ QRectF aRect = anObject->getPullingRect();
+ if( aRect.contains( thePoint ) && anObject->startPulling( thePoint ) )
+ {
+ myIsPulling = true;
+ myPullingObject = anObject;
+ setCursor( *getHandCursor() );
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+//================================================================
+// Function : drawPulling
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint )
+{
+ GraphicsView_Object* aLockedObject = 0;
+
+ QListIterator<QGraphicsItem*> anIter( items() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
+ {
+ if( !anObject->isVisible() )
+ continue;
+
+ QRectF aRect = anObject->getPullingRect();
+ if( aRect.contains( thePoint ) && anObject->portContains( thePoint ) )
+ {
+ aLockedObject = anObject;
+ break;
+ }
+ }
+ }
+
+ myPullingObject->pull( thePoint, aLockedObject );
+}
+
+//================================================================
+// Function : finishPulling
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::finishPulling()
+{
+ myIsPulling = false;
+ myPullingObject->finishPulling();
+ setCursor( *getDefaultCursor() );
+}
+
+//================================================================
+// Function : onMouseEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e )
+{
+ emit vpMouseEvent( e );
+
+ switch( e->type() )
+ {
+ case QEvent::GraphicsSceneMousePress:
+ {
+ bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey();
+ if( ( getHighlightedObject() &&
+ getHighlightedObject()->isMovable() &&
+ !( anAccel || e->button() == Qt::RightButton ) ) ||
+ ( nbSelected() && !anAccel && e->button() == Qt::MidButton ) )
+ myIsDragging = true;
+ break;
+ }
+ case QEvent::GraphicsSceneMouseMove:
+ {
+ if( !isPulling() && myIsDragging )
+ dragObjects( e );
+ break;
+ }
+ case QEvent::GraphicsSceneMouseRelease:
+ {
+ if( !isPulling() && myIsDragging )
+ {
+ bool anIsMoved = false;
+ for( initSelected(); moreSelected(); nextSelected() )
+ if( GraphicsView_Object* aMovingObject = selectedObject() )
+ anIsMoved = aMovingObject->finishMove() || anIsMoved;
+
+ if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
+ anIsMoved = aMovingObject->finishMove() || anIsMoved;
+
+ myIsDragging = false;
+ myDragPosition = QPointF();
+
+ if( anIsMoved )
+ emit vpObjectMoved();
+ }
+ break;
+ }
+ case QEvent::GraphicsSceneMouseDoubleClick:
+ break; // do nothing, just emit the signal
+ default:
+ break;
+ }
+}
+
+//================================================================
+// Function : onWheelEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onWheelEvent( QGraphicsSceneWheelEvent* e )
+{
+ emit vpWheelEvent( e );
+}
+
+//================================================================
+// Function : onContextMenuEvent
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::onContextMenuEvent( QGraphicsSceneContextMenuEvent* e )
+{
+ emit vpContextMenuEvent( e );
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewPort.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_VIEWPORT_H
+#define GRAPHICSVIEW_VIEWPORT_H
+
+#include "GraphicsView.h"
+
+#include "GraphicsView_Defs.h"
+
+#include <QGraphicsView>
+
+class QRubberBand;
+
+class GraphicsView_Object;
+class GraphicsView_Scene;
+
+/*
+ Class : GraphicsView_ViewPort
+ Description : View port of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_ViewPort : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ enum BlockStatus
+ {
+ BS_NoBlock = 0x0000,
+ BS_Selection = 0x0001, // and highlighting
+ BS_Dragging = 0x0002 // currently unused
+ };
+
+public:
+ GraphicsView_ViewPort( QWidget* theParent );
+ ~GraphicsView_ViewPort();
+
+public:
+ GraphicsView_Scene* getScene() { return myScene; }
+ void addItem( QGraphicsItem* theItem );
+ void removeItem( QGraphicsItem* theItem );
+
+ QImage dumpView( bool theWholeScene = false );
+
+public:
+ // background / foreground
+ QColor backgroundColor() const;
+ void setBackgroundColor( const QColor& theColor );
+
+ bool isForegroundEnabled() const { return myIsForegroundEnabled; }
+ void setForegroundEnabled( bool theState );
+
+ QSizeF foregroundSize() const { return myForegroundSize; }
+ void setForegroundSize( const QSizeF& theRect );
+
+ double foregroundMargin() const { return myForegroundMargin; }
+ void setForegroundMargin( double theMargin );
+
+ QColor foregroundColor() const { return myForegroundColor; }
+ void setForegroundColor( const QColor& theColor );
+
+ QColor foregroundFrameColor() const { return myForegroundFrameColor; }
+ void setForegroundFrameColor( const QColor& theColor );
+
+ double foregroundFrameLineWidth() const { return myForegroundFrameLineWidth; }
+ void setForegroundFrameLineWidth( double theLineWidth );
+
+ void updateForeground();
+
+ // transformation
+ void reset();
+ void pan( double theDX, double theDY );
+ void setCenter( double theX, double theY );
+ void zoom( double theX1, double theY1, double theX2, double theY2 );
+ void fitRect( const QRectF& theRect );
+ void fitSelect();
+ void fitAll( bool theKeepScale = false );
+
+ bool isTransforming() const { return myIsTransforming; }
+
+ // block status
+ BlockStatus currentBlock();
+
+ // highlighting
+ virtual void highlight( double theX, double theY );
+ void clearHighlighted();
+
+ GraphicsView_Object* getHighlightedObject() const { return myHighlightedObject; }
+
+ // selection
+ virtual int select( const QRectF& theRect, bool theIsAppend );
+ void clearSelected();
+ void setSelected( GraphicsView_Object* theObject );
+
+ int nbSelected() const;
+ void initSelected();
+ bool moreSelected();
+ bool nextSelected();
+ GraphicsView_Object* selectedObject();
+
+ // rectangle selection
+ void startSelectByRect( int x, int y );
+ void drawSelectByRect( int x, int y );
+ void finishSelectByRect();
+ bool isSelectByRect() const;
+ QRect selectionRect();
+
+ // dragging
+ bool isDragging() { return myIsDragging; }
+
+ // pulling
+ bool startPulling( const QPointF& );
+ void drawPulling( const QPointF& );
+ void finishPulling();
+ bool isPulling() const { return myIsPulling; }
+
+public:
+ static void createCursors();
+ static void destroyCursors();
+ static QCursor* getDefaultCursor() { return defCursor; }
+ static QCursor* getHandCursor() { return handCursor; }
+ static QCursor* getPanCursor() { return panCursor; }
+ static QCursor* getPanglCursor() { return panglCursor; }
+ static QCursor* getZoomCursor() { return zoomCursor; }
+
+protected slots:
+ void onMouseEvent( QGraphicsSceneMouseEvent* );
+ void onWheelEvent( QGraphicsSceneWheelEvent* );
+ void onContextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+signals:
+ void vpMouseEvent( QGraphicsSceneMouseEvent* );
+ void vpWheelEvent( QGraphicsSceneWheelEvent* );
+ void vpContextMenuEvent( QGraphicsSceneContextMenuEvent* );
+
+ void vpObjectMoved();
+
+private:
+ void initialize();
+ void cleanup();
+
+ void dragObjects( QGraphicsSceneMouseEvent* );
+
+private:
+ static int nCounter;
+ static QCursor* defCursor;
+ static QCursor* handCursor;
+ static QCursor* panCursor;
+ static QCursor* panglCursor;
+ static QCursor* zoomCursor;
+
+private:
+ GraphicsView_Scene* myScene;
+
+ // foreground
+ bool myIsForegroundEnabled;
+ QSizeF myForegroundSize;
+ double myForegroundMargin;
+ QColor myForegroundColor;
+ QColor myForegroundFrameColor;
+ double myForegroundFrameLineWidth;
+ QGraphicsRectItem* myForegroundItem;
+
+ // transformation
+ bool myIsTransforming;
+ QTransform myCurrentTransform;
+
+ // highlighting
+ GraphicsView_Object* myHighlightedObject;
+ double myHighlightX;
+ double myHighlightY;
+
+ // selection
+ GraphicsView_ObjectList mySelectedObjects;
+ int mySelectionIterator;
+
+ // rectangle selection
+ QRubberBand* myRectBand;
+ QPoint myFirstSelectionPoint;
+ QPoint myLastSelectionPoint;
+ bool myAreSelectionPointsInitialized;
+
+ // dragging
+ int myIsDragging;
+ QPointF myDragPosition;
+ bool myIsDragPositionInitialized;
+
+ // pulling
+ bool myIsPulling;
+ GraphicsView_Object* myPullingObject;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewTransformer.cxx
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_ViewTransformer.h"
+
+#include "GraphicsView_Scene.h"
+#include "GraphicsView_ViewPort.h"
+#include "GraphicsView_Viewer.h"
+
+#include <QGraphicsSceneMouseEvent>
+#include <QRectF>
+#include <QRubberBand>
+
+int GraphicsView_ViewTransformer::panBtn = Qt::MidButton;
+int GraphicsView_ViewTransformer::zoomBtn = Qt::LeftButton;
+int GraphicsView_ViewTransformer::fitRectBtn = Qt::LeftButton;
+int GraphicsView_ViewTransformer::panGlobalBtn = Qt::LeftButton;
+int GraphicsView_ViewTransformer::acccelKey = Qt::ControlModifier;
+
+//=======================================================================
+// Name : GraphicsView_ViewTransformer
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_ViewTransformer::GraphicsView_ViewTransformer( GraphicsView_Viewer* v, int type )
+: QObject( 0 ),
+ myViewer( v ),
+ myType( type ),
+ myMajorBtn( Qt::NoButton ),
+ myButtonState( 0 ),
+ myRectBand( 0 )
+{
+ if( myType == GraphicsView_Viewer::Pan ||
+ myType == GraphicsView_Viewer::Zoom ||
+ myType == GraphicsView_Viewer::PanGlobal ||
+ myType == GraphicsView_Viewer::FitRect )
+ initTransform( true );
+}
+
+//=======================================================================
+// Name : GraphicsView_ViewTransformer
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_ViewTransformer::~GraphicsView_ViewTransformer()
+{
+ if( myType == GraphicsView_Viewer::Pan ||
+ myType == GraphicsView_Viewer::Zoom ||
+ myType == GraphicsView_Viewer::PanGlobal ||
+ myType == GraphicsView_Viewer::FitRect )
+ initTransform( false );
+
+ endDrawRect();
+}
+
+//================================================================
+// Function : initTransform
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::initTransform( bool init )
+{
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ {
+ if( GraphicsView_Scene* aScene = aViewPort->getScene() )
+ {
+ if( init )
+ {
+ mySavedCursor = aViewPort->cursor();
+ mySavedMouseTrack = aViewPort->hasMouseTracking();
+ aViewPort->setMouseTracking( false );
+ aScene->installEventFilter( this );
+ }
+ else
+ {
+ aScene->removeEventFilter( this );
+ aViewPort->setMouseTracking( mySavedMouseTrack );
+ aViewPort->setCursor( mySavedCursor );
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : exec
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::exec()
+{
+ GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort();
+ if( !aViewPort )
+ return;
+
+ switch( myType )
+ {
+ case GraphicsView_Viewer::Zoom:
+ myMajorBtn = zoomButton();
+ aViewPort->setCursor( *aViewPort->getZoomCursor() );
+ break;
+ case GraphicsView_Viewer::Pan:
+ myMajorBtn = panButton();
+ aViewPort->setCursor( *aViewPort->getPanCursor() );
+ break;
+ case GraphicsView_Viewer::PanGlobal:
+ myMajorBtn = panGlobalButton();
+ aViewPort->setCursor( *aViewPort->getPanglCursor() );
+ aViewPort->fitAll( true );
+ break;
+ case GraphicsView_Viewer::FitRect:
+ myMajorBtn = fitRectButton();
+ aViewPort->setCursor( *aViewPort->getHandCursor() );
+ break;
+ case GraphicsView_Viewer::Reset:
+ aViewPort->reset();
+ onTransform( Finished );
+ break;
+ case GraphicsView_Viewer::FitAll:
+ aViewPort->fitAll();
+ onTransform( Finished );
+ break;
+ case GraphicsView_Viewer::FitSelect:
+ aViewPort->fitSelect();
+ onTransform( Finished );
+ break;
+ default: break;
+ }
+}
+
+//================================================================
+// Function : eventFilter
+// Purpose :
+//================================================================
+bool GraphicsView_ViewTransformer::eventFilter( QObject* o, QEvent* e )
+{
+ switch( e->type() )
+ {
+ case QEvent::GraphicsSceneMouseMove:
+ case QEvent::GraphicsSceneMousePress:
+ case QEvent::GraphicsSceneMouseRelease:
+ {
+ TransformState state = InProcess;
+ QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* )e;
+
+ myButtonState = me->buttons();
+ if ( e->type() == QEvent::GraphicsSceneMousePress )
+ myButtonState |= me->button();
+
+ if ( e->type() == QEvent::GraphicsSceneMouseRelease )
+ myButtonState |= me->button();
+
+ int mouseOnlyState = ( myButtonState & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
+ if ( myStart.isNull() )
+ {
+ state = Begin;
+ myStart = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() );
+ myMajorBtn = mouseOnlyState;
+ }
+
+ if ( e->type() == QEvent::GraphicsSceneMouseRelease )
+ state = Finished;
+
+ myCurr = myViewer->getActiveViewPort()->mapFromScene( me->scenePos() );
+ onTransform( state );
+ return true;
+ }
+ default: break;
+ }
+ return QObject::eventFilter( o, e );
+}
+
+//================================================================
+// Function : onTransform
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::onTransform( TransformState state )
+{
+ GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort();
+ if( !aViewPort || aViewPort->isTransforming() )
+ return;
+
+ bool doTrsf = ( myButtonState & myMajorBtn );
+ switch ( myType )
+ {
+ case GraphicsView_Viewer::Zoom:
+ if ( state != Finished && doTrsf )
+ {
+ aViewPort->zoom( myStart.x(), myStart.y(), myCurr.x(), myCurr.y() );
+ myStart = myCurr;
+ }
+ break;
+ case GraphicsView_Viewer::Pan:
+ if ( state != Finished && doTrsf )
+ {
+ aViewPort->pan( myCurr.x() - myStart.x(), myStart.y() - myCurr.y() );
+ myStart = myCurr;
+ }
+ break;
+ case GraphicsView_Viewer::PanGlobal:
+ if ( state == Finished )
+ {
+ QPointF aPoint = aViewPort->mapToScene( myCurr.toPoint() );
+ aViewPort->setCenter( aPoint.x(), aPoint.y() );
+ }
+ break;
+ case GraphicsView_Viewer::FitRect:
+ if ( doTrsf )
+ {
+ QRectF aRect( qMin( myStart.x(), myCurr.x() ), qMin( myStart.y(), myCurr.y() ),
+ qAbs( myStart.x() - myCurr.x() ), qAbs( myStart.y() - myCurr.y() ) );
+ if ( !aRect.isEmpty() )
+ {
+ switch ( state )
+ {
+ case Finished:
+ aRect = aViewPort->mapToScene( aRect.toRect() ).boundingRect();
+ aViewPort->fitRect( aRect );
+ break;
+ default:
+ drawRect( aRect );
+ break;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ if ( state == Finished )
+ myViewer->activateTransform( GraphicsView_Viewer::NoTransform );
+}
+
+//================================================================
+// Function : drawRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::drawRect(const QRectF& theRect)
+{
+ if ( !myRectBand )
+ {
+ myRectBand = new QRubberBand( QRubberBand::Rectangle, myViewer->getActiveViewPort() );
+ QPalette palette;
+ palette.setColor(myRectBand->foregroundRole(), Qt::white);
+ myRectBand->setPalette(palette);
+ }
+ myRectBand->hide();
+
+ myRectBand->setGeometry( theRect.toRect() );
+ myRectBand->setVisible( theRect.isValid() );
+}
+
+//================================================================
+// Function : endDrawRect
+// Purpose :
+//================================================================
+void GraphicsView_ViewTransformer::endDrawRect()
+{
+ if ( myRectBand )
+ {
+ myRectBand->hide();
+ delete myRectBand;
+ myRectBand = 0;
+ }
+}
+
+//================================================================
+// Function : GraphicsView_ViewTransformer
+// Purpose :
+//================================================================
+int GraphicsView_ViewTransformer::type() const
+{
+ return myType;
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_ViewTransformer.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_VIEWTRANSFORMER_H
+#define GRAPHICSVIEW_VIEWTRANSFORMER_H
+
+#include "GraphicsView.h"
+
+#include <QCursor>
+#include <QObject>
+
+class QRectF;
+class QRubberBand;
+
+class GraphicsView_Viewer;
+
+/*
+ Class : GraphicsView_ViewTransformer
+ Description : View transformer of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_ViewTransformer : public QObject
+{
+public:
+ GraphicsView_ViewTransformer( GraphicsView_Viewer*, int type );
+ ~GraphicsView_ViewTransformer();
+
+public:
+ int type() const;
+
+ static int accelKey() { return acccelKey; }
+ static void setAccelKey( int k ) { acccelKey = k; }
+
+ static int zoomButton() { return zoomBtn; }
+ static void setZoomButton( int b ) { zoomBtn = b; }
+
+ static int panButton() { return panBtn; }
+ static void setPanButton( int b ) { panBtn = b; }
+
+ static int panGlobalButton() { return panGlobalBtn; }
+ static void setPanGlobalButton( int b ) { panGlobalBtn = b; }
+
+ static int fitRectButton() { return fitRectBtn; }
+ static void setFitRectButton( int b ) { fitRectBtn = b; }
+
+ virtual void exec();
+ virtual bool eventFilter( QObject*, QEvent* );
+
+protected:
+ enum TransformState { Begin, InProcess, Finished };
+ virtual void onTransform( TransformState );
+ void initTransform( bool );
+
+ void drawRect( const QRectF& theRect );
+ void endDrawRect();
+
+protected:
+ static int panBtn;
+ static int zoomBtn;
+ static int fitRectBtn;
+ static int panGlobalBtn;
+
+ static int acccelKey;
+
+ GraphicsView_Viewer* myViewer;
+ int myType;
+ QCursor mySavedCursor;
+ bool mySavedMouseTrack;
+ QPointF myStart;
+ QPointF myCurr;
+ int myButtonState;
+ int myMajorBtn;
+
+ QRubberBand* myRectBand;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Viewer.cxx
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#include "GraphicsView_Viewer.h"
+
+#include "GraphicsView_Selector.h"
+#include "GraphicsView_Scene.h"
+#include "GraphicsView_ViewFrame.h"
+#include "GraphicsView_ViewPort.h"
+#include "GraphicsView_ViewTransformer.h"
+
+#include <SUIT_ViewManager.h>
+
+#include <QApplication>
+#include <QColorDialog>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsSceneWheelEvent>
+#include <QMenu>
+
+//=======================================================================
+// Name : GraphicsView_Viewer
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_Viewer::GraphicsView_Viewer( const QString& title )
+: SUIT_ViewModel(),
+ mySelector( 0 ),
+ myTransformer( 0 )
+{
+}
+
+//=======================================================================
+// Name : GraphicsView_Viewer
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_Viewer::~GraphicsView_Viewer()
+{
+ delete mySelector;
+}
+
+//================================================================
+// Function : createView
+// Purpose :
+//================================================================
+SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
+{
+ GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this );
+
+ connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
+ this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+
+ connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
+ this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
+
+ return aViewFrame;
+}
+
+//================================================================
+// Function : contextMenuPopup
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
+{
+ if( thePopup->actions().count() > 0 )
+ thePopup->addSeparator();
+
+ thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
+}
+
+//================================================================
+// Function : getSelector
+// Purpose :
+//================================================================
+GraphicsView_Selector* GraphicsView_Viewer::getSelector()
+{
+ if( !mySelector )
+ {
+ mySelector = new GraphicsView_Selector( this );
+ if( mySelector )
+ {
+ connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
+ this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
+ connect( mySelector, SIGNAL( selSelectionCancel() ),
+ this, SLOT( onSelectionCancel() ) );
+ }
+ }
+ return mySelector;
+}
+
+//================================================================
+// Function : getActiveView
+// Purpose :
+//================================================================
+GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
+{
+ if( SUIT_ViewManager* aViewManager = getViewManager() )
+ return dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->getActiveView() );
+ return NULL;
+}
+
+//================================================================
+// Function : getActiveViewPort
+// Purpose :
+//================================================================
+GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const
+{
+ if( GraphicsView_ViewFrame* aViewFrame = getActiveView() )
+ return aViewFrame->getViewPort();
+ return NULL;
+}
+
+//================================================================
+// Function : getActiveScene
+// Purpose :
+//================================================================
+GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ return dynamic_cast<GraphicsView_Scene*>( aViewPort->scene() );
+ return NULL;
+}
+
+//================================================================
+// Function : activateTransform
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::activateTransform( int theType )
+{
+ if( theType == NoTransform ) // finish current transform
+ {
+ if ( myTransformer )
+ {
+ onTransformationFinished();
+ delete myTransformer;
+ myTransformer = 0;
+ }
+ }
+ else // activate new transform
+ {
+ activateTransform( NoTransform );
+ myTransformer = createTransformer( theType );
+ onTransformationStarted();
+ myTransformer->exec();
+ }
+}
+
+//================================================================
+// Function : createTransformer
+// Purpose :
+//================================================================
+GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
+{
+ return new GraphicsView_ViewTransformer( this, theType );
+}
+
+//================================================================
+// Function : onTransformationStarted
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onTransformationStarted()
+{
+ if( GraphicsView_Selector* aSelector = getSelector() )
+ {
+ aSelector->undetectAll();
+ aSelector->lock( true ); // disable selection
+ }
+
+ // watch events: any mouse/key event outside the
+ // viewport will be considered as the end of transform
+ if( myTransformer )
+ qApp->installEventFilter( this );
+}
+
+//================================================================
+// Function : onTransformationFinished
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onTransformationFinished()
+{
+ if( GraphicsView_Selector* aSelector = getSelector() )
+ aSelector->lock( false ); // enable selection
+
+ // stop watching events
+ if( myTransformer )
+ qApp->removeEventFilter( this );
+}
+
+//================================================================
+// Function : onMouseEvent
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
+{
+ switch( e->type() )
+ {
+ case QEvent::GraphicsSceneMousePress:
+ handleMousePress( e );
+ break;
+ case QEvent::GraphicsSceneMouseMove:
+ handleMouseMove( e );
+ break;
+ case QEvent::GraphicsSceneMouseRelease:
+ handleMouseRelease( e );
+ break;
+ default: break;
+ }
+}
+
+//================================================================
+// Function : onWheelEvent
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
+{
+ switch( e->type() )
+ {
+ case QEvent::Wheel:
+ handleWheel( e );
+ break;
+ default: break;
+ }
+}
+
+//================================================================
+// Function : handleMousePress
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
+{
+ // test accel for transforms
+ if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
+ {
+ Qt::MouseButton bs = e->button();
+ if ( bs == GraphicsView_ViewTransformer::zoomButton() )
+ activateTransform( Zoom );
+ else if ( bs == GraphicsView_ViewTransformer::panButton() )
+ activateTransform( Pan );
+ }
+ else // checking for other operations before selection in release event
+ startOperations( e );
+}
+
+//================================================================
+// Function : handleMouseMove
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
+{
+ // highlight for selection
+ bool dragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
+ if ( !dragged )
+ {
+ if ( getSelector() )
+ getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
+ }
+
+ updateOperations( e ); // try to activate other operations
+}
+
+//================================================================
+// Function : handleMouseRelease
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
+{
+ // selection
+ if( e->button() == Qt::LeftButton &&
+ !( getActiveViewPort()->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
+ {
+ if ( getSelector() )
+ {
+ bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
+ getSelector()->select( QRectF(), append );
+ }
+ }
+
+ finishOperations( e ); // try to finish active operations
+}
+
+//================================================================
+// Function : handleWheel
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
+{
+ startOperations( e );
+}
+
+//================================================================
+// Function : onSelectionDone
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
+{
+ emit selectionChanged( theStatus );
+}
+
+//================================================================
+// Function : onChangeBgColor
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onChangeBgColor()
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ QColor aColor = aViewPort->isForegroundEnabled() ? aViewPort->foregroundColor() : aViewPort->backgroundColor();
+ aColor = QColorDialog::getColor( aColor, aViewPort );
+ if ( aColor.isValid() )
+ {
+ if( aViewPort->isForegroundEnabled() )
+ {
+ aViewPort->setForegroundColor( aColor );
+ aViewPort->updateForeground();
+ }
+ else
+ aViewPort->setBackgroundColor( aColor );
+ }
+ }
+}
+
+//================================================================
+// Function : onSelectionCancel
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onSelectionCancel()
+{
+ emit selectionChanged( GVSCS_Invalid );
+}
+
+//================================================================
+// Function : startOperations
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::startOperations( QGraphicsSceneMouseEvent* e )
+{
+ GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+
+ // Try to start pulling if rectangular selection is performed
+ if( e->button() == Qt::LeftButton &&
+ !aViewPort->isSelectByRect() &&
+ !aViewPort->isDragging() &&
+ aViewPort->startPulling( e->scenePos() ) )
+ {
+ aViewPort->finishSelectByRect();
+ return;
+ }
+
+ // Start rectangular selection if pulling was not started
+ if( e->button() == Qt::LeftButton &&
+ !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
+ !aViewPort->getHighlightedObject() )
+ {
+ QPoint p = aViewPort->mapFromScene( e->scenePos() );
+ aViewPort->startSelectByRect( p.x(), p.y() );
+ }
+}
+
+//================================================================
+// Function : updateOperations
+// Purpose :
+//================================================================
+bool GraphicsView_Viewer::updateOperations( QGraphicsSceneMouseEvent* e )
+{
+ GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+
+ if( aViewPort->isPulling() )
+ {
+ aViewPort->drawPulling( e->scenePos() );
+ return true;
+ }
+
+ if( e->button() == Qt::LeftButton )
+ {
+ if( !aViewPort->isSelectByRect() && !aViewPort->isDragging() && aViewPort->startPulling( e->scenePos() ) )
+ {
+ aViewPort->finishSelectByRect();
+ return true;
+ }
+ }
+
+ if( !aViewPort->getHighlightedObject() )
+ {
+ QPoint p = aViewPort->mapFromScene( e->scenePos() );
+ aViewPort->drawSelectByRect( p.x(), p.y() );
+ return true;
+ }
+ return false;
+}
+
+//================================================================
+// Function : finishOperations
+// Purpose :
+//================================================================
+bool GraphicsView_Viewer::finishOperations( QGraphicsSceneMouseEvent* e )
+{
+ GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+
+ if( aViewPort->isPulling() )
+ {
+ aViewPort->finishPulling();
+ // Although operation is finished, FALSE is returned because base class try to
+ // perform selection in this case. In the other case it is impossible to perform
+ // selection of pulled port
+ return false;
+ }
+
+ if( !aViewPort->getHighlightedObject() )
+ {
+ QRect aSelRect = aViewPort->selectionRect();
+ aViewPort->finishSelectByRect();
+ if ( getSelector() && !aSelRect.isNull() )
+ {
+ bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
+ QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
+ getSelector()->select( aRect, append );
+ return true;
+ }
+ }
+
+ return false;
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File: GraphicsView_Viewer.h
+// Author: Oleg UVAROV, Open CASCADE S.A.S. (oleg.uvarov@opencascade.com)
+//
+
+#ifndef GRAPHICSVIEW_VIEWER_H
+#define GRAPHICSVIEW_VIEWER_H
+
+#include "GraphicsView.h"
+
+#include "GraphicsView_Defs.h"
+
+#include <SUIT_ViewModel.h>
+
+class QGraphicsSceneMouseEvent;
+class QGraphicsSceneWheelEvent;
+
+class SUIT_ViewWindow;
+
+class GraphicsView_Selector;
+class GraphicsView_Scene;
+class GraphicsView_ViewTransformer;
+class GraphicsView_ViewFrame;
+class GraphicsView_ViewPort;
+
+/*
+ Class : GraphicsView_Viewer
+ Description : View model of the graphics view
+*/
+class GRAPHICSVIEW_API GraphicsView_Viewer: public SUIT_ViewModel
+{
+ Q_OBJECT
+
+public:
+ enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
+ Zoom, PanGlobal, Pan, UserTransform = 100 };
+public:
+ GraphicsView_Viewer( const QString& title );
+ ~GraphicsView_Viewer();
+
+public:
+ virtual SUIT_ViewWindow* createView( SUIT_Desktop* );
+
+ virtual QString getType() const { return Type(); }
+ static QString Type() { return "GraphicsView"; }
+
+ virtual void contextMenuPopup( QMenu* );
+
+public:
+ GraphicsView_Selector* getSelector();
+
+ GraphicsView_ViewFrame* getActiveView() const;
+ GraphicsView_ViewPort* getActiveViewPort() const;
+ GraphicsView_Scene* getActiveScene() const;
+
+ void activateTransform( int );
+
+signals:
+ void selectionChanged( GV_SelectionChangeStatus );
+
+protected:
+ virtual GraphicsView_ViewTransformer* createTransformer( int );
+
+ virtual void onTransformationStarted();
+ virtual void onTransformationFinished();
+
+ virtual void startOperations( QGraphicsSceneMouseEvent* );
+ virtual bool updateOperations( QGraphicsSceneMouseEvent* );
+ virtual bool finishOperations( QGraphicsSceneMouseEvent* );
+ virtual void startOperations( QGraphicsSceneWheelEvent* ) {}
+
+protected slots:
+ virtual void onMouseEvent( QGraphicsSceneMouseEvent* );
+ virtual void onWheelEvent( QGraphicsSceneWheelEvent* );
+
+ virtual void onSelectionDone( GV_SelectionChangeStatus );
+ virtual void onSelectionCancel();
+
+ virtual void onChangeBgColor();
+
+private:
+ void handleMouseMove( QGraphicsSceneMouseEvent* );
+ void handleMousePress( QGraphicsSceneMouseEvent* );
+ void handleMouseRelease( QGraphicsSceneMouseEvent* );
+ void handleWheel( QGraphicsSceneWheelEvent* );
+
+protected:
+ GraphicsView_Selector* mySelector;
+ GraphicsView_ViewTransformer* myTransformer;
+};
+
+#endif
--- /dev/null
+<!DOCTYPE TS><TS>
+<context>
+ <name>@default</name>
+ <message>
+ <source>ICON_GV_DUMP</source>
+ <translation>graphics_view_dump.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_ZOOM</source>
+ <translation>graphics_view_zoom.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_PAN</source>
+ <translation>graphics_view_pan.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_GLOBALPAN</source>
+ <translation>graphics_view_glpan.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_CURSOR_ZOOM</source>
+ <translation>graphics_view_cursor_zoom.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_FITALL</source>
+ <translation>graphics_view_fitall.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_FITSELECT</source>
+ <translation>graphics_view_fitselect.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_RESET</source>
+ <translation>graphics_view_reset.png</translation>
+ </message>
+ <message>
+ <source>ICON_GV_FITAREA</source>
+ <translation>graphics_view_fitarea.png</translation>
+ </message>
+</context>
+</TS>
--- /dev/null
+<!DOCTYPE TS>
+<TS>
+ <context>
+ <name>GraphicsView_ViewFrame</name>
+ <message>
+ <source>DSC_DUMP_VIEW</source>
+ <translation>Saves the active view in the image file</translation>
+ </message>
+ <message>
+ <source>DSC_FITALL</source>
+ <translation>Fit all objects inside the view frame</translation>
+ </message>
+ <message>
+ <source>DSC_FITRECT</source>
+ <translation>Fit area within the view frame</translation>
+ </message>
+ <message>
+ <source>DSC_FITSELECT</source>
+ <translation>Fit area of selection within the view frame</translation>
+ </message>
+ <message>
+ <source>DSC_GLOBALPAN_VIEW</source>
+ <translation>Selection of a new center of the view</translation>
+ </message>
+ <message>
+ <source>DSC_PAN_VIEW</source>
+ <translation>Pan the view</translation>
+ </message>
+ <message>
+ <source>DSC_RESET_VIEW</source>
+ <translation>Reset view point</translation>
+ </message>
+ <message>
+ <source>DSC_ZOOM_VIEW</source>
+ <translation>Zoom the view</translation>
+ </message>
+ <message>
+ <source>LBL_TOOLBAR_LABEL</source>
+ <translation>View Operations</translation>
+ </message>
+ <message>
+ <source>MNU_DUMP_VIEW</source>
+ <translation>Dump</translation>
+ </message>
+ <message>
+ <source>MNU_FITALL</source>
+ <translation>Fit All</translation>
+ </message>
+ <message>
+ <source>MNU_FITRECT</source>
+ <translation>Fit Area</translation>
+ </message>
+ <message>
+ <source>MNU_FITSELECT</source>
+ <translation>Fit Selection</translation>
+ </message>
+ <message>
+ <source>MNU_GLOBALPAN_VIEW</source>
+ <translation>Global Pan</translation>
+ </message>
+ <message>
+ <source>MNU_PAN_VIEW</source>
+ <translation>Pan</translation>
+ </message>
+ <message>
+ <source>MNU_RESET_VIEW</source>
+ <translation>Reset</translation>
+ </message>
+ <message>
+ <source>MNU_ZOOM_VIEW</source>
+ <translation>Zoom</translation>
+ </message>
+ </context>
+ <context>
+ <name>GraphicsView_Viewer</name>
+ <message>
+ <source>CHANGE_BGCOLOR</source>
+ <translation>Change background...</translation>
+ </message>
+ </context>
+ <context>
+ <name>GraphicsView_ViewManager</name>
+ <message>
+ <source>GRAPHICS_VIEW_TITLE</source>
+ <translation>Graphics scene:%M - viewer:%V</translation>
+ </message>
+ </context>
+</TS>
#include <QxGraph_ViewManager.h>
#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ #include <GraphicsView_Viewer.h>
+ #include <GraphicsView_ViewManager.h>
+#endif
+
#include <QDir>
#include <QImage>
#include <QString>
#ifndef DISABLE_QXGRAPHVIEWER
createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_C );
#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_R );
+#endif
createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) );
case NewQxGraphViewId:
type = QxGraph_Viewer::Type();
break;
+#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ case NewGraphicsViewId:
+ type = GraphicsView_Viewer::Type();
+ break;
#endif
}
if( a )
a->setEnabled( activeStudy() );
#endif
+
+#ifndef DISABLE_GRAPHICSVIEWER
+ a = action( NewGraphicsViewId );
+ if( a )
+ a->setEnabled( activeStudy() );
+#endif
}
/*!
#endif
}
#endif
+#ifndef DISABLE_GRAPHICSVIEWER
+ if( vmType == GraphicsView_Viewer::Type() )
+ {
+ viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() );
+ }
+#endif
if ( !viewMgr )
return 0;
enum { RenameId = CAM_Application::UserID,
CloseId, CloseAllId, GroupAllId,
PreferencesId, MRUId, ModulesListId,
- NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, UserID };
+ NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId,
+ NewGraphicsViewId, UserID };
protected:
enum { NewStudyId = 1, OpenStudyId };
STD = $(GUI_ROOT_DIR)/share/salome/resources/gui
LightApp = $(GUI_ROOT_DIR)/share/salome/resources/gui
Plot2d = $(GUI_ROOT_DIR)/share/salome/resources/gui
+GraphicsView = $(GUI_ROOT_DIR)/share/salome/resources/gui
GLViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui
OCCViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui
VTKViewer = $(GUI_ROOT_DIR)/share/salome/resources/gui
<parameter name="STD" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="Plot2d" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="SPlot2d" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
+ <parameter name="GraphicsView" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="GLViewer" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="OCCViewer" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<parameter name="VTKViewer" value="${GUI_ROOT_DIR}/share/salome/resources/gui"/>
<source>NEW_WINDOW_4</source>
<translation>&QxGraph view</translation>
</message>
+ <message>
+ <source>NEW_WINDOW_5</source>
+ <translation>G&raphics view</translation>
+ </message>
<message>
<source>OBJ_BROWSER_NAME</source>
<translation>Object</translation>