]> Shamusworld >> Repos - architektonas/blob - src/actions/actionsetrelativezero.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actionsetrelativezero.cpp
1 // actionsetrelativezero.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/05/2010  Added this text. :-)
15 //
16
17 #include "actionsetrelativezero.h"
18
19 #include "dialogfactory.h"
20 #include "graphicview.h"
21
22 ActionSetRelativeZero::ActionSetRelativeZero(EntityContainer & container,
23         GraphicView & graphicView): ActionInterface("Set the relative Zero",
24                 container, graphicView)
25 {
26 }
27
28 ActionSetRelativeZero::~ActionSetRelativeZero()
29 {
30 }
31
32 /*virtual*/ RS2::ActionType ActionSetRelativeZero::rtti()
33 {
34         return RS2::ActionSetRelativeZero;
35 }
36
37 void ActionSetRelativeZero::trigger()
38 {
39         bool wasLocked = graphicView->isRelativeZeroLocked();
40
41         if (pt.valid)
42         {
43                 graphicView->lockRelativeZero(false);
44                 graphicView->moveRelativeZero(pt);
45                 graphicView->lockRelativeZero(wasLocked);
46         }
47         finish();
48 }
49
50 void ActionSetRelativeZero::mouseMoveEvent(QMouseEvent * e)
51 {
52         snapPoint(e);
53 }
54
55 void ActionSetRelativeZero::mouseReleaseEvent(QMouseEvent * e)
56 {
57         if (e->button() == Qt::RightButton)
58         {
59                 deleteSnapper();
60                 init(getStatus() - 1);
61         }
62         else
63         {
64                 Vector ce(snapPoint(e));
65                 coordinateEvent(&ce);
66         }
67 }
68
69 void ActionSetRelativeZero::coordinateEvent(Vector * e)
70 {
71         if (e == NULL)
72                 return;
73
74         pt = *e;
75         trigger();
76 }
77
78 void ActionSetRelativeZero::updateMouseButtonHints()
79 {
80         switch (getStatus())
81         {
82         case 0:
83                 DIALOGFACTORY->updateMouseWidget(tr("Set relative Zero"), tr("Cancel"));
84                 break;
85
86         default:
87                 DIALOGFACTORY->updateMouseWidget("", "");
88                 break;
89         }
90 }
91
92 void ActionSetRelativeZero::updateMouseCursor()
93 {
94         graphicView->setMouseCursor(RS2::CadCursor);
95 }
96
97 void ActionSetRelativeZero::updateToolBar()
98 {
99         if (!isFinished())
100                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
101         else
102                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
103 }
104
105