]> Shamusworld >> Repos - architektonas/blob - src/actions/actioninfodist2.cpp
In the middle of major refactoring...
[architektonas] / src / actions / actioninfodist2.cpp
1 // actioninfodist2.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/04/2010  Added this text. :-)
13 //
14
15 #include "actioninfodist2.h"
16
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
20
21 ActionInfoDist2::ActionInfoDist2(RS_EntityContainer & container, GraphicView & graphicView):
22         ActionInterface("Info Dist2", container, graphicView)
23 {
24 }
25
26 ActionInfoDist2::~ActionInfoDist2()
27 {
28 }
29
30 void ActionInfoDist2::init(int status)
31 {
32         ActionInterface::init(status);
33 }
34
35 void ActionInfoDist2::trigger()
36 {
37         RS_DEBUG->print("ActionInfoDist2::trigger()");
38         deleteSnapper();
39
40         if (point.valid && entity != NULL)
41         {
42                 double dist = entity->getDistanceToPoint(point);
43                 QString str;
44                 str.sprintf("%.6f", dist);
45                 RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
46         }
47 }
48
49 void ActionInfoDist2::mouseMoveEvent(QMouseEvent * e)
50 {
51         RS_DEBUG->print("ActionInfoDist2::mouseMoveEvent begin");
52
53         switch (getStatus())
54         {
55         case SetEntity:
56                 //entity = catchEntity(e);
57                 break;
58
59         case SetPoint:
60                 if (entity != NULL)
61                         point = snapPoint(e);
62
63                 break;
64
65         default:
66                 break;
67         }
68
69         RS_DEBUG->print("ActionInfoDist2::mouseMoveEvent end");
70 }
71
72 void ActionInfoDist2::mouseReleaseEvent(QMouseEvent * e)
73 {
74         if (e->button() == Qt::LeftButton)
75         {
76                 switch (getStatus())
77                 {
78                 case SetEntity:
79                         entity = catchEntity(e);
80
81                         if (entity != NULL)
82                                 setStatus(SetPoint);
83                         break;
84
85                 case SetPoint:
86                 {
87                         Vector ce(snapPoint(e));
88                         coordinateEvent(&ce);
89                 }
90                         break;
91
92                 default:
93                         break;
94                 }
95         }
96         else if (e->button() == Qt::RightButton)
97         {
98                 deletePreview();
99                 deleteSnapper();
100                 init(getStatus() - 1);
101         }
102 }
103
104 void ActionInfoDist2::coordinateEvent(Vector * e)
105 {
106         if (e == NULL)
107                 return;
108
109         if (getStatus() == SetPoint && entity != NULL)
110         {
111                 point = *e;
112                 graphicView->moveRelativeZero(point);
113                 trigger();
114                 setStatus(SetEntity);
115         }
116 }
117
118 void ActionInfoDist2::updateMouseButtonHints()
119 {
120         switch (getStatus())
121         {
122         case SetEntity:
123                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity"), tr("Cancel"));
124                 break;
125
126         case SetPoint:
127                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"), tr("Back"));
128                 break;
129
130         default:
131                 RS_DIALOGFACTORY->updateMouseWidget("", "");
132                 break;
133         }
134 }
135
136 void ActionInfoDist2::updateMouseCursor()
137 {
138         graphicView->setMouseCursor(RS2::CadCursor);
139 }
140
141 void ActionInfoDist2::updateToolBar()
142 {
143         switch (getStatus())
144         {
145         case SetPoint:
146         case SetEntity:
147                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
148                 break;
149
150         default:
151                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
152                 break;
153         }
154 }