]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioninfodist2.cpp
Scrubbed out all references to RS2::qtToRsButton(). Gone!
[architektonas] / src / actions / rs_actioninfodist2.cpp
1 // rs_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 "rs_actioninfodist2.h"
16
17 #include "rs_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
20
21 RS_ActionInfoDist2::RS_ActionInfoDist2(RS_EntityContainer & container, RS_GraphicView & graphicView):
22         RS_PreviewActionInterface("Info Dist2", container, graphicView)
23 {
24 }
25
26 RS_ActionInfoDist2::~RS_ActionInfoDist2()
27 {
28 }
29
30 void RS_ActionInfoDist2::init(int status)
31 {
32         RS_ActionInterface::init(status);
33 }
34
35 void RS_ActionInfoDist2::trigger()
36 {
37         RS_DEBUG->print("RS_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 RS_ActionInfoDist2::mouseMoveEvent(QMouseEvent * e)
50 {
51         RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent begin");
52
53         switch (getStatus())
54         {
55         case SetEntity:
56                 //entity = catchEntity(e);
57                 break;
58
59         case SetPoint:
60
61                 if (entity != NULL)
62                         point = snapPoint(e);
63                 break;
64
65         default:
66                 break;
67         }
68
69         RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent end");
70 }
71
72 void RS_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                         Vector ce(snapPoint(e));
87                         coordinateEvent(&ce);
88                 }
89                 break;
90
91                 default:
92                         break;
93                 }
94         }
95         else if (e->button() == Qt::RightButton)
96         {
97                 deletePreview();
98                 deleteSnapper();
99                 init(getStatus() - 1);
100         }
101 }
102
103 void RS_ActionInfoDist2::coordinateEvent(Vector * e)
104 {
105         if (e == NULL)
106                 return;
107
108         if (getStatus() == SetPoint && entity != NULL)
109         {
110                 point = *e;
111                 graphicView->moveRelativeZero(point);
112                 trigger();
113                 setStatus(SetEntity);
114         }
115 }
116
117 void RS_ActionInfoDist2::updateMouseButtonHints()
118 {
119         switch (getStatus())
120         {
121         case SetEntity:
122                 RS_DIALOGFACTORY->updateMouseWidget(
123                         tr("Specify entity"),
124                         tr("Cancel"));
125                 break;
126
127         case SetPoint:
128                 RS_DIALOGFACTORY->updateMouseWidget(
129                         tr("Specify point"),
130                         tr("Back"));
131                 break;
132
133         default:
134                 RS_DIALOGFACTORY->updateMouseWidget("", "");
135                 break;
136         }
137 }
138
139 void RS_ActionInfoDist2::updateMouseCursor()
140 {
141         graphicView->setMouseCursor(RS2::CadCursor);
142 }
143
144 void RS_ActionInfoDist2::updateToolBar()
145 {
146         switch (getStatus())
147         {
148         case SetPoint:
149         case SetEntity:
150                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
151                 break;
152
153         default:
154                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
155                 break;
156         }
157 }
158
159 // EOF