Version: 9.16.0
GraphicsView_ViewPort.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 CEA, EDF, 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_VIEWPORT_H
21#define GRAPHICSVIEW_VIEWPORT_H
22
23#include "GraphicsView.h"
24
25#include "GraphicsView_Defs.h"
26
27#include <QGraphicsView>
28#include <QPainterPath>
29
30class QGridLayout;
31class QRubberBand;
32
35
36/*
37 Class : GraphicsView_ViewPort
38 Description : View port of the graphics view
39*/
41{
42 Q_OBJECT
43
44public:
45 class ViewLabel;
46
48 {
49 // main flags
50 Dragging = 0x0001,
51 Pulling = 0x0002,
52 WheelScaling = 0x0004,
53 EditFlags = Dragging | Pulling | WheelScaling,
54 // advanced flags
55 TraceBoundingRect = 0x0008,
56 DraggingByMiddleButton = 0x0010,
57 ImmediateContextMenu = 0x0020,
58 ImmediateSelection = 0x0040,
59 Sketching = 0x0080,
60
61 GlobalWheelScaling = 0x0100
62 };
63 Q_DECLARE_FLAGS( InteractionFlags, InteractionFlag )
64
65 enum BlockStatus
66 {
67 BS_NoBlock = 0x0000,
68 BS_Selection = 0x0001, // and highlighting
69 BS_Dragging = 0x0002 // currently unused
70 };
71
73 {
74 VLP_None = 0,
75 VLP_TopLeft = 1,
76 VLP_TopRight = 2,
77 VLP_BottomLeft = 3,
78 VLP_BottomRight = 4
79 };
80
81public:
82 GraphicsView_ViewPort( QWidget* theParent );
84
85public:
86 GraphicsView_Scene* getScene() { return myScene; }
87 void addItem( QGraphicsItem* theItem );
88 bool isItemAdded( QGraphicsItem* theItem );
89 void removeItem( QGraphicsItem* theItem );
90 void clearItems();
91
92 enum SortType { NoSorting, SelectedFirst, SortByZLevel };
93 GraphicsView_ObjectList getObjects( SortType theSortType = NoSorting ) const;
94
95 QRectF objectsBoundingRect( bool theOnlyVisible = false ) const;
96
97 QImage dumpView( bool theWholeScene = false,
98 QSizeF theSize = QSizeF() );
99
100 bool dumpViewToFormat(const QString& fileName, const QString& format);
101
102public:
103 // scene
104 void setSceneGap( double theSceneGap );
105 void setFitAllGap( double theFitAllGap );
106
107 // interaction flags
108 int interactionFlags() const;
109 bool hasInteractionFlag( InteractionFlag theFlag );
110 void setInteractionFlag( InteractionFlag theFlag,
111 bool theIsEnabled = true );
112 void setInteractionFlags( InteractionFlags theFlags );
113
114 // view label
115 void setViewLabelPosition( ViewLabelPosition thePosition,
116 bool theIsForced = false );
117 void setViewLabelText( const QString& theText );
118
119 // displaying mouse position (currently, overlaps with view label feature)
120 void setMousePositionEnabled( bool theState );
121
122 // background / foreground
123 QColor backgroundColor() const;
124 void setBackgroundColor( const QColor& theColor );
125
126 bool isForegroundEnabled() const { return myIsForegroundEnabled; }
127 void setForegroundEnabled( bool theState );
128
129 QSizeF foregroundSize() const { return myForegroundSize; }
130 void setForegroundSize( const QSizeF& theRect );
131
132 double foregroundMargin() const { return myForegroundMargin; }
133 void setForegroundMargin( double theMargin );
134
135 QColor foregroundColor() const { return myForegroundColor; }
136 void setForegroundColor( const QColor& theColor );
137
138 QColor foregroundFrameColor() const { return myForegroundFrameColor; }
139 void setForegroundFrameColor( const QColor& theColor );
140
141 double foregroundFrameLineWidth() const { return myForegroundFrameLineWidth; }
142 void setForegroundFrameLineWidth( double theLineWidth );
143
144 void updateForeground();
145
146 // grid
147 void setGridEnabled( bool theState );
148 void setGridCellSize( int theCellSize );
149 void setGridLineStyle( int theLineStyle );
150 void setGridLineColor( const QColor& theLineColor );
151 void updateGrid();
152
153 // transformation
154 void reset();
155 void pan( double theDX, double theDY );
156 void setCenter( double theX, double theY );
157 void zoom( double theX1, double theY1, double theX2, double theY2 );
158 void fitRect( const QRectF& theRect );
159 void fitSelect();
160 void fitAll( bool theKeepScale = false );
161 void fitWidth();
162
163 bool isTransforming() const { return myIsTransforming; }
164
165 void applyTransform();
166
167 int zoomCoeff() const { return myZoomCoeff; }
168 void setZoomCoeff( const int& theZoomCoeff );
169
170 bool isUnlimitedPanning() const { return myUnlimitedPanning; }
171 void setUnlimitedPanning( const bool& theValue );
172
173 // block status
174 BlockStatus currentBlock();
175
176 // highlighting
177 virtual void highlight( double theX, double theY );
178 void clearHighlighted();
179
180 GraphicsView_Object* getHighlightedObject() const { return myHighlightedObject; }
181
182 // selection
183 virtual int select( const QRectF& theRect, bool theIsAppend );
184 void clearSelected();
185 void setSelected( GraphicsView_Object* theObject );
186
187 int nbSelected() const;
188 void initSelected();
189 bool moreSelected();
190 bool nextSelected();
191 GraphicsView_Object* selectedObject();
192
193 const GraphicsView_ObjectList& getSelectedObjects() const { return mySelectedObjects; }
194
195 // rectangle selection
196 void startSelectByRect( int x, int y );
197 void drawSelectByRect( int x, int y );
198 void finishSelectByRect();
199 bool isSelectByRect() const;
200 QRect selectionRect();
201
202 // sketching
203 void prepareToSketch( bool theStatus );
204 bool isPrepareToSketch();
205 void startSketching( const QPointF& thePoint,
206 bool theIsPath );
207 void drawSketching( const QPointF& thePoint );
208 void finishSketching( bool theStatus );
209 bool isSketching( bool* theIsPath = 0 ) const;
210
211 // dragging
212 bool isDragging() { return myIsDragging; }
213
214 bool isDraggingSelectedByLeftButton() const { return myDraggingSelectedByLeftButton; }
215 void setDraggingSelectedByLeftButton( const bool& theValue );
216
217 // pulling
218 bool startPulling( const QPointF& );
219 void drawPulling( const QPointF& );
220 void finishPulling( bool theStatus );
221 bool isPulling() const { return myIsPulling; }
222
223 // other
224 bool cancelCurrentOperation();
225
226public:
227 static void createCursors();
228 static void destroyCursors();
229 static QCursor* getDefaultCursor() { return defCursor; }
230 static QCursor* getHandCursor() { return handCursor; }
231 static QCursor* getPanCursor() { return panCursor; }
232 static QCursor* getPanglCursor() { return panglCursor; }
233 static QCursor* getZoomCursor() { return zoomCursor; }
234 static QCursor* getSketchCursor() { return sketchCursor; }
235
236public slots:
237 void onBoundingRectChanged();
238
239protected slots:
240 void onKeyEvent( QKeyEvent* );
241 void onMouseEvent( QGraphicsSceneMouseEvent* );
242 void onWheelEvent( QGraphicsSceneWheelEvent* );
243 void onContextMenuEvent( QGraphicsSceneContextMenuEvent* );
244
245protected:
246 virtual void scrollContentsBy( int theDX, int theDY );
247
248signals:
249 void vpKeyEvent( QKeyEvent* );
250 void vpMouseEvent( QGraphicsSceneMouseEvent* );
251 void vpWheelEvent( QGraphicsSceneWheelEvent* );
252 void vpContextMenuEvent( QGraphicsSceneContextMenuEvent* );
253
254 void vpSketchingFinished( QPainterPath );
255
258
259private:
260 void initialize();
261 void cleanup();
262
263 void dragObjects( QGraphicsSceneMouseEvent* );
264
265private:
266 static int nCounter;
267 static QCursor* defCursor;
268 static QCursor* handCursor;
269 static QCursor* panCursor;
270 static QCursor* panglCursor;
271 static QCursor* zoomCursor;
272 static QCursor* sketchCursor;
273
274private:
275 // scene
280
281 // interaction flags
282 InteractionFlags myInteractionFlags;
283
284 // view label
287 QGridLayout* myViewLabelLayout;
288
289 // displaying mouse position (currently, overlaps with view label feature)
291
292 // foreground
299 QGraphicsRectItem* myForegroundItem;
300
301 // grid
306 QGraphicsPathItem* myGridItem;
307
308 // transformation
311
313 Qt::ScrollBarPolicy myHBarPolicy;
314 Qt::ScrollBarPolicy myVBarPolicy;
315
316 // highlighting
321
322 // selection
325
326 // rectangle selection
327 QRubberBand* myRectBand;
331
332 // sketching
333 QGraphicsPathItem* mySketchingItem;
338
339 // dragging
344
345 // pulling
348
349 // cursor
351
352 // zoom diagonal coefficient
354};
355
356Q_DECLARE_OPERATORS_FOR_FLAGS( GraphicsView_ViewPort::InteractionFlags )
357
358#endif
BlockStatus
Definition: GLViewer_ViewPort.h:50
@ BS_NoBlock
Definition: GLViewer_ViewPort.h:51
@ BS_Dragging
Definition: GLViewer_ViewPort.h:54
@ BS_Selection
Definition: GLViewer_ViewPort.h:53
#define GRAPHICSVIEW_API
Definition: GraphicsView.h:29
QList< GraphicsView_Object * > GraphicsView_ObjectList
Definition: GraphicsView_Defs.h:26
Definition: GraphicsView_Object.h:36
Definition: GraphicsView_Scene.h:34
Definition: GraphicsView_ViewPort.cxx:61
Definition: GraphicsView_ViewPort.h:41
void vpContextMenuEvent(QGraphicsSceneContextMenuEvent *)
double foregroundFrameLineWidth() const
Definition: GraphicsView_ViewPort.h:141
QGraphicsRectItem * myForegroundItem
Definition: GraphicsView_ViewPort.h:299
static QCursor * panglCursor
Definition: GraphicsView_ViewPort.h:270
QSizeF myForegroundSize
Definition: GraphicsView_ViewPort.h:294
int myZoomCoeff
Definition: GraphicsView_ViewPort.h:353
bool myIsHighlighting
Definition: GraphicsView_ViewPort.h:320
static QCursor * zoomCursor
Definition: GraphicsView_ViewPort.h:271
bool myUnlimitedPanning
Definition: GraphicsView_ViewPort.h:312
static QCursor * handCursor
Definition: GraphicsView_ViewPort.h:268
int myGridLineStyle
Definition: GraphicsView_ViewPort.h:304
static QCursor * getPanCursor()
Definition: GraphicsView_ViewPort.h:231
bool myIsSketching
Definition: GraphicsView_ViewPort.h:336
bool myIsSketchingByPath
Definition: GraphicsView_ViewPort.h:337
GraphicsView_Scene * myScene
Definition: GraphicsView_ViewPort.h:276
bool myIsDragPositionInitialized
Definition: GraphicsView_ViewPort.h:342
void vpSketchingFinished(QPainterPath)
double mySceneGap
Definition: GraphicsView_ViewPort.h:277
int zoomCoeff() const
Definition: GraphicsView_ViewPort.h:167
double myForegroundFrameLineWidth
Definition: GraphicsView_ViewPort.h:298
bool myIsPrepareToSketch
Definition: GraphicsView_ViewPort.h:335
SortType
Definition: GraphicsView_ViewPort.h:92
@ NoSorting
Definition: GraphicsView_ViewPort.h:92
double myForegroundMargin
Definition: GraphicsView_ViewPort.h:295
bool isForegroundEnabled() const
Definition: GraphicsView_ViewPort.h:126
double myHighlightY
Definition: GraphicsView_ViewPort.h:319
QGridLayout * myViewLabelLayout
Definition: GraphicsView_ViewPort.h:287
void vpKeyEvent(QKeyEvent *)
bool myIsTransforming
Definition: GraphicsView_ViewPort.h:309
InteractionFlag
Definition: GraphicsView_ViewPort.h:48
bool isDragging()
Definition: GraphicsView_ViewPort.h:212
void vpWheelEvent(QGraphicsSceneWheelEvent *)
Q_DECLARE_FLAGS(InteractionFlags, InteractionFlag) enum BlockStatus
Definition: GraphicsView_ViewPort.h:63
QGraphicsPathItem * mySketchingItem
Definition: GraphicsView_ViewPort.h:333
QPoint myFirstSelectionPoint
Definition: GraphicsView_ViewPort.h:328
Qt::ScrollBarPolicy myHBarPolicy
Definition: GraphicsView_ViewPort.h:313
static QCursor * defCursor
Definition: GraphicsView_ViewPort.h:267
double myHighlightX
Definition: GraphicsView_ViewPort.h:318
static QCursor * sketchCursor
Definition: GraphicsView_ViewPort.h:272
int myGridCellSize
Definition: GraphicsView_ViewPort.h:303
bool myIsForegroundEnabled
Definition: GraphicsView_ViewPort.h:293
bool myIsPulling
Definition: GraphicsView_ViewPort.h:346
double foregroundMargin() const
Definition: GraphicsView_ViewPort.h:132
Qt::ScrollBarPolicy myVBarPolicy
Definition: GraphicsView_ViewPort.h:314
static QCursor * getDefaultCursor()
Definition: GraphicsView_ViewPort.h:229
bool myAreSelectionPointsInitialized
Definition: GraphicsView_ViewPort.h:330
QSizeF foregroundSize() const
Definition: GraphicsView_ViewPort.h:129
static QCursor * getHandCursor()
Definition: GraphicsView_ViewPort.h:230
QColor foregroundFrameColor() const
Definition: GraphicsView_ViewPort.h:138
InteractionFlags myInteractionFlags
Definition: GraphicsView_ViewPort.h:282
GraphicsView_Object * myPullingObject
Definition: GraphicsView_ViewPort.h:347
static QCursor * panCursor
Definition: GraphicsView_ViewPort.h:269
static QCursor * getZoomCursor()
Definition: GraphicsView_ViewPort.h:233
GraphicsView_Object * getHighlightedObject() const
Definition: GraphicsView_ViewPort.h:180
void vpMouseEvent(QGraphicsSceneMouseEvent *)
void vpObjectAfterMoving(bool)
QColor myForegroundFrameColor
Definition: GraphicsView_ViewPort.h:297
bool isUnlimitedPanning() const
Definition: GraphicsView_ViewPort.h:170
int mySelectionIterator
Definition: GraphicsView_ViewPort.h:324
bool myIsMousePositionEnabled
Definition: GraphicsView_ViewPort.h:290
bool myIsGridEnabled
Definition: GraphicsView_ViewPort.h:302
QColor foregroundColor() const
Definition: GraphicsView_ViewPort.h:135
bool myDraggingSelectedByLeftButton
Definition: GraphicsView_ViewPort.h:343
QPointF myDragPosition
Definition: GraphicsView_ViewPort.h:341
QColor myGridLineColor
Definition: GraphicsView_ViewPort.h:305
bool isPulling() const
Definition: GraphicsView_ViewPort.h:221
QColor myForegroundColor
Definition: GraphicsView_ViewPort.h:296
ViewLabel * myViewLabel
Definition: GraphicsView_ViewPort.h:285
int myIsDragging
Definition: GraphicsView_ViewPort.h:340
GraphicsView_Object * myHighlightedObject
Definition: GraphicsView_ViewPort.h:317
bool isDraggingSelectedByLeftButton() const
Definition: GraphicsView_ViewPort.h:214
QPoint myLastSelectionPoint
Definition: GraphicsView_ViewPort.h:329
static QCursor * getPanglCursor()
Definition: GraphicsView_ViewPort.h:232
QRubberBand * myRectBand
Definition: GraphicsView_ViewPort.h:327
double myFitAllGap
Definition: GraphicsView_ViewPort.h:278
GraphicsView_ObjectList myObjects
Definition: GraphicsView_ViewPort.h:279
static QCursor * getSketchCursor()
Definition: GraphicsView_ViewPort.h:234
bool isTransforming() const
Definition: GraphicsView_ViewPort.h:163
QPointF mySketchingPoint
Definition: GraphicsView_ViewPort.h:334
QTransform myCurrentTransform
Definition: GraphicsView_ViewPort.h:310
ViewLabelPosition
Definition: GraphicsView_ViewPort.h:73
const GraphicsView_ObjectList & getSelectedObjects() const
Definition: GraphicsView_ViewPort.h:193
QGraphicsPathItem * myGridItem
Definition: GraphicsView_ViewPort.h:306
QCursor myStoredCursor
Definition: GraphicsView_ViewPort.h:350
GraphicsView_ObjectList mySelectedObjects
Definition: GraphicsView_ViewPort.h:323
ViewLabelPosition myViewLabelPosition
Definition: GraphicsView_ViewPort.h:286
static int nCounter
Definition: GraphicsView_ViewPort.h:266
GraphicsView_Scene * getScene()
Definition: GraphicsView_ViewPort.h:86