1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
14
** This program is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
19
** You should have received a copy of the GNU General Public License
20
** along with this program; if not, write to the Free Software
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
27
#include "rs_actiondrawlinefree.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
35
RS_ActionDrawLineFree::RS_ActionDrawLineFree(RS_EntityContainer& container,
36
RS_GraphicView& graphicView)
37
:RS_PreviewActionInterface("Draw freehand lines",
38
container, graphicView) {
39
vertex = RS_Vector(false);
43
RS_ActionDrawLineFree::~RS_ActionDrawLineFree() {
49
QAction* RS_ActionDrawLineFree::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
50
// tr(""Line: Freehand"),
51
QAction* action = new QAction(tr("&Freehand Line"), NULL);
52
action->setIcon(QIcon(":/extui/linesfree.png"));
53
//action->zetStatusTip(tr("Draw freehand lines"));
57
void RS_ActionDrawLineFree::trigger() {
61
polyline->endPolyline();
62
RS_VectorSolutions sol=polyline->getRefPoints();
63
if(sol.getNumber() > 2 ) {
64
container->addEntity(polyline);
66
document->startUndoCycle();
67
document->addUndoable(polyline);
68
document->endUndoCycle();
70
graphicView->redraw(RS2::RedrawDrawing);
71
RS_DEBUG->print("RS_ActionDrawLineFree::trigger():"
72
" polyline added: %d", polyline->getId());
78
setStatus(SetStartpoint);
82
* 11 Aug 2011, Dongxu Li
85
void RS_ActionDrawLineFree::mouseMoveEvent(QMouseEvent* e) {
86
if (getStatus()==Dragging && polyline!=NULL) {
87
RS_Vector v = snapPoint(e);
88
if( (graphicView->toGui(v) - graphicView->toGui(vertex)).squared()< 1. ){
89
//do not add the same mouse position
92
RS_Entity* ent = polyline->addVertex(v);
93
if (polyline->count() > 0){
94
preview->addCloneOf(ent);
100
RS_DEBUG->print("RS_ActionDrawLineFree::mouseMoveEvent():"
101
" line added: %d", ent->getId());
107
void RS_ActionDrawLineFree::mousePressEvent(QMouseEvent* e) {
108
if (e->button()==Qt::LeftButton) {
113
vertex = snapPoint(e);
114
polyline = new RS_Polyline(container,
115
RS_PolylineData(vertex, vertex, 0));
116
polyline->setLayerToActive();
117
polyline->setPenToActive();
124
//else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton && !vertex.valid) {
130
void RS_ActionDrawLineFree::mouseReleaseEvent(QMouseEvent* e) {
131
if (e->button()==Qt::LeftButton) {
132
if(getStatus()==Dragging){
133
vertex = RS_Vector(false);
136
} else if (e->button()==Qt::RightButton) {
137
if (polyline!=NULL) {
147
void RS_ActionDrawLineFree::updateMouseButtonHints() {
148
switch (getStatus()) {
151
RS_DIALOGFACTORY->updateMouseWidget(
152
tr("Click and drag to draw a line"), tr("Cancel"));
155
RS_DIALOGFACTORY->updateMouseWidget("", "");
162
void RS_ActionDrawLineFree::updateMouseCursor() {
163
graphicView->setMouseCursor(RS2::CadCursor);
168
//void RS_ActionDrawLineFree::updateToolBar() {
169
// if (RS_DIALOGFACTORY!=NULL) {
170
// if (isFinished()) {
171
// RS_DIALOGFACTORY->resetToolBar();