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