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