]> Shamusworld >> Repos - architektonas/blob - src/actions/actioninfodist.cpp
Last checkin before major refactor...
[architektonas] / src / actions / actioninfodist.cpp
1 // 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 "actioninfodist.h"
16
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_preview.h"
20
21 ActionInfoDist::ActionInfoDist(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Dist",
22                 container, graphicView)
23 {
24 }
25
26 ActionInfoDist::~ActionInfoDist()
27 {
28 }
29
30 void ActionInfoDist::init(int status)
31 {
32         ActionInterface::init(status);
33 }
34
35 void ActionInfoDist::trigger()
36 {
37         RS_DEBUG->print("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 ActionInfoDist::mouseMoveEvent(QMouseEvent * e)
49 {
50         RS_DEBUG->print("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 //                              preview->addEntity(new RS_Line(preview, RS_LineData(point1, point2)));
71                                 drawPreview();
72                         }
73                         break;
74
75                 default:
76                         break;
77                 }
78         }
79
80         RS_DEBUG->print("ActionInfoDist::mouseMoveEvent end");
81 }
82
83 void ActionInfoDist::mouseReleaseEvent(QMouseEvent * e)
84 {
85         if (e->button() == Qt::LeftButton)
86         {
87                 Vector ce(snapPoint(e));
88                 coordinateEvent(&ce);
89         }
90         else if (e->button() == Qt::RightButton)
91         {
92                 deletePreview();
93                 deleteSnapper();
94                 init(getStatus() - 1);
95         }
96 }
97
98 void ActionInfoDist::coordinateEvent(Vector * e)
99 {
100         if (e == NULL)
101                 return;
102
103         Vector mouse = *e;
104
105         switch (getStatus())
106         {
107         case SetPoint1:
108                 point1 = mouse;
109                 graphicView->moveRelativeZero(point1);
110                 setStatus(SetPoint2);
111                 break;
112
113         case SetPoint2:
114
115                 if (point1.valid)
116                 {
117                         point2 = mouse;
118                         deletePreview();
119                         clearPreview();
120                         graphicView->moveRelativeZero(point2);
121                         trigger();
122                         setStatus(SetPoint1);
123                 }
124                 break;
125
126         default:
127                 break;
128         }
129 }
130
131 void ActionInfoDist::updateMouseButtonHints()
132 {
133         switch (getStatus())
134         {
135         case SetPoint1:
136                 RS_DIALOGFACTORY->updateMouseWidget(
137                         tr("Specify first point of distance"),
138                         tr("Cancel"));
139                 break;
140
141         case SetPoint2:
142                 RS_DIALOGFACTORY->updateMouseWidget(
143                         tr("Specify second point of distance"),
144                         tr("Back"));
145                 break;
146
147         default:
148                 RS_DIALOGFACTORY->updateMouseWidget("", "");
149                 break;
150         }
151 }
152
153 void ActionInfoDist::updateMouseCursor()
154 {
155         graphicView->setMouseCursor(RS2::CadCursor);
156 }
157
158 void ActionInfoDist::updateToolBar()
159 {
160         switch (getStatus())
161         {
162         case SetPoint1:
163         case SetPoint2:
164                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
165                 break;
166
167         default:
168                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
169                 break;
170         }
171 }