1 /****************************************************************************
2 ** $Id: rs_actiondrawlinepolygon2.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_actiondrawlinepolygon2.h"
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
34 RS_ActionDrawLinePolygon2::RS_ActionDrawLinePolygon2(
35 RS_EntityContainer& container,
36 RS_GraphicView& graphicView)
37 :RS_PreviewActionInterface("Draw Polygons", container, graphicView) {
39 corner1 = Vector(false);
40 corner2 = Vector(false);
45 QAction* RS_ActionDrawLinePolygon2::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
47 QAction * action = new QAction(tr("Polygo&n (Cor,Cor)"), 0);
48 // QAction* action = new QAction(tr("Polygon"), tr("Polygo&n (Cor,Cor)"),
49 // QKeySequence(), NULL);
50 action->setStatusTip(tr("Draw polygon with two corners"));
55 void RS_ActionDrawLinePolygon2::trigger() {
56 RS_PreviewActionInterface::trigger();
62 RS_Creation creation(container, graphicView);
63 bool ok = creation.createPolygon2(corner1, corner2, number);
66 RS_DEBUG->print("RS_ActionDrawLinePolygon2::trigger:"
67 " No polygon added\n");
73 void RS_ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent* e) {
74 RS_DEBUG->print("RS_ActionDrawLinePolygon2::mouseMoveEvent begin");
76 Vector mouse = snapPoint(e);
78 switch (getStatus()) {
88 RS_Creation creation(preview, NULL, false);
89 creation.createPolygon2(corner1, corner2, number);
102 void RS_ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent* e) {
103 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
104 RS_CoordinateEvent ce(snapPoint(e));
105 coordinateEvent(&ce);
106 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
116 void RS_ActionDrawLinePolygon2::coordinateEvent(RS_CoordinateEvent* e) {
121 Vector mouse = e->getCoordinate();
123 switch (getStatus()) {
126 setStatus(SetCorner2);
127 graphicView->moveRelativeZero(mouse);
142 void RS_ActionDrawLinePolygon2::updateMouseButtonHints() {
143 if (RS_DIALOGFACTORY!=NULL) {
144 switch (getStatus()) {
146 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
151 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
156 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
160 RS_DIALOGFACTORY->updateMouseWidget("", "");
168 void RS_ActionDrawLinePolygon2::showOptions() {
169 RS_ActionInterface::showOptions();
171 if (RS_DIALOGFACTORY!=NULL) {
172 RS_DIALOGFACTORY->requestOptions(this, true);
178 void RS_ActionDrawLinePolygon2::hideOptions() {
179 RS_ActionInterface::hideOptions();
181 if (RS_DIALOGFACTORY!=NULL) {
182 RS_DIALOGFACTORY->requestOptions(this, false);
188 void RS_ActionDrawLinePolygon2::commandEvent(RS_CommandEvent* e) {
189 QString c = e->getCommand().toLower();
191 if (checkCommand("help", c)) {
192 if (RS_DIALOGFACTORY!=NULL) {
193 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
194 + getAvailableCommands().join(", "));
199 switch (getStatus()) {
202 if (checkCommand("number", c)) {
206 lastStatus = (Status)getStatus();
207 setStatus(SetNumber);
213 int n = c.toInt(&ok);
215 if (n>0 && n<10000) {
218 if (RS_DIALOGFACTORY!=NULL) {
219 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
224 if (RS_DIALOGFACTORY!=NULL) {
225 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression."));
228 if (RS_DIALOGFACTORY!=NULL) {
229 RS_DIALOGFACTORY->requestOptions(this, true, true);
231 setStatus(lastStatus);
242 QStringList RS_ActionDrawLinePolygon2::getAvailableCommands() {
245 switch (getStatus()) {
248 cmd += command("number");
259 void RS_ActionDrawLinePolygon2::updateMouseCursor() {
260 graphicView->setMouseCursor(RS2::CadCursor);
265 void RS_ActionDrawLinePolygon2::updateToolBar() {
266 if (RS_DIALOGFACTORY!=NULL) {
268 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
270 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);