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