1 /****************************************************************************
2 ** $Id: rs_actiondrawlinerectangle.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_actiondrawlinerectangle.h"
28 #include "rs_snapper.h"
32 RS_ActionDrawLineRectangle::RS_ActionDrawLineRectangle(
33 RS_EntityContainer& container,
34 RS_GraphicView& graphicView)
35 :RS_PreviewActionInterface("Draw rectangles",
36 container, graphicView) {
42 RS_ActionDrawLineRectangle::~RS_ActionDrawLineRectangle() {}
44 QAction* RS_ActionDrawLineRectangle::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
46 QAction * action = new QAction(tr("&Rectangle"), 0);
47 // QAction* action = new QAction(tr("Rectangle"), tr("&Rectangle"),
48 // QKeySequence(), NULL);
49 action->setStatusTip(tr("Draw rectangles"));
54 void RS_ActionDrawLineRectangle::reset() {
55 for (int i=0; i<4; ++i) {
56 data[i] = RS_LineData(Vector(false),
63 void RS_ActionDrawLineRectangle::init(int status) {
64 RS_PreviewActionInterface::init(status);
71 void RS_ActionDrawLineRectangle::trigger() {
72 RS_PreviewActionInterface::trigger();
77 // create and add rectangle:
78 for (int i=0; i<4; ++i) {
79 line[i] = new RS_Line(container,
81 line[i]->setLayerToActive();
82 line[i]->setPenToActive();
83 container->addEntity(line[i]);
88 document->startUndoCycle();
89 for (int i=0; i<4; ++i) {
90 document->addUndoable(line[i]);
92 document->endUndoCycle();
97 graphicView->moveRelativeZero(Vector(0.0,0.0));
98 for (int i=0; i<4; ++i) {
99 graphicView->drawEntity(line[i]);
100 RS_DEBUG->print("RS_ActionDrawLineRectangle::trigger():"
104 graphicView->moveRelativeZero(corner2);
109 void RS_ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent* e) {
110 RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent begin");
112 Vector mouse = snapPoint(e);
113 if (getStatus()==SetCorner2 && corner1.valid) {
120 for (int i=0; i<4; ++i) {
121 preview->addEntity(new RS_Line(preview, data[i]));
126 RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent end");
130 void RS_ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent* e) {
131 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
132 RS_CoordinateEvent ce(snapPoint(e));
133 coordinateEvent(&ce);
134 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
143 void RS_ActionDrawLineRectangle::preparePreview() {
144 data[0] = RS_LineData(corner1, Vector(corner2.x, corner1.y));
145 data[1] = RS_LineData(Vector(corner2.x, corner1.y), corner2);
146 data[2] = RS_LineData(corner2, Vector(corner1.x, corner2.y));
147 data[3] = RS_LineData(Vector(corner1.x, corner2.y), corner1);
151 void RS_ActionDrawLineRectangle::coordinateEvent(RS_CoordinateEvent* e) {
156 Vector mouse = e->getCoordinate();
158 switch (getStatus()) {
161 graphicView->moveRelativeZero(mouse);
162 setStatus(SetCorner2);
168 setStatus(SetCorner1);
178 void RS_ActionDrawLineRectangle::commandEvent(RS_CommandEvent* e) {
179 QString c = e->getCommand().toLower();
181 if (checkCommand("help", c)) {
182 if (RS_DIALOGFACTORY!=NULL) {
183 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
184 + getAvailableCommands().join(", "));
192 QStringList RS_ActionDrawLineRectangle::getAvailableCommands() {
198 void RS_ActionDrawLineRectangle::updateMouseButtonHints() {
199 if (RS_DIALOGFACTORY!=NULL) {
200 switch (getStatus()) {
202 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
206 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
210 RS_DIALOGFACTORY->updateMouseWidget("", "");
217 void RS_ActionDrawLineRectangle::updateMouseCursor() {
218 graphicView->setMouseCursor(RS2::CadCursor);
222 void RS_ActionDrawLineRectangle::updateToolBar() {
223 if (RS_DIALOGFACTORY!=NULL) {
225 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
227 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);