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