]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionsetrelativezero.cpp
Initial import
[architektonas] / src / actions / rs_actionsetrelativezero.cpp
1 /****************************************************************************
2 ** $Id: rs_actionsetrelativezero.cpp 1134 2004-07-13 23:26:13Z 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_actionsetrelativezero.h"
28
29 #include "rs_snapper.h"
30 #include "rs_point.h"
31
32
33
34 RS_ActionSetRelativeZero::RS_ActionSetRelativeZero(RS_EntityContainer& container,
35         RS_GraphicView& graphicView)
36         :RS_PreviewActionInterface("Set the relative Zero",
37                            container, graphicView) {}
38
39
40 QAction * RS_ActionSetRelativeZero::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
41 {
42         QAction * action = new QAction(tr("&Set Relative Zero"), 0);
43 //      QAction* action = new QAction(tr("Set Relative Zero"), tr("&Set Relative Zero"),
44 //                                                                      QKeySequence(), NULL);
45         action->setStatusTip(tr("Set position of the Relative Zero point"));
46         return action;
47 }
48
49
50 void RS_ActionSetRelativeZero::trigger() {
51     bool wasLocked = graphicView->isRelativeZeroLocked();
52     if (pt.valid) {
53         graphicView->lockRelativeZero(false);
54         graphicView->moveRelativeZero(pt);
55         graphicView->lockRelativeZero(wasLocked);
56     }
57     finish();
58 }
59
60
61
62 void RS_ActionSetRelativeZero::mouseMoveEvent(QMouseEvent* e) {
63     snapPoint(e);
64 }
65
66
67
68 void RS_ActionSetRelativeZero::mouseReleaseEvent(QMouseEvent* e) {
69     if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
70         deleteSnapper();
71         init(getStatus()-1);
72     } else {
73         RS_CoordinateEvent ce(snapPoint(e));
74         coordinateEvent(&ce);
75     }
76 }
77
78
79
80 void RS_ActionSetRelativeZero::coordinateEvent(RS_CoordinateEvent* e) {
81     if (e==NULL) {
82         return;
83     }
84
85     pt = e->getCoordinate();
86     trigger();
87 }
88
89
90
91 void RS_ActionSetRelativeZero::updateMouseButtonHints() {
92     switch (getStatus()) {
93     case 0:
94         RS_DIALOGFACTORY->updateMouseWidget(tr("Set relative Zero"), tr("Cancel"));
95         break;
96     default:
97         RS_DIALOGFACTORY->updateMouseWidget("", "");
98         break;
99     }
100 }
101
102
103
104 void RS_ActionSetRelativeZero::updateMouseCursor() {
105     graphicView->setMouseCursor(RS2::CadCursor);
106 }
107
108
109
110 void RS_ActionSetRelativeZero::updateToolBar() {
111     if (!isFinished()) {
112         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
113     } else {
114         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
115     }
116 }
117
118 // EOF