]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifyrotate2.cpp
b5d6baac6c9bfd8e38013fdd3137634bde4e0f5d
[architektonas] / src / actions / actionmodifyrotate2.cpp
1 // actionmodifyrotate2.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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/04/2010  Added this text. :-)
13 //
14
15 #include "actionmodifyrotate2.h"
16
17 #include "rs_dialogfactory.h"
18
19 ActionModifyRotate2::ActionModifyRotate2(
20         RS_EntityContainer & container, GraphicView & graphicView):
21         ActionInterface("Rotate Entities around two centers", container, graphicView)
22 {
23 }
24
25 ActionModifyRotate2::~ActionModifyRotate2()
26 {
27 }
28
29 void ActionModifyRotate2::init(int status)
30 {
31         ActionInterface::init(status);
32 }
33
34 void ActionModifyRotate2::trigger()
35 {
36         RS_DEBUG->print("ActionModifyRotate2::trigger()");
37
38         RS_Modification m(*container, graphicView);
39         m.rotate2(data);
40
41         finish();
42
43         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
44 }
45
46 void ActionModifyRotate2::mouseMoveEvent(QMouseEvent * e)
47 {
48         RS_DEBUG->print("ActionModifyRotate2::mouseMoveEvent begin");
49
50         if (getStatus() == SetReferencePoint1 || getStatus() == SetReferencePoint2)
51         {
52                 Vector mouse = snapPoint(e);
53
54                 switch (getStatus())
55                 {
56                 case SetReferencePoint1:
57                         data.center1 = mouse;
58                         break;
59
60                 case SetReferencePoint2:
61
62                         if (data.center1.valid)
63                                 data.center2 = mouse;
64
65                         break;
66
67                 default:
68                         break;
69                 }
70         }
71
72         RS_DEBUG->print("ActionModifyRotate2::mouseMoveEvent end");
73 }
74
75 void ActionModifyRotate2::mouseReleaseEvent(QMouseEvent * e)
76 {
77         if (e->button() == Qt::LeftButton)
78         {
79                 Vector ce(snapPoint(e));
80                 coordinateEvent(&ce);
81         }
82         else if (e->button() == Qt::RightButton)
83         {
84                 deletePreview();
85                 deleteSnapper();
86                 init(getStatus() - 1);
87         }
88 }
89
90 void ActionModifyRotate2::coordinateEvent(Vector * e)
91 {
92         if (e == NULL)
93                 return;
94
95         Vector pos = *e;
96
97         switch (getStatus())
98         {
99         case SetReferencePoint1:
100                 data.center1 = pos;
101                 setStatus(SetReferencePoint2);
102                 break;
103
104         case SetReferencePoint2:
105                 data.center2 = pos;
106                 setStatus(ShowDialog);
107
108                 if (RS_DIALOGFACTORY->requestRotate2Dialog(data))
109                         trigger();
110                         //finish();
111                 break;
112
113         default:
114                 break;
115         }
116 }
117
118 void ActionModifyRotate2::commandEvent(RS_CommandEvent * /*e*/)
119 {
120 }
121
122 QStringList ActionModifyRotate2::getAvailableCommands()
123 {
124         QStringList cmd;
125         return cmd;
126 }
127
128 void ActionModifyRotate2::updateMouseButtonHints()
129 {
130         switch (getStatus())
131         {
132         case SetReferencePoint1:
133                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify absolute reference point"),
134                         tr("Cancel"));
135                 break;
136
137         case SetReferencePoint2:
138                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify relative reference point"),
139                         tr("Back"));
140                 break;
141
142         default:
143                 RS_DIALOGFACTORY->updateMouseWidget("", "");
144                 break;
145         }
146 }
147
148 void ActionModifyRotate2::updateMouseCursor()
149 {
150         graphicView->setMouseCursor(RS2::CadCursor);
151 }
152
153 void ActionModifyRotate2::updateToolBar()
154 {
155         switch (getStatus())
156         {
157         case SetReferencePoint1:
158         case SetReferencePoint2:
159                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
160                 break;
161
162         default:
163                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
164                 break;
165         }
166 }