]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifyrotate.cpp
GPL compliance check...
[architektonas] / src / actions / actionmodifyrotate.cpp
1 // actionmodifyrotate.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/04/2010  Added this text. :-)
15 //
16
17 #include "actionmodifyrotate.h"
18
19 #include "rs_dialogfactory.h"
20
21 ActionModifyRotate::ActionModifyRotate(RS_EntityContainer & container, GraphicView & graphicView):
22         ActionInterface("Rotate Entities",
23                 container, graphicView)
24 {
25 }
26
27 ActionModifyRotate::~ActionModifyRotate()
28 {
29 }
30
31 void ActionModifyRotate::init(int status)
32 {
33         ActionInterface::init(status);
34 }
35
36 void ActionModifyRotate::trigger()
37 {
38         RS_DEBUG->print("ActionModifyRotate::trigger()");
39
40         RS_Modification m(*container, graphicView);
41         m.rotate(data);
42
43         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
44 }
45
46 void ActionModifyRotate::mouseMoveEvent(QMouseEvent * e)
47 {
48         RS_DEBUG->print("ActionModifyRotate::mouseMoveEvent begin");
49
50         if (getStatus() == SetReferencePoint)
51         {
52                 Vector mouse = snapPoint(e);
53
54                 switch (getStatus())
55                 {
56                 case SetReferencePoint:
57                         referencePoint = mouse;
58                         break;
59
60                 default:
61                         break;
62                 }
63         }
64
65         RS_DEBUG->print("ActionModifyRotate::mouseMoveEvent end");
66 }
67
68 void ActionModifyRotate::mouseReleaseEvent(QMouseEvent * e)
69 {
70         if (e->button() == Qt::LeftButton)
71         {
72                 Vector ce(snapPoint(e));
73                 coordinateEvent(&ce);
74         }
75         else if (e->button() == Qt::RightButton)
76         {
77                 deletePreview();
78                 deleteSnapper();
79                 init(getStatus() - 1);
80         }
81 }
82
83 void ActionModifyRotate::coordinateEvent(Vector * e)
84 {
85         if (e == NULL)
86                 return;
87
88         Vector pos = *e;
89
90         switch (getStatus())
91         {
92         case SetReferencePoint:
93                 referencePoint = pos;
94                 setStatus(ShowDialog);
95
96                 if (RS_DIALOGFACTORY->requestRotateDialog(data))
97                 {
98                         data.center = referencePoint;
99                         trigger();
100                         finish();
101                 }
102                 break;
103
104         default:
105                 break;
106         }
107 }
108
109 void ActionModifyRotate::updateMouseButtonHints()
110 {
111         switch (getStatus())
112         {
113         case SetReferencePoint:
114                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
115                         tr("Back"));
116                 break;
117
118         default:
119                 RS_DIALOGFACTORY->updateMouseWidget("", "");
120                 break;
121         }
122 }
123
124 void ActionModifyRotate::updateMouseCursor()
125 {
126         graphicView->setMouseCursor(RS2::CadCursor);
127 }
128
129 void ActionModifyRotate::updateToolBar()
130 {
131         switch (getStatus())
132         {
133         case SetReferencePoint:
134                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
135                 break;
136
137         default:
138                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
139                 break;
140         }
141 }