]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawlinefree.cpp
Initial import
[architektonas] / src / actions / rs_actiondrawlinefree.cpp
1 /****************************************************************************
2 ** $Id: rs_actiondrawlinefree.cpp 1134 2004-07-13 23:26:13Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actiondrawlinefree.h"
28 #include "rs_snapper.h"
29 #include "rs_point.h"
30
31
32
33 RS_ActionDrawLineFree::RS_ActionDrawLineFree(RS_EntityContainer& container,
34         RS_GraphicView& graphicView)
35         :RS_ActionInterface("Draw freehand lines",
36                     container, graphicView) {
37     vertex = Vector(false);
38     polyline = NULL;
39 }
40
41 RS_ActionDrawLineFree::~RS_ActionDrawLineFree() {
42     if (polyline!=NULL) {
43         delete polyline;
44     }
45 }
46
47 QAction* RS_ActionDrawLineFree::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
48 {
49         QAction * action = new QAction(tr("&Freehand Line"), 0);
50 //      QAction* action = new QAction(tr("Line: Freehand"), tr("&Freehand Line"),
51 //                                                                      QKeySequence(), NULL);
52         action->setStatusTip(tr("Draw freehand lines"));
53         return action;
54 }
55
56 void RS_ActionDrawLineFree::trigger() {
57     if (polyline!=NULL) {
58         container->addEntity(polyline);
59         deleteSnapper();
60
61         if (document) {
62             document->startUndoCycle();
63             document->addUndoable(polyline);
64             document->endUndoCycle();
65         }
66
67         RS_DEBUG->print("RS_ActionDrawLineFree::trigger():"
68                         " polyline added: %d", polyline->getId());
69         polyline = NULL;
70     }
71 }
72
73
74
75 void RS_ActionDrawLineFree::mouseMoveEvent(QMouseEvent* e) {
76     if (vertex.valid && polyline!=NULL) {
77         Vector v = snapPoint(e);
78         RS_Entity* ent = polyline->addVertex(v);
79         ent->setLayerToActive();
80         ent->setPenToActive();
81
82         deleteSnapper();
83         graphicView->drawEntity(ent);
84         drawSnapper();
85
86         vertex = v;
87
88         RS_DEBUG->print("RS_ActionDrawLineFree::mouseMoveEvent():"
89                         " line added: %d", ent->getId());
90     }
91 }
92
93
94
95 void RS_ActionDrawLineFree::mousePressEvent(QMouseEvent* e) {
96     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
97         vertex = snapPoint(e);
98         polyline = new RS_Polyline(container,
99                                    RS_PolylineData(vertex, vertex, 0));
100         polyline->setLayerToActive();
101         polyline->setPenToActive();
102     }
103     //else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton && !vertex.valid) {
104     //}
105 }
106
107
108
109 void RS_ActionDrawLineFree::mouseReleaseEvent(QMouseEvent* e) {
110     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
111         vertex = Vector(false);
112         trigger();
113     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
114         if (polyline!=NULL) {
115             delete polyline;
116             polyline = NULL;
117         }
118         deleteSnapper();
119         init(getStatus()-1);
120     }
121 }
122
123
124
125 void RS_ActionDrawLineFree::updateMouseButtonHints() {
126     switch (getStatus()) {
127     case 0:
128         RS_DIALOGFACTORY->updateMouseWidget(
129             tr("Click and drag to draw a line"), tr("Cancel"));
130         break;
131     default:
132         RS_DIALOGFACTORY->updateMouseWidget("", "");
133         break;
134     }
135 }
136
137
138
139 void RS_ActionDrawLineFree::updateMouseCursor() {
140     graphicView->setMouseCursor(RS2::CadCursor);
141 }
142
143
144
145 void RS_ActionDrawLineFree::updateToolBar() {
146     if (!isFinished()) {
147         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
148     } else {
149         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
150     }
151 }
152
153 // EOF