1 /****************************************************************************
2 ** $Id: rs_actiondrawlineparallelthrough.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_actiondrawlineparallelthrough.h"
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
34 RS_ActionDrawLineParallelThrough::RS_ActionDrawLineParallelThrough(
35 RS_EntityContainer& container,
36 RS_GraphicView& graphicView)
37 :RS_PreviewActionInterface("Draw Parallels", container, graphicView) {
43 coord = Vector(false);
47 QAction* RS_ActionDrawLineParallelThrough::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
49 QAction * action = new QAction(tr("Par&allel through point"), 0);
50 // QAction* action = new QAction(tr("Parallel through point"),
51 // tr("Par&allel through point"),
52 // QKeySequence(), NULL);
53 action->setStatusTip(tr("Draw parallel through a given point"));
57 void RS_ActionDrawLineParallelThrough::trigger() {
58 RS_PreviewActionInterface::trigger();
62 RS_Creation creation(container, graphicView);
63 RS_Entity* e = creation.createParallelThrough(coord,
68 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::trigger:"
69 " No parallels added\n");
76 void RS_ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent* e) {
77 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent begin");
80 switch (getStatus()) {
82 entity = catchEntity(e, RS2::ResolveAll);
86 RS_Creation creation(preview, NULL, false);
87 creation.createParallelThrough(coord,
97 //Vector(graphicView->toGraphX(e->x()),
98 // graphicView->toGraphY(e->y()));
102 RS_Creation creation(preview, NULL, false);
103 creation.createParallelThrough(coord,
115 RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent end");
120 void RS_ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent* e) {
121 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
122 switch (getStatus()) {
124 entity = catchEntity(e, RS2::ResolveAll);
126 entity->setHighlighted(true);
127 graphicView->drawEntity(entity);
132 RS_CoordinateEvent ce(snapPoint(e));
133 coordinateEvent(&ce);
139 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
143 entity->setHighlighted(false);
144 graphicView->drawEntity(entity);
153 void RS_ActionDrawLineParallelThrough::coordinateEvent(RS_CoordinateEvent* e) {
158 Vector mouse = e->getCoordinate();
160 switch (getStatus()) {
173 void RS_ActionDrawLineParallelThrough::updateMouseButtonHints() {
174 switch (getStatus()) {
176 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel"));
180 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"),
185 RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
189 RS_DIALOGFACTORY->updateMouseWidget("", "");
196 void RS_ActionDrawLineParallelThrough::showOptions() {
197 RS_ActionInterface::showOptions();
199 RS_DIALOGFACTORY->requestOptions(this, true);
200 updateMouseButtonHints();
205 void RS_ActionDrawLineParallelThrough::hideOptions() {
206 RS_ActionInterface::hideOptions();
208 RS_DIALOGFACTORY->requestOptions(this, false);
213 void RS_ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent* e) {
214 QString c = e->getCommand().toLower();
216 if (checkCommand("help", c)) {
217 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
218 + getAvailableCommands().join(", "));
222 switch (getStatus()) {
225 if (checkCommand("number", c)) {
229 lastStatus = (Status)getStatus();
230 setStatus(SetNumber);
237 int n = c.toInt(&ok);
242 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
246 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
248 RS_DIALOGFACTORY->requestOptions(this, true, true);
249 setStatus(lastStatus);
260 QStringList RS_ActionDrawLineParallelThrough::getAvailableCommands() {
263 switch (getStatus()) {
265 cmd += command("number");
276 void RS_ActionDrawLineParallelThrough::updateMouseCursor() {
277 graphicView->setMouseCursor(RS2::CadCursor);
282 void RS_ActionDrawLineParallelThrough::updateToolBar() {
283 if (getStatus()==SetPos && !isFinished()) {
284 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
286 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);