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