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