1 #pragma once 2 3 #include "tools/tool.h" 4 5 class ShiftTraceTool final : public TTool { 6 public: 7 enum CurveStatus { 8 NoCurve, 9 TwoPointsCurve, // just during the first click&drag 10 ThreePointsCurve 11 }; 12 13 enum GadgetId { 14 NoGadget, 15 NoGadget_InBox, 16 CurveP0Gadget, 17 CurveP1Gadget, 18 CurvePmGadget, 19 MoveCenterGadget, 20 RotateGadget, 21 TranslateGadget, 22 ScaleGadget 23 }; isCurveGadget(GadgetId id)24 inline bool isCurveGadget(GadgetId id) const { 25 return CurveP0Gadget <= id && id <= CurvePmGadget; 26 } 27 28 private: 29 TPointD m_oldPos, m_startPos; 30 int m_ghostIndex; 31 TPointD m_p0, m_p1, m_p2; 32 33 CurveStatus m_curveStatus; 34 GadgetId m_gadget; 35 GadgetId m_highlightedGadget; 36 37 TRectD m_box; 38 TAffine m_dpiAff; 39 int m_row[2]; 40 TAffine m_aff[2]; 41 TPointD m_center[2]; 42 43 TAffine m_oldAff; 44 45 public: 46 ShiftTraceTool(); 47 getToolType()48 ToolType getToolType() const override { return GenericTool; } 49 50 void clearData(); 51 void updateData(); 52 void updateBox(); 53 void updateCurveAffs(); 54 void updateGhost(); 55 56 void reset() override; 57 58 void mouseMove(const TPointD &, const TMouseEvent &e) override; 59 void leftButtonDown(const TPointD &, const TMouseEvent &) override; 60 void leftButtonDrag(const TPointD &, const TMouseEvent &) override; 61 void leftButtonUp(const TPointD &, const TMouseEvent &) override; 62 void draw() override; 63 64 TAffine getGhostAff(); 65 GadgetId getGadget(const TPointD &); 66 void drawDot(const TPointD ¢er, double r, 67 const TPixel32 &color = TPixel32::White); 68 void drawControlRect(); 69 void drawCurve(); 70 71 void onActivate() override; 72 void onDeactivate() override; 73 74 void onLeave() override; 75 76 bool isEventAcceptable(QEvent *e) override; 77 78 int getCursorId() const override; 79 getCurrentGhostIndex()80 int getCurrentGhostIndex() { return m_ghostIndex; } 81 void setCurrentGhostIndex(int index); 82 };