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