1 /****************************************************************************
2 ** $Id: rs_actiondrawlinehorvert.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_actiondrawlinehorvert.h"
28 #include "rs_snapper.h"
32 RS_ActionDrawLineHorVert::RS_ActionDrawLineHorVert(
33 RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Draw horizontal/vertical lines",
36 container, graphicView) {
38 RS_DEBUG->print("RS_ActionDrawLineHorVert::constructor");
43 RS_ActionDrawLineHorVert::~RS_ActionDrawLineHorVert() {}
46 QAction* RS_ActionDrawLineHorVert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
48 QAction * action = new QAction(tr("H&orizontal / Vertical"), 0);
49 // QAction* action = new QAction(tr("hor./vert. line"),
50 // tr("H&orizontal / Vertical"),
51 // QKeySequence(), NULL);
52 action->setStatusTip(tr("Draw horizontal/vertical lines"));
56 void RS_ActionDrawLineHorVert::reset() {
57 data = RS_LineData(Vector(false),
63 void RS_ActionDrawLineHorVert::init(int status) {
64 RS_PreviewActionInterface::init(status);
67 RS_DEBUG->print("RS_ActionDrawLineHorVert::init");
72 void RS_ActionDrawLineHorVert::trigger() {
73 RS_PreviewActionInterface::trigger();
75 RS_Line* line = new RS_Line(container, data);
76 line->setLayerToActive();
77 line->setPenToActive();
78 container->addEntity(line);
82 document->startUndoCycle();
83 document->addUndoable(line);
84 document->endUndoCycle();
88 graphicView->moveRelativeZero(Vector(0.0,0.0));
89 graphicView->drawEntity(line);
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 Vector mouse = snapPoint(e);
102 if (getStatus()==SetEndpoint && p1.valid) {
103 Vector p2x = Vector(mouse.x, p1.y);
104 Vector p2y = Vector(p1.x, mouse.y);
105 if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x))
111 data = RS_LineData(p1, p2);
112 preview->addEntity(new RS_Line(preview, data));
116 RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent end");
121 void RS_ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent* e) {
122 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
123 Vector mouse = snapPoint(e);
125 switch (getStatus()) {
128 setStatus(SetEndpoint);
134 setStatus(SetStartpoint);
140 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
149 void RS_ActionDrawLineHorVert::updateMouseButtonHints() {
150 switch (getStatus()) {
152 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"),
156 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"),
160 RS_DIALOGFACTORY->updateMouseWidget("", "");
166 void RS_ActionDrawLineHorVert::updateMouseCursor() {
167 graphicView->setMouseCursor(RS2::CadCursor);
171 void RS_ActionDrawLineHorVert::updateToolBar() {
173 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
175 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);