1 /****************************************************************************
2 ** $Id: rs_actionmodifymove.cpp 1161 2004-12-09 23:10:09Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actionmodifymove.h"
29 #include "rs_snapper.h"
33 RS_ActionModifyMove::RS_ActionModifyMove(RS_EntityContainer& container,
34 RS_GraphicView& graphicView):
35 RS_PreviewActionInterface("Move Entities", container, graphicView)
39 QAction* RS_ActionModifyMove::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
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"));
48 void RS_ActionModifyMove::init(int status)
50 RS_ActionInterface::init(status);
55 void RS_ActionModifyMove::trigger()
58 RS_DEBUG->print("RS_ActionModifyMove::trigger()");
60 RS_Modification m(*container, graphicView);
63 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
68 void RS_ActionModifyMove::mouseMoveEvent(QMouseEvent* e) {
69 RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent begin");
71 if (getStatus()==SetReferencePoint ||
72 getStatus()==SetTargetPoint) {
74 Vector mouse = snapPoint(e);
75 switch (getStatus()) {
76 case SetReferencePoint:
77 referencePoint = mouse;
81 if (referencePoint.valid) {
86 preview->addSelectionFrom(*container);
87 preview->move(targetPoint-referencePoint);
97 RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent end");
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) {
113 void RS_ActionModifyMove::coordinateEvent(RS_CoordinateEvent* e) {
119 Vector pos = e->getCoordinate();
121 switch (getStatus()) {
122 case SetReferencePoint:
123 referencePoint = pos;
124 graphicView->moveRelativeZero(referencePoint);
125 setStatus(SetTargetPoint);
130 graphicView->moveRelativeZero(targetPoint);
131 setStatus(ShowDialog);
132 if (RS_DIALOGFACTORY->requestMoveDialog(data)) {
133 data.offset = targetPoint - referencePoint;
145 void RS_ActionModifyMove::updateMouseButtonHints() {
146 switch (getStatus()) {
148 RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"),
151 case SetReferencePoint:
152 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
156 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
160 RS_DIALOGFACTORY->updateMouseWidget("", "");
167 void RS_ActionModifyMove::updateMouseCursor() {
168 graphicView->setMouseCursor(RS2::CadCursor);
173 void RS_ActionModifyMove::updateToolBar() {
174 switch (getStatus()) {
176 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
178 case SetReferencePoint:
180 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
183 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);