]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondrawpoint.cpp
In the middle of major refactoring...
[architektonas] / src / actions / actiondrawpoint.cpp
1 // actiondrawpoint.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  05/22/2010  Added this text. :-)
13 //
14
15 #include "actiondrawpoint.h"
16
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
21
22 ActionDrawPoint::ActionDrawPoint(RS_EntityContainer & container, GraphicView & graphicView):
23         ActionInterface("Draw Points", container, graphicView)
24 {
25 }
26
27 ActionDrawPoint::~ActionDrawPoint()
28 {
29 }
30
31 void ActionDrawPoint::trigger()
32 {
33         if (pt.valid)
34         {
35                 RS_Point * point = new RS_Point(container, RS_PointData(pt));
36                 container->addEntity(point);
37
38                 if (document)
39                 {
40                         document->startUndoCycle();
41                         document->addUndoable(point);
42                         document->endUndoCycle();
43                 }
44
45                 deleteSnapper();
46                 graphicView->moveRelativeZero(Vector(0.0, 0.0));
47                 graphicView->drawEntity(point);
48                 graphicView->moveRelativeZero(pt);
49                 drawSnapper();
50         }
51 }
52
53 void ActionDrawPoint::mouseMoveEvent(QMouseEvent * e)
54 {
55         snapPoint(e);
56 }
57
58 void ActionDrawPoint::mouseReleaseEvent(QMouseEvent * e)
59 {
60         if (e->button() == Qt::LeftButton)
61         {
62                 Vector ce(snapPoint(e));
63                 coordinateEvent(&ce);
64         }
65         else if (e->button() == Qt::RightButton)
66         {
67                 deleteSnapper();
68                 init(getStatus() - 1);
69         }
70 }
71
72 void ActionDrawPoint::coordinateEvent(Vector * e)
73 {
74         if (e == NULL)
75                 return;
76
77         Vector mouse = *e;
78
79         pt = mouse;
80         trigger();
81 }
82
83 void ActionDrawPoint::commandEvent(RS_CommandEvent * e)
84 {
85         QString c = e->getCommand().toLower();
86
87         if (checkCommand("help", c))
88         {
89                 if (RS_DIALOGFACTORY != NULL)
90                         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
91                                 + getAvailableCommands().join(", "));
92
93                 return;
94         }
95 }
96
97 QStringList ActionDrawPoint::getAvailableCommands()
98 {
99         QStringList cmd;
100         return cmd;
101 }
102
103 void ActionDrawPoint::updateMouseButtonHints()
104 {
105         if (RS_DIALOGFACTORY != NULL)
106         {
107                 switch (getStatus())
108                 {
109                 case 0:
110                         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify location"), tr("Cancel"));
111                         break;
112
113                 default:
114                         RS_DIALOGFACTORY->updateMouseWidget("", "");
115                         break;
116                 }
117         }
118 }
119
120 void ActionDrawPoint::updateMouseCursor()
121 {
122         graphicView->setMouseCursor(RS2::CadCursor);
123 }
124
125 void ActionDrawPoint::updateToolBar()
126 {
127         if (RS_DIALOGFACTORY != NULL)
128         {
129                 if (!isFinished())
130                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
131                 else
132                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarPoints);
133         }
134 }