1 /****************************************************************************
2 ** $Id: rs_actiondrawlinefree.cpp 1134 2004-07-13 23:26:13Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
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.
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.
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.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actiondrawlinefree.h"
28 #include "rs_snapper.h"
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);
41 RS_ActionDrawLineFree::~RS_ActionDrawLineFree() {
47 QAction* RS_ActionDrawLineFree::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
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"));
56 void RS_ActionDrawLineFree::trigger() {
58 container->addEntity(polyline);
62 document->startUndoCycle();
63 document->addUndoable(polyline);
64 document->endUndoCycle();
67 RS_DEBUG->print("RS_ActionDrawLineFree::trigger():"
68 " polyline added: %d", polyline->getId());
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();
83 graphicView->drawEntity(ent);
88 RS_DEBUG->print("RS_ActionDrawLineFree::mouseMoveEvent():"
89 " line added: %d", ent->getId());
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();
103 //else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton && !vertex.valid) {
109 void RS_ActionDrawLineFree::mouseReleaseEvent(QMouseEvent* e) {
110 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
111 vertex = Vector(false);
113 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
114 if (polyline!=NULL) {
125 void RS_ActionDrawLineFree::updateMouseButtonHints() {
126 switch (getStatus()) {
128 RS_DIALOGFACTORY->updateMouseWidget(
129 tr("Click and drag to draw a line"), tr("Cancel"));
132 RS_DIALOGFACTORY->updateMouseWidget("", "");
139 void RS_ActionDrawLineFree::updateMouseCursor() {
140 graphicView->setMouseCursor(RS2::CadCursor);
145 void RS_ActionDrawLineFree::updateToolBar() {
147 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
149 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);