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_actiondrawlinehorvert.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
35
RS_ActionDrawLineHorVert::RS_ActionDrawLineHorVert(
36
RS_EntityContainer& container,
37
RS_GraphicView& graphicView)
38
:RS_PreviewActionInterface("Draw horizontal/vertical lines",
39
container, graphicView) {
41
RS_DEBUG->print("RS_ActionDrawLineHorVert::constructor");
46
RS_ActionDrawLineHorVert::~RS_ActionDrawLineHorVert() {}
49
QAction* RS_ActionDrawLineHorVert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
50
/* RVT_PORT QAction* action = new QAction(tr("hor./vert. line"),
51
tr("H&orizontal / Vertical"),
52
QKeySequence(), NULL); */
53
QAction* action = new QAction(tr("Vertical"), NULL);
54
//action->zetStatusTip(tr("Draw horizontal/vertical lines"));
58
void RS_ActionDrawLineHorVert::reset() {
59
data = RS_LineData(RS_Vector(false),
65
void RS_ActionDrawLineHorVert::init(int status) {
66
RS_PreviewActionInterface::init(status);
69
RS_DEBUG->print("RS_ActionDrawLineHorVert::init");
74
void RS_ActionDrawLineHorVert::trigger() {
75
RS_PreviewActionInterface::trigger();
77
RS_Line* line = new RS_Line(container, data);
78
line->setLayerToActive();
79
line->setPenToActive();
80
container->addEntity(line);
84
document->startUndoCycle();
85
document->addUndoable(line);
86
document->endUndoCycle();
89
graphicView->redraw(RS2::RedrawDrawing);
90
graphicView->moveRelativeZero(line->getMiddlePoint());
91
RS_DEBUG->print("RS_ActionDrawLineHorVert::trigger():"
92
" line added: %d", line->getId());
98
void RS_ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent* e) {
99
RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent begin");
101
RS_Vector mouse = snapPoint(e);
102
if (getStatus()==SetEndpoint && p1.valid) {
103
RS_Vector p2x = RS_Vector(mouse.x, p1.y);
104
RS_Vector p2y = RS_Vector(p1.x, mouse.y);
105
if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x))
110
data = RS_LineData(p1, p2);
111
preview->addEntity(new RS_Line(preview, data));
115
RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent end");
120
void RS_ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent* e) {
121
if (e->button()==Qt::LeftButton) {
122
RS_Vector mouse = snapPoint(e);
124
switch (getStatus()) {
127
setStatus(SetEndpoint);
133
setStatus(SetStartpoint);
139
} else if (e->button()==Qt::RightButton) {
147
void RS_ActionDrawLineHorVert::updateMouseButtonHints() {
148
switch (getStatus()) {
150
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"),
154
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"),
158
RS_DIALOGFACTORY->updateMouseWidget("", "");
164
void RS_ActionDrawLineHorVert::updateMouseCursor() {
165
graphicView->setMouseCursor(RS2::CadCursor);
169
void RS_ActionDrawLineHorVert::updateToolBar() {
170
if (RS_DIALOGFACTORY!=NULL) {
172
RS_DIALOGFACTORY->resetToolBar();