]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawlinehorvert.cpp
d8e41e1edd028713048e47fcc47af777ee866699
[architektonas] / src / actions / rs_actiondrawlinehorvert.cpp
1 /****************************************************************************
2 ** $Id: rs_actiondrawlinehorvert.cpp 1134 2004-07-13 23:26:13Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
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.
12 **
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.
16 **
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.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actiondrawlinehorvert.h"
28 #include "rs_snapper.h"
29
30
31
32 RS_ActionDrawLineHorVert::RS_ActionDrawLineHorVert(
33     RS_EntityContainer& container,
34     RS_GraphicView& graphicView)
35         :RS_PreviewActionInterface("Draw horizontal/vertical lines",
36                            container, graphicView) {
37     reset();
38     RS_DEBUG->print("RS_ActionDrawLineHorVert::constructor");
39 }
40
41
42
43 RS_ActionDrawLineHorVert::~RS_ActionDrawLineHorVert() {}
44
45
46 QAction* RS_ActionDrawLineHorVert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
47 {
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"));
53         return action;
54 }
55
56 void RS_ActionDrawLineHorVert::reset() {
57     data = RS_LineData(Vector(false),
58                        Vector(false));
59 }
60
61
62
63 void RS_ActionDrawLineHorVert::init(int status) {
64     RS_PreviewActionInterface::init(status);
65
66     reset();
67     RS_DEBUG->print("RS_ActionDrawLineHorVert::init");
68 }
69
70
71
72 void RS_ActionDrawLineHorVert::trigger() {
73     RS_PreviewActionInterface::trigger();
74
75     RS_Line* line = new RS_Line(container, data);
76     line->setLayerToActive();
77     line->setPenToActive();
78     container->addEntity(line);
79
80     // upd. undo list:
81     if (document!=NULL) {
82         document->startUndoCycle();
83         document->addUndoable(line);
84         document->endUndoCycle();
85     }
86
87     deleteSnapper();
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());
93
94 }
95
96
97
98 void RS_ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent* e) {
99     RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent begin");
100
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))
106             p2 = p2x;
107         else
108             p2 = p2y;
109         deletePreview();
110         clearPreview();
111         data = RS_LineData(p1, p2);
112         preview->addEntity(new RS_Line(preview, data));
113         drawPreview();
114     }
115
116     RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent end");
117 }
118
119
120
121 void RS_ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent* e) {
122     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
123         Vector mouse = snapPoint(e);
124
125         switch (getStatus()) {
126         case SetStartpoint:
127             p1 = mouse;
128             setStatus(SetEndpoint);
129             break;
130
131         case SetEndpoint:
132             p2 = mouse;
133             trigger();
134             setStatus(SetStartpoint);
135             break;
136
137         default:
138             break;
139         }
140     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
141         deletePreview();
142         deleteSnapper();
143         init(getStatus()-1);
144     }
145 }
146
147
148
149 void RS_ActionDrawLineHorVert::updateMouseButtonHints() {
150     switch (getStatus()) {
151     case SetStartpoint:
152         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"),
153                                             tr("Cancel"));
154         break;
155     case SetEndpoint:
156         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"),
157                                             tr("Back"));
158         break;
159     default:
160         RS_DIALOGFACTORY->updateMouseWidget("", "");
161         break;
162     }
163 }
164
165
166 void RS_ActionDrawLineHorVert::updateMouseCursor() {
167     graphicView->setMouseCursor(RS2::CadCursor);
168 }
169
170
171 void RS_ActionDrawLineHorVert::updateToolBar() {
172     if (!isFinished()) {
173         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
174     } else {
175         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
176     }
177 }
178
179 // EOF