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