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