]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifymove.cpp
f38e236ab5a5b00bea5ea6508f8a8abfdbd2b23a
[architektonas] / src / actions / rs_actionmodifymove.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifymove.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionmodifymove.h"
28
29 #include "rs_snapper.h"
30
31
32
33 RS_ActionModifyMove::RS_ActionModifyMove(RS_EntityContainer& container,
34         RS_GraphicView& graphicView):
35         RS_PreviewActionInterface("Move Entities", container, graphicView)
36 {
37 }
38
39 QAction* RS_ActionModifyMove::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
40 {
41         QAction * action = new QAction(tr("&Move / Copy"), 0);
42 //      QAction* action = new QAction(tr("Move / Copy"), tr("&Move / Copy"),
43 //                                                                      QKeySequence(), NULL);
44         action->setStatusTip(tr("Move or copy entities one or multiple times"));
45         return action;
46 }
47
48 void RS_ActionModifyMove::init(int status)
49 {
50     RS_ActionInterface::init(status);
51 }
52
53
54
55 void RS_ActionModifyMove::trigger()
56 {
57
58     RS_DEBUG->print("RS_ActionModifyMove::trigger()");
59
60     RS_Modification m(*container, graphicView);
61     m.move(data);
62
63     RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
64 }
65
66
67
68 void RS_ActionModifyMove::mouseMoveEvent(QMouseEvent* e) {
69     RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent begin");
70
71     if (getStatus()==SetReferencePoint ||
72             getStatus()==SetTargetPoint) {
73
74         Vector mouse = snapPoint(e);
75         switch (getStatus()) {
76         case SetReferencePoint:
77             referencePoint = mouse;
78             break;
79
80         case SetTargetPoint:
81             if (referencePoint.valid) {
82                 targetPoint = mouse;
83
84                 deletePreview();
85                 clearPreview();
86                 preview->addSelectionFrom(*container);
87                 preview->move(targetPoint-referencePoint);
88                 drawPreview();
89             }
90             break;
91
92         default:
93             break;
94         }
95     }
96
97     RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent end");
98 }
99
100
101
102 void RS_ActionModifyMove::mouseReleaseEvent(QMouseEvent* e) {
103     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
104         RS_CoordinateEvent ce(snapPoint(e));
105         coordinateEvent(&ce);
106     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
107         deletePreview();
108         deleteSnapper();
109         init(getStatus()-1);
110     }
111 }
112
113 void RS_ActionModifyMove::coordinateEvent(RS_CoordinateEvent* e) {
114
115     if (e==NULL) {
116         return;
117     }
118
119     Vector pos = e->getCoordinate();
120
121     switch (getStatus()) {
122     case SetReferencePoint:
123         referencePoint = pos;
124         graphicView->moveRelativeZero(referencePoint);
125         setStatus(SetTargetPoint);
126         break;
127
128     case SetTargetPoint:
129         targetPoint = pos;
130         graphicView->moveRelativeZero(targetPoint);
131         setStatus(ShowDialog);
132         if (RS_DIALOGFACTORY->requestMoveDialog(data)) {
133             data.offset = targetPoint - referencePoint;
134             trigger();
135             finish();
136         }
137         break;
138
139     default:
140         break;
141     }
142 }
143
144
145 void RS_ActionModifyMove::updateMouseButtonHints() {
146     switch (getStatus()) {
147         /*case Select:
148             RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"),
149                                            tr("Cancel"));
150             break;*/
151     case SetReferencePoint:
152         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
153                                             tr("Cancel"));
154         break;
155     case SetTargetPoint:
156         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
157                                             tr("Back"));
158         break;
159     default:
160         RS_DIALOGFACTORY->updateMouseWidget("", "");
161         break;
162     }
163 }
164
165
166
167 void RS_ActionModifyMove::updateMouseCursor() {
168     graphicView->setMouseCursor(RS2::CadCursor);
169 }
170
171
172
173 void RS_ActionModifyMove::updateToolBar() {
174     switch (getStatus()) {
175         /*case Select:
176             RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
177             break;*/
178     case SetReferencePoint:
179     case SetTargetPoint:
180         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
181         break;
182     default:
183         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
184         break;
185     }
186 }
187
188
189 // EOF