1 #pragma once 2 3 #ifndef SUBCAMERAMANAGER_INCLUDED 4 #define SUBCAMERAMANAGER_INCLUDED 5 6 #include "tgeometry.h" 7 8 //============================================================================== 9 10 // Forward declarations 11 class QMouseEvent; 12 class QPaintEvent; 13 class SceneViewer; 14 class QPoint; 15 16 //============================================================================== 17 18 //===================================== 19 // SceneViewerInteractiveGadget 20 //------------------------------------- 21 22 /*! 23 SceneViewerInteractiveGadget constitutes the base class for implementing 24 objects that use the SceneViewer for user editing. 25 The class contains the basic QEvent-related methods that a SceneViewer 26 will invoke once an instance of this class has been assigned to it. 27 The class implements a priority number which identifies the precedence 28 between gadgets. Lower priority gadgets interact later and are drawn before 29 with respect to higher priority ones. 30 Interaction methods such as mouse events also return a boolean to specify 31 whether 32 the event allows further processing of lower priority gadgets. 33 \note Under development yet. 34 */ 35 class SceneViewerInteractiveGadget { 36 public: getPriority()37 virtual int getPriority() const { return 0; } 38 mousePressEvent(SceneViewer * viewer,QMouseEvent * me)39 virtual bool mousePressEvent(SceneViewer *viewer, QMouseEvent *me) { 40 return true; 41 } mouseMoveEvent(SceneViewer * viewer,QMouseEvent * me)42 virtual bool mouseMoveEvent(SceneViewer *viewer, QMouseEvent *me) { 43 return true; 44 } mouseReleaseEvent(SceneViewer * viewer,QMouseEvent * me)45 virtual bool mouseReleaseEvent(SceneViewer *viewer, QMouseEvent *me) { 46 return true; 47 } 48 draw(SceneViewer * viewer,QPaintEvent * pe)49 virtual void draw(SceneViewer *viewer, QPaintEvent *pe) {} 50 }; 51 52 //============================================================================== 53 54 //================================ 55 // PreviewSubCameraManager 56 //-------------------------------- 57 58 class PreviewSubCameraManager final : public SceneViewerInteractiveGadget { 59 TRect m_editingInterestRect; 60 UCHAR m_dragType; 61 bool m_clickAndDrag; 62 63 QPointF m_mousePressPos; 64 TPointD m_cameraMousePressPos; 65 bool m_mousePressed; 66 67 public: 68 enum EditPreviewDrag { 69 NODRAG = 0x0, 70 OUTER_LEFT = 0x1, 71 INNER_LEFT = 0x2, 72 OUTER_RIGHT = 0x4, 73 INNER_RIGHT = 0x8, 74 OUTER_TOP = 0x10, 75 INNER_TOP = 0x20, 76 OUTER_BOTTOM = 0x40, 77 INNER_BOTTOM = 0x80, 78 OUTER = OUTER_LEFT | OUTER_RIGHT | OUTER_TOP | OUTER_BOTTOM, 79 INNER = INNER_LEFT | INNER_RIGHT | INNER_TOP | INNER_BOTTOM, 80 DRAG_LEFT = OUTER_LEFT | INNER, 81 DRAG_RIGHT = OUTER_RIGHT | INNER, 82 DRAG_TOP = OUTER_TOP | INNER, 83 DRAG_BOTTOM = OUTER_BOTTOM | INNER 84 }; 85 86 PreviewSubCameraManager(); 87 ~PreviewSubCameraManager(); 88 89 public: 90 static PreviewSubCameraManager *instance(); 91 getDragType()92 UCHAR getDragType() const { return m_dragType; } setDragType(UCHAR dragType)93 void setDragType(UCHAR dragType) { m_dragType = dragType; } 94 95 TRect getEditingCameraInterestRect() const; setEditingCameraInterestRect(const TRect & rect)96 void setEditingCameraInterestRect(const TRect &rect) { 97 m_editingInterestRect = rect; 98 } 99 100 TRectD getEditingCameraInterestStageRect() const; 101 102 bool mousePressEvent(SceneViewer *viewer, const TMouseEvent &event); 103 bool mouseMoveEvent(SceneViewer *viewer, const TMouseEvent &event); 104 bool mouseReleaseEvent(SceneViewer *viewer); 105 106 void deleteSubCamera(SceneViewer *viewer); 107 108 private: 109 TPointD winToCamera(SceneViewer *viewer, const QPointF &pos) const; 110 TPointD cameraToWin(SceneViewer *viewer, const TPointD &cameraPos) const; 111 112 UCHAR getSubCameraDragEnum(SceneViewer *viewer, const QPointF &mousePos); 113 TPoint getSubCameraDragDistance(SceneViewer *viewer, const QPointF &mousePos); 114 }; 115 116 #endif // SUBCAMERAMANAGER_INCLUDED 117