CViewBase.h
Go to the documentation of this file.
1 #ifndef iview_CViewBase_included
2 #define iview_CViewBase_included
3 
4 
5 // ACF includes
6 #include <i2d/CRectangle.h>
7 
8 #include <iview/IDraggable.h>
10 #include <iview/CScreenTransform.h>
11 #include <iview/CViewLayer.h>
13 
14 
15 class QPainter;
16 
17 
18 namespace iview
19 {
20 
21 
22 class IViewEventObserver;
23 class ISelectableLayer;
24 class IInteractiveShape;
25 
26 
27 class CViewBase:
28  virtual public IShapeView,
29  virtual public IDraggable,
30  protected IMouseActionObserver
31 {
32 public:
33  enum ZoomMode{
42  };
43 
44  CViewBase();
45  virtual ~CViewBase();
46 
50  virtual void SetZoom(ZoomMode zoom);
51 
55  virtual void SetEditMode(int mode);
56 
60  virtual void UpdateAllShapes(const istd::IChangeable::ChangeSet& changeSet);
61 
65  virtual void SetScreenPosition(const i2d::CVector2d& client, istd::CIndex2d screen);
66 
71  virtual const i2d::CRectangle& GetFitArea() const;
72 
77  virtual void SetFitArea(const i2d::CRectangle& area);
78 
82  virtual void SetViewDraggable(bool state = true);
83 
87  virtual void SetMultiselectable(bool state = true);
88 
92  virtual void SetDraggable(bool state = true);
93 
97  virtual void AddViewEventObserver(iview::IViewEventObserver* listenerPtr);
98 
102  virtual void RemoveViewEventObserver(iview::IViewEventObserver* listenerPtr);
103 
107  virtual void InsertDefaultLayers();
108 
112  int GetBackgroundLayerIndex() const;
113 
117  int GetInactiveLayerIndex() const;
118 
122  int GetActiveLayerIndex() const;
123 
129 
131 
132  // reimplemented (iview::IShapeView)
133  virtual void Update();
134  virtual bool IsViewDraggable() const;
135  virtual bool IsMultiselectable() const;
136  virtual int InsertLayer(IViewLayer* layerPtr, int index = -1, int layerType = IViewLayer::LT_NONE);
137  virtual int GetLayerIndex(const IViewLayer& layer) const;
138  virtual int GetLayerIndex(int layerType) const;
139  virtual void RemoveLayer(int index);
140  virtual int GetLayersCount() const;
141  virtual IViewLayer& GetLayer(int index) const;
142  virtual bool ConnectShape(IShape* shapePtr);
143  virtual ISelectableLayer* GetFocusedLayerPtr() const;
144  virtual void OnLayerShapeFocused(IInteractiveShape* shapePtr, ISelectableLayer* layerPtr);
145  virtual void OnLayerShapeDefocused(IInteractiveShape* shapePtr, ISelectableLayer* layerPtr);
146  virtual void OnLayerInvalidated(const IViewLayer& layer, const i2d::CRect& prevArea, const i2d::CRect& newArea);
147 
148  // reimplemented (iview::ISelectable)
149  virtual int GetSelectedShapesCount() const;
150  virtual void InsertSelectedShapes(SelectedShapes& result) const;
151  virtual void DeselectAllShapes();
152  virtual int GetKeysState() const;
153  virtual int GetEditMode() const;
154  virtual void OnShapeFocused(IInteractiveShape* /*shapePtr*/) {}
155  virtual void OnShapeDefocused(IInteractiveShape* /*shapePtr*/) {}
156 
157  // reimplemented (iview::ITouchable)
158  virtual TouchState IsTouched(istd::CIndex2d position) const;
159  virtual QString GetShapeDescriptionAt(istd::CIndex2d position) const;
160 
161  // reimplemented (iview::IShapeView)
162  virtual void SetTransform(const i2d::CAffine2d& transform);
163  virtual void UpdateMousePointer();
164 
165  // reimplemented (iview::IMouseActionObserver)
166  virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag);
167  virtual bool OnMouseMove(istd::CIndex2d position);
168 
169  // reimplemented (iview::IDisplay)
170  virtual IDisplay* GetParentDisplayPtr() const;
171  virtual const iview::CScreenTransform& GetTransform() const;
172  virtual i2d::CRect GetBoundingBox() const;
173  virtual const IColorSchema& GetColorSchema() const;
174  virtual void OnAreaInvalidated(const i2d::CRect& prevArea, const i2d::CRect& newArea);
175 
176  // reimplemented (iview::IShapeObserver)
177  virtual void OnChangeShape(IShape* shapePtr);
178  virtual bool DisconnectShape(IShape* shapePtr);
179  virtual void OnShapeSelected(IInteractiveShape& shape, bool state = true);
180 
181  // reimplemented (iview::IDraggable)
182  virtual bool IsDraggable() const;
183  virtual void BeginDrag(const istd::CIndex2d& reference);
184  virtual void SetDragPosition(const istd::CIndex2d& position);
185  virtual void EndDrag();
186 
187  // abstract methods
188  virtual const IColorSchema& GetDefaultColorSchema() const = 0;
189 
190 protected:
191  typedef QVector<IViewLayer*> Layers;
192 
199  virtual void DrawLayers(QPainter& drawContext, int firstLayer, int lastLayer);
200 
205  void SetLastBackgroundLayerIndex(int index);
206 
212  virtual bool CanBeMoved() const;
213 
217  void DisconnectAllShapes();
218 
223  virtual void InvalidateBackground();
224 
228  virtual void InvalidateBoundingBox();
233  bool EnsureBoundingBoxValid();
234 
239  virtual i2d::CRect CalcBoundingBox() const;
243  virtual void OnBoundingBoxChanged();
244 
245  virtual MousePointerMode CalcMousePointer(istd::CIndex2d position) const;
246 
250  virtual void InvalidateMouseShape();
251 
255  virtual void CalcMouseShape() const;
256 
260  virtual bool IsBackgroundBufferValid() const;
261 
265  virtual void SetBackgroundBufferValid(bool state = true);
266 
270  const i2d::CRect& GetInvalidatedBox() const;
271 
276  void InvalidateBox(const i2d::CRect& rect);
277 
281  void ResetInvalidatedBox();
282 
286  void SetKeysState(int state);
287 
288  const Layers& GetLayers() const;
289  Layers& GetLayers();
290 
291  // abstract methods
292 
297  virtual void SetMousePointer(MousePointerMode mode) = 0;
300  virtual void UpdateRectArea(const i2d::CRect& rect) = 0;
301 
302 private:
303  enum ViewMode
304  {
305  VM_NONE,
306  VM_DRAG,
307  VM_MOVE
308  };
309 
310  bool m_isBackgroundBufferValid;
311 
312  iview::CScreenTransform m_transform;
313 
314  ViewMode m_viewMode;
315  int m_editMode;
316  i2d::CVector2d m_moveReference;
317 
318  bool m_isMultiselectable;
319  bool m_isViewDraggable;
320  bool m_isDraggable;
321 
322  QVector<iview::IViewEventObserver*> m_viewListeners;
323 
324  ISelectableLayer* m_focusedLayerPtr;
325  int m_backgroundLayerIndex;
326  int m_activeLayerIndex;
327  int m_inactiveLayerIndex;
328 
329  i2d::CRect m_invalidatedBox;
330  i2d::CRectangle m_fitArea;
331 
332  Layers m_layers;
333 
334  int m_lastBackgroundLayerIndex;
335 
336  // default layers
337  iview::CViewLayer m_backgroundLayer;
338  iview::CViewLayer m_inactiveLayer;
339  iview::CInteractiveViewLayer m_activeLayer;
340 
341  // help objects
342  bool m_isLastMouseButtonDown;
343  mutable int m_keysState;
344  mutable istd::CIndex2d m_lastMousePosition;
345  mutable bool m_isSelectEventActive;
346 
347  i2d::CRect m_boundingBox;
348  bool m_isBoundingBoxValid;
349 
350  mutable IInteractiveShape* m_mouseShapePtr;
351  mutable bool m_isMouseShapeValid;
352 
353  mutable bool m_blockBBoxEvent;
354 };
355 
356 
357 // inline methods
358 
360 {
361  return m_fitArea;
362 }
363 
364 
365 inline void CViewBase::SetFitArea(const i2d::CRectangle& area)
366 {
367  m_fitArea = area;
368 }
369 
370 
371 inline void CViewBase::SetViewDraggable(bool state)
372 {
373  m_isViewDraggable = state;
374 }
375 
376 
377 inline void CViewBase::SetMultiselectable(bool state)
378 {
379  m_isMultiselectable = state;
380 }
381 
382 
383 inline void CViewBase::SetDraggable(bool state)
384 {
385  m_isDraggable = state;
386 }
387 
388 
390 {
391  if (!m_isMouseShapeValid){
392  CalcMouseShape();
393  m_isMouseShapeValid = true;
394  }
395 
396  return m_mouseShapePtr;
397 }
398 
399 
400 // reimplemented (iview::IShapeView)
401 
402 inline bool CViewBase::IsViewDraggable() const
403 {
404  return m_isViewDraggable;
405 }
406 
407 
408 inline bool CViewBase::IsMultiselectable() const
409 {
410  return m_isMultiselectable;
411 }
412 
413 
414 inline int CViewBase::GetLayersCount() const
415 {
416  return int(m_layers.size());
417 }
418 
419 
420 inline IViewLayer& CViewBase::GetLayer(int index) const
421 {
422  if (GetLayersCount() <= 0){
423  CViewBase* view = const_cast<CViewBase*> (this);
424  view->InsertDefaultLayers();
425  }
426 
427  Q_ASSERT((index >= 0) && (index < int(m_layers.size())));
428 
429  IViewLayer* layerPtr = m_layers[index];
430  Q_ASSERT(layerPtr != NULL);
431 
432  return *layerPtr;
433 }
434 
435 
436 // reimplemented (iview::IDisplay)
437 
439 {
440  return NULL;
441 }
442 
443 
445 {
446  return m_transform;
447 }
448 
449 
451 {
452  const_cast<CViewBase*>(this)->EnsureBoundingBoxValid();
453 
454  return m_boundingBox;
455 }
456 
457 
459 {
460  return GetDefaultColorSchema();
461 }
462 
463 
464 // reimplemented (iview::ISelectable)
465 
466 inline int CViewBase::GetKeysState() const
467 {
468  return m_keysState;
469 }
470 
471 
472 // reimplemented (iview::IDraggable)
473 
474 inline bool CViewBase::IsDraggable() const
475 {
476  return m_isDraggable;
477 }
478 
479 
480 // protected methods
481 
483 {
484  return m_lastBackgroundLayerIndex;
485 }
486 
487 
489 {
490  m_lastBackgroundLayerIndex = index;
491 }
492 
493 
495 {
496  return m_backgroundLayerIndex;
497 }
498 
499 
501 {
502  return m_inactiveLayerIndex;
503 }
504 
505 
507 {
508  return m_activeLayerIndex;
509 }
510 
511 
513 {
514  return m_isBackgroundBufferValid;
515 }
516 
517 
518 inline void CViewBase::SetBackgroundBufferValid(bool state)
519 {
520  if (state != m_isBackgroundBufferValid){
521  if (!state){
522  m_invalidatedBox = GetClientRect();
523  }
524  m_isBackgroundBufferValid = state;
525  }
526 }
527 
528 
530 {
531  return m_invalidatedBox;
532 }
533 
534 
535 inline void CViewBase::InvalidateBox(const i2d::CRect& rect)
536 {
537  m_invalidatedBox.Union(rect);
538 }
539 
540 
542 {
543  m_invalidatedBox.Reset();
544 }
545 
546 
547 inline void CViewBase::SetKeysState(int state)
548 {
549  m_keysState = state;
550 }
551 
552 
554 {
555  return m_layers;
556 }
557 
558 
560 {
561  return m_layers;
562 }
563 
564 
565 } // namespace iview
566 
567 
568 #endif // !iview_CViewBase_included
569 
570 
virtual void InsertDefaultLayers()
Insert default layers, when there is no one user layer.
int GetLastBackgroundLayerIndex()
Get last background layer index.
Definition: CViewBase.h:482
Interface for a logical layer in the console view.
Definition: IViewLayer.h:24
virtual bool CanBeMoved() const
This method is internal used to check, if drag mode is allowed.
virtual void SetMultiselectable(bool state=true)
Turn on/off possibility to select more shapes using control keys.
Definition: CViewBase.h:377
virtual bool ConnectShape(IShape *shapePtr)
Connect shape object to view.
virtual void SetScreenPosition(const i2d::CVector2d &client, istd::CIndex2d screen)
It sets position to become transformation of client point to specified screen position.
virtual void InsertSelectedShapes(SelectedShapes &result) const
Get set of selected shapes.
bool EnsureBoundingBoxValid()
Calculate bounding box if it was invalid.
virtual void Update()
Updates all invalidates shapes.
virtual bool IsViewDraggable() const
Check if is draggable mode.
Definition: CViewBase.h:402
void SetKeysState(int state)
Set state of keys.
Definition: CViewBase.h:547
virtual int GetLayersCount() const
Get count of layer in this view.
Definition: CViewBase.h:414
void Union(const CRect &rect)
Calculate union of this and second rectangle and stores result in this object.
Definition: CRect.h:495
MousePointerMode
Defines possible states of mouse pointer.
Definition: ISelectable.h:29
virtual void InvalidateBoundingBox()
Invalidate bounding box.
virtual bool IsBackgroundBufferValid() const
Check if background buffer is valid.
Definition: CViewBase.h:512
virtual bool IsMultiselectable() const
Check, if it is possible to select more than one shape.
Definition: CViewBase.h:408
const Layers & GetLayers() const
Definition: CViewBase.h:553
virtual const IColorSchema & GetColorSchema() const
Get color schema.
Definition: CViewBase.h:458
virtual void UpdateRectArea(const i2d::CRect &rect)=0
Start updating specified rectangle area.
virtual void SetTransform(const i2d::CAffine2d &transform)
Set a screen transformation.
virtual int GetSelectedShapesCount() const
Get count of selected shapes.
virtual void UpdateMousePointer()
Update mouse pointer.
Simple rectangle with integer bounds.
Definition: CRect.h:21
Index implementation for addressing elements in 2D-space.
Definition: CIndex2d.h:20
virtual int GetLayerIndex(const IViewLayer &layer) const
Get index of layer.
virtual const iview::CScreenTransform & GetTransform() const
Return a screen transformation.
Definition: CViewBase.h:444
virtual IViewLayer & GetLayer(int index) const
Get layer with the given index.
Definition: CViewBase.h:420
Common interface for a general shape view implementations.
Definition: IShapeView.h:24
virtual i2d::CRect GetClientRect() const =0
Get bounding box of client area.
virtual void RemoveLayer(int index)
Remove layer from view.
void InvalidateBox(const i2d::CRect &rect)
Invalidate rectangle screen area.
Definition: CViewBase.h:535
int GetBackgroundLayerIndex() const
Get index of default background layer.
Definition: CViewBase.h:494
virtual int GetKeysState() const
Get state of system keys.
Definition: CViewBase.h:466
virtual void SetEditMode(int mode)
Set edit mode.
virtual void OnShapeFocused(IInteractiveShape *)
Called when shape get focus.
Definition: CViewBase.h:154
Common interface for all display console shapes which can interacts with user.
int GetActiveLayerIndex() const
Get index of default active layer.
Definition: CViewBase.h:506
virtual void OnLayerShapeFocused(IInteractiveShape *shapePtr, ISelectableLayer *layerPtr)
Called when shape in layer get focus.
virtual IDisplay * GetParentDisplayPtr() const
Get parent object of this display.
Definition: CViewBase.h:438
virtual void AddViewEventObserver(iview::IViewEventObserver *listenerPtr)
Adds handler to catch view events.
Common interface for all shapes which are mouse events receiver.
virtual void SetDragPosition(const istd::CIndex2d &position)
Set new drag position.
virtual bool OnMouseButton(istd::CIndex2d position, Qt::MouseButton buttonType, bool downFlag)
It is called, when mouse button is pushed down or up on this object.
Definition of rectangle area orthogonal to axis of coordination system.
Definition: CRectangle.h:26
virtual MousePointerMode CalcMousePointer(istd::CIndex2d position) const
Common interface for all, you can drag.
Definition: IDraggable.h:17
Interface for external view event observer.
virtual void SetViewDraggable(bool state=true)
Turn on/off possibility to move whole view transform.
Definition: CViewBase.h:371
virtual i2d::CRect GetBoundingBox() const
Get bounding box of all object in this display.
Definition: CViewBase.h:450
virtual ~CViewBase()
virtual void OnShapeSelected(IInteractiveShape &shape, bool state=true)
It is called after change shape selection state.
QSet< IInteractiveShape * > SelectedShapes
Definition: ISelectable.h:24
virtual int GetEditMode() const
Get actual edit mode.
virtual void OnBoundingBoxChanged()
Called when bounding box has been changed.
Definition of position or mathematical vector on 2D plane.
Definition: CVector2d.h:28
Common interface for all display console shapes.
Definition: IShape.h:27
virtual void InvalidateMouseShape()
Invalidate stored shape under mouse pointer.
virtual void DrawLayers(QPainter &drawContext, int firstLayer, int lastLayer)
Draw Background layer.
int GetInactiveLayerIndex() const
Get index of default inactive layer.
Definition: CViewBase.h:500
virtual void UpdateAllShapes(const istd::IChangeable::ChangeSet &changeSet)
Inform all shapes about changes.
virtual bool OnMouseMove(istd::CIndex2d position)
It is called, when mouse is moved.
QVector< IViewLayer * > Layers
Definition: CViewBase.h:191
#define NULL
Definition: istd.h:64
virtual void OnShapeDefocused(IInteractiveShape *)
Called when shape loose focus.
Definition: CViewBase.h:155
virtual void RemoveViewEventObserver(iview::IViewEventObserver *listenerPtr)
Removes handler to catch view events.
virtual void OnLayerShapeDefocused(IInteractiveShape *shapePtr, ISelectableLayer *layerPtr)
Called when shape in layer loose focus.
virtual void SetFitArea(const i2d::CRectangle &area)
Set area will be used to fit in some zoom modes.
Definition: CViewBase.h:365
TouchState
Enumeration for possible shape touch states.
Definition: ITouchable.h:24
virtual i2d::CRect CalcBoundingBox() const
Calculate bounding box of all shapes.
virtual void CalcMouseShape() const
Calc shape under mouse pointer.
virtual int InsertLayer(IViewLayer *layerPtr, int index=-1, int layerType=IViewLayer::LT_NONE)
Insert layer to view.
virtual bool DisconnectShape(IShape *shapePtr)
Disconnect shape object from view.
virtual const i2d::CRectangle & GetFitArea() const
Get area will be used to automatic fit the zoom to view size.
Definition: CViewBase.h:359
virtual void EndDrag()
Called after dragging.
virtual ISelectableLayer * GetFocusedLayerPtr() const
Get focused layer.
virtual void SetMousePointer(MousePointerMode mode)=0
Set mouse pointer.
virtual void OnChangeShape(IShape *shapePtr)
Invalidate a shape.
virtual TouchState IsTouched(istd::CIndex2d position) const
Check, if any shape is touched.
virtual void InvalidateBackground()
Invalidate whole background buffer.
Set of change flags (its IDs).
Definition: IChangeable.h:30
Defines set of standard pens, brushes and simple management of unions.
Definition: IColorSchema.h:28
This class defines an affine 2D-transformation.
Definition: CAffine2d.h:17
virtual void SetBackgroundBufferValid(bool state=true)
Set validate flag of background buffer.
Definition: CViewBase.h:518
virtual const IColorSchema & GetDefaultColorSchema() const =0
virtual void DeselectAllShapes()
Set all shapes to be deselected.
virtual void BeginDrag(const istd::CIndex2d &reference)
Called before dragging is begin.
IInteractiveShape * GetMouseShapePtr() const
Get shape under mouse pointer.
Definition: CViewBase.h:389
virtual void SetDraggable(bool state=true)
Turn on/off possibility to move more selected shapes, when one is moved.
Definition: CViewBase.h:383
const i2d::CRect & GetInvalidatedBox() const
Get bounding box of all invalidated rectangles.
Definition: CViewBase.h:529
void DisconnectAllShapes()
Disconnect all shapes from this view.
virtual void SetZoom(ZoomMode zoom)
Set zoom.
void ResetInvalidatedBox()
Reset invalidated box.
Definition: CViewBase.h:541
virtual void OnLayerInvalidated(const IViewLayer &layer, const i2d::CRect &prevArea, const i2d::CRect &newArea)
Inform that layer was invalidated.
virtual bool IsDraggable() const
Check if drag is enabled.
Definition: CViewBase.h:474
virtual QString GetShapeDescriptionAt(istd::CIndex2d position) const
Get description to shape at specified position.
virtual void OnAreaInvalidated(const i2d::CRect &prevArea, const i2d::CRect &newArea)
Invalidate display area.
Standard implementation of view layer.
Definition: CViewLayer.h:21
void Reset()
Set all members to 0.
Definition: CRect.h:488
void SetLastBackgroundLayerIndex(int index)
Definition: CViewBase.h:488
Layer type is not set.
Definition: IViewLayer.h:34
IInteractiveShape * GetFirstActiveShape() const

© 2007-2017 Witold Gantzke and Kirill Lepskiy