]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioninfodist.cpp
af59d52643b37869107c1abc77db714ad7becf0d
[architektonas] / src / actions / rs_actioninfodist.cpp
1 // rs_actioninfodist.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_actioninfodist.h"
16
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
20
21 RS_ActionInfoDist::RS_ActionInfoDist(RS_EntityContainer & container, GraphicView & graphicView): RS_PreviewActionInterface("Info Dist",
22                 container, graphicView)
23 {
24 }
25
26 RS_ActionInfoDist::~RS_ActionInfoDist()
27 {
28 }
29
30 void RS_ActionInfoDist::init(int status)
31 {
32         RS_ActionInterface::init(status);
33 }
34
35 void RS_ActionInfoDist::trigger()
36 {
37         RS_DEBUG->print("RS_ActionInfoDist::trigger()");
38
39         if (point1.valid && point2.valid)
40         {
41                 double dist = point1.distanceTo(point2);
42                 QString str;
43                 str.sprintf("%.6f", dist);
44                 RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str));
45         }
46 }
47
48 void RS_ActionInfoDist::mouseMoveEvent(QMouseEvent * e)
49 {
50         RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent begin");
51
52         if (getStatus() == SetPoint1
53             || getStatus() == SetPoint2)
54         {
55                 Vector mouse = snapPoint(e);
56
57                 switch (getStatus())
58                 {
59                 case SetPoint1:
60                         break;
61
62                 case SetPoint2:
63
64                         if (point1.valid)
65                         {
66                                 point2 = mouse;
67
68                                 deletePreview();
69                                 clearPreview();
70
71                                 preview->addEntity(new RS_Line(preview,
72                                                 RS_LineData(point1,
73                                                         point2)));
74
75                                 drawPreview();
76                         }
77                         break;
78
79                 default:
80                         break;
81                 }
82         }
83
84         RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent end");
85 }
86
87 void RS_ActionInfoDist::mouseReleaseEvent(QMouseEvent * e)
88 {
89         if (e->button() == Qt::LeftButton)
90         {
91                 Vector ce(snapPoint(e));
92                 coordinateEvent(&ce);
93         }
94         else if (e->button() == Qt::RightButton)
95         {
96                 deletePreview();
97                 deleteSnapper();
98                 init(getStatus() - 1);
99         }
100 }
101
102 void RS_ActionInfoDist::coordinateEvent(Vector * e)
103 {
104         if (e == NULL)
105                 return;
106
107         Vector mouse = *e;
108
109         switch (getStatus())
110         {
111         case SetPoint1:
112                 point1 = mouse;
113                 graphicView->moveRelativeZero(point1);
114                 setStatus(SetPoint2);
115                 break;
116
117         case SetPoint2:
118
119                 if (point1.valid)
120                 {
121                         point2 = mouse;
122                         deletePreview();
123                         clearPreview();
124                         graphicView->moveRelativeZero(point2);
125                         trigger();
126                         setStatus(SetPoint1);
127                 }
128                 break;
129
130         default:
131                 break;
132         }
133 }
134
135 void RS_ActionInfoDist::updateMouseButtonHints()
136 {
137         switch (getStatus())
138         {
139         case SetPoint1:
140                 RS_DIALOGFACTORY->updateMouseWidget(
141                         tr("Specify first point of distance"),
142                         tr("Cancel"));
143                 break;
144
145         case SetPoint2:
146                 RS_DIALOGFACTORY->updateMouseWidget(
147                         tr("Specify second point of distance"),
148                         tr("Back"));
149                 break;
150
151         default:
152                 RS_DIALOGFACTORY->updateMouseWidget("", "");
153                 break;
154         }
155 }
156
157 void RS_ActionInfoDist::updateMouseCursor()
158 {
159         graphicView->setMouseCursor(RS2::CadCursor);
160 }
161
162 void RS_ActionInfoDist::updateToolBar()
163 {
164         switch (getStatus())
165         {
166         case SetPoint1:
167         case SetPoint2:
168                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
169                 break;
170
171         default:
172                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
173                 break;
174         }
175 }
176
177 // EOF