Salome HOME
cb5fd6017c44c8ac3e3a69a6f0738eba4d11ee01
[modules/gui.git] / src / GraphicsView / GraphicsView_Viewer.h
1 // Copyright (C) 2013-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef GRAPHICSVIEW_VIEWER_H
21 #define GRAPHICSVIEW_VIEWER_H
22
23 #include "GraphicsView.h"
24
25 #include "GraphicsView_Defs.h"
26
27 #include <SUIT_ViewModel.h>
28
29 #include <QPainterPath>
30
31 class QGraphicsSceneMouseEvent;
32 class QGraphicsSceneWheelEvent;
33 class QKeyEvent;
34
35 class SUIT_ViewWindow;
36
37 class GraphicsView_Selector;
38 class GraphicsView_Scene;
39 class GraphicsView_ViewTransformer;
40 class GraphicsView_ViewFrame;
41 class GraphicsView_ViewPort;
42
43 /*
44   Class       : GraphicsView_Viewer
45   Description : View model of the graphics view
46 */
47 class GRAPHICSVIEW_API GraphicsView_Viewer: public SUIT_ViewModel
48 {
49   Q_OBJECT
50
51 public:
52   enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
53                        Zoom, PanGlobal, Pan, FitWidth, UserTransform = 100 };
54 public:
55   GraphicsView_Viewer( const QString& title, QWidget* widget = NULL );
56   ~GraphicsView_Viewer();
57
58 public:
59   virtual SUIT_ViewWindow*      createView( SUIT_Desktop* );
60
61   virtual QString               getType() const { return Type(); }
62   static QString                Type() { return "GraphicsView";  }
63
64   virtual void                  contextMenuPopup( QMenu* );
65
66 public:
67   GraphicsView_Selector*        getSelector();
68
69   GraphicsView_ViewFrame*       getActiveView() const;
70   GraphicsView_ViewPort*        getActiveViewPort() const;
71   GraphicsView_Scene*           getActiveScene() const;
72
73   void                          activateTransform( int );
74
75   bool                          isInitialized() const { return myIsInitialized; }
76   void                          setIsInitialized( bool );
77
78 signals:
79   void                          selectionChanged( GV_SelectionChangeStatus );
80   void                          wheelScaleChanged();
81
82 protected:
83   virtual GraphicsView_ViewTransformer* createTransformer( int );
84   virtual GraphicsView_ViewFrame* createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget );
85
86   virtual void                  onTransformationStarted();
87   virtual void                  onTransformationFinished();
88
89 protected slots:
90   virtual void                  onKeyEvent( QKeyEvent* );
91   virtual void                  onMouseEvent( QGraphicsSceneMouseEvent* );
92   virtual void                  onWheelEvent( QGraphicsSceneWheelEvent* );
93
94   virtual void                  onSketchingFinished( QPainterPath );
95
96   virtual void                  onSelectionDone( GV_SelectionChangeStatus );
97   virtual void                  onSelectionCancel();
98
99   virtual void                  onChangeBgColor();
100
101   // testing ImageViewer
102   /*
103   void                          onAddImage();
104   void                          onRemoveImages();
105   void                          onBringToFront();
106   void                          onSendToBack();
107   void                          onBringForward();
108   void                          onSendBackward();
109   void                          onPrsProperties();
110   void                          onTestFuseOperator();
111   void                          onTestCropOperatorPrepare();
112   void                          onTestCropOperatorPerform( QPainterPath thePath );
113   */
114
115 protected:
116   virtual void                  handleKeyPress( QKeyEvent* );
117   virtual void                  handleKeyRelease( QKeyEvent* );
118   virtual void                  handleMouseMove( QGraphicsSceneMouseEvent* );
119   virtual void                  handleMousePress( QGraphicsSceneMouseEvent* );
120   virtual void                  handleMouseRelease( QGraphicsSceneMouseEvent* );
121   virtual void                  handleWheel( QGraphicsSceneWheelEvent* );
122
123   // testing ImageViewer
124   enum QueueOperation { BringToFront, SendToBack, BringForward, SendBackward };
125   void                          processQueueOperation( const QueueOperation );
126
127 protected:
128   GraphicsView_Selector*        mySelector;
129   GraphicsView_ViewTransformer* myTransformer;
130   QWidget*                      myWidget;
131
132   bool                          myIsInitialized;
133 };
134
135 #endif