1 // actiondrawlinerectangle.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/04/2010 Added this text. :-)
17 #include "actiondrawlinerectangle.h"
19 #include "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
25 ActionDrawLineRectangle::ActionDrawLineRectangle(
26 EntityContainer & container, GraphicView & graphicView):
27 ActionInterface("Draw rectangles", container, graphicView)
32 ActionDrawLineRectangle::~ActionDrawLineRectangle()
36 void ActionDrawLineRectangle::reset()
38 for(int i=0; i<4; i++)
39 data[i] = LineData(Vector(false), Vector(false));
42 void ActionDrawLineRectangle::init(int status)
44 ActionInterface::init(status);
48 void ActionDrawLineRectangle::trigger()
50 ActionInterface::trigger();
55 // create and add rectangle:
56 for(int i=0; i<4; i++)
58 line[i] = new Line(container, data[i]);
59 line[i]->setLayerToActive();
60 line[i]->setPenToActive();
61 container->addEntity(line[i]);
67 document->startUndoCycle();
69 for(int i=0; i<4; i++)
70 document->addUndoable(line[i]);
72 document->endUndoCycle();
77 graphicView->moveRelativeZero(Vector(0.0, 0.0));
79 for(int i=0; i<4; i++)
81 graphicView->drawEntity(line[i]);
82 DEBUG->print("ActionDrawLineRectangle::trigger(): line added: %d", line[i]->getId());
85 graphicView->moveRelativeZero(corner2);
86 graphicView->redraw();
89 void ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent * e)
91 DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent begin");
93 Vector mouse = snapPoint(e);
95 if (getStatus() == SetCorner2 && corner1.valid)
102 // for(int i=0; i<4; i++)
103 // preview->addEntity(new Line(preview, data[i]));
107 graphicView->preview.clear();
109 for(int i=0; i<4; i++)
110 graphicView->preview.addEntity(new Line(&(graphicView->preview), data[i]));
113 graphicView->redraw();
114 DEBUG->print("ActionDrawLineRectangle::mouseMoveEvent end");
117 void ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent * e)
119 if (e->button() == Qt::LeftButton)
121 // Vector ce(snapPoint(e));
122 Vector ce(graphicView->SnapPoint(e));
123 coordinateEvent(&ce);
125 else if (e->button() == Qt::RightButton)
129 init(getStatus() - 1);
132 graphicView->preview.clear(); // Remove entities from container
133 graphicView->redraw();
136 void ActionDrawLineRectangle::preparePreview()
138 data[0] = LineData(corner1, Vector(corner2.x, corner1.y));
139 data[1] = LineData(Vector(corner2.x, corner1.y), corner2);
140 data[2] = LineData(corner2, Vector(corner1.x, corner2.y));
141 data[3] = LineData(Vector(corner1.x, corner2.y), corner1);
144 void ActionDrawLineRectangle::coordinateEvent(Vector * e)
155 graphicView->moveRelativeZero(mouse);
156 setStatus(SetCorner2);
162 setStatus(SetCorner1);
170 void ActionDrawLineRectangle::commandEvent(CommandEvent * e)
172 QString c = e->getCommand().toLower();
174 if (checkCommand("help", c))
177 DIALOGFACTORY->commandMessage(msgAvailableCommands()
178 + getAvailableCommands().join(", "));
183 QStringList ActionDrawLineRectangle::getAvailableCommands()
189 void ActionDrawLineRectangle::updateMouseButtonHints()
196 DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), tr("Cancel"));
200 DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), tr("Back"));
204 DIALOGFACTORY->updateMouseWidget("", "");
210 void ActionDrawLineRectangle::updateMouseCursor()
212 graphicView->setMouseCursor(RS2::CadCursor);
215 void ActionDrawLineRectangle::updateToolBar()
220 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
222 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);