1 /****************************************************************************
2 ** $Id: rs_actiondefault.cpp 1161 2004-12-09 23:10:09Z 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_actiondefault.h"
30 #include "rs_modification.h"
31 #include "rs_snapper.h"
32 #include "rs_selection.h"
39 RS_ActionDefault::RS_ActionDefault(RS_EntityContainer& container,
40 RS_GraphicView& graphicView)
41 : RS_PreviewActionInterface("Default",
42 container, graphicView) {
44 RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault");
45 RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault: OK");
50 RS_ActionDefault::~RS_ActionDefault() {
55 QAction* RS_ActionDefault::createGUIAction(RS2::ActionType /*type*/,
56 QObject* /*parent*/) {
62 void RS_ActionDefault::init(int status) {
63 RS_DEBUG->print("RS_ActionDefault::init");
65 RS_PreviewActionInterface::init(status);
66 v1 = v2 = Vector(false);
67 snapMode = RS2::SnapFree;
68 snapRes = RS2::RestrictNothing;
69 restrBak = RS2::RestrictNothing;
70 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
72 RS_DEBUG->print("RS_ActionDefault::init: OK");
77 void RS_ActionDefault::trigger() {
78 RS_PreviewActionInterface::trigger();
82 void RS_ActionDefault::keyPressEvent(QKeyEvent* e) {
83 if (e->key()==Qt::Key_Shift) {
85 setSnapRestriction(RS2::RestrictOrthogonal);
89 void RS_ActionDefault::keyReleaseEvent(QKeyEvent* e) {
90 if (e->key()==Qt::Key_Shift) {
91 setSnapRestriction(restrBak);
96 void RS_ActionDefault::mouseMoveEvent(QMouseEvent* e) {
98 Vector mouse = graphicView->toGraph(Vector(e->x(), e->y()));
99 Vector relMouse = mouse - graphicView->getRelativeZero();
101 RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
103 switch (getStatus()) {
105 //v2 = graphicView->toGraph(e->x(), e->y());
108 if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
109 // look for reference points to drag:
111 Vector ref = container->getNearestSelectedRef(v1, &dist);
112 if (ref.valid==true && graphicView->toGuiDX(dist)<8) {
113 RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
114 "moving reference point");
115 setStatus(MovingRef);
117 graphicView->moveRelativeZero(v1);
120 // test for an entity to drag:
121 RS_Entity* en = catchEntity(v1);
122 if (en!=NULL && en->isSelected()) {
123 RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
126 v1 = en->getNearestRef(v1);
127 graphicView->moveRelativeZero(v1);
130 // no entity found. start area selection:
132 setStatus(SetCorner2);
143 preview->addSelectionFrom(*container);
144 preview->moveRef(v1, v2-v1);
153 preview->addSelectionFrom(*container);
154 preview->move(v2-v1);
167 preview->addEntity(new RS_Line(preview,
168 RS_LineData(Vector(v1.x, v1.y),
169 Vector(v2.x, v1.y))));
170 preview->addEntity(new RS_Line(preview,
171 RS_LineData(Vector(v2.x, v1.y),
172 Vector(v2.x, v2.y))));
173 preview->addEntity(new RS_Line(preview,
174 RS_LineData(Vector(v2.x, v2.y),
175 Vector(v1.x, v2.y))));
176 preview->addEntity(new RS_Line(preview,
177 RS_LineData(Vector(v1.x, v2.y),
178 Vector(v1.x, v1.y))));
189 void RS_ActionDefault::mousePressEvent(QMouseEvent* e) {
190 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
191 switch (getStatus()) {
193 v1 = graphicView->toGraph(e->x(), e->y());
202 RS_Modification m(*container, graphicView);
205 data.useCurrentLayer = false;
206 data.useCurrentAttributes = false;
210 RS_DIALOGFACTORY->updateSelectionWidget(
211 container->countSelected());
212 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
221 RS_Modification m(*container, graphicView);
226 //container->moveSelectedRef(v1, v2-v2);
228 RS_DIALOGFACTORY->updateSelectionWidget(
229 container->countSelected());
230 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
242 void RS_ActionDefault::mouseReleaseEvent(QMouseEvent* e) {
243 RS_DEBUG->print("RS_ActionDefault::mouseReleaseEvent()");
245 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
246 v2 = graphicView->toGraph(e->x(), e->y());
247 switch (getStatus()) {
249 // select single entity:
250 RS_Entity* en = catchEntity(e);
257 RS_Selection s(*container, graphicView);
260 RS_DIALOGFACTORY->updateSelectionWidget(
261 container->countSelected());
264 #if QT_VERSION>=0x030000
270 setStatus(SetCorner2);
277 v2 = graphicView->toGraph(e->x(), e->y());
280 //if (graphicView->toGuiDX(v1.distanceTo(v2))>20) {
285 bool cross = (v2.y>v1.y);
286 RS_Selection s(*container, graphicView);
287 s.selectWindow(v1, v2, true, cross);
289 RS_DIALOGFACTORY->updateSelectionWidget(
290 container->countSelected());
293 #if QT_VERSION>=0x030000
306 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
307 switch (getStatus()) {
315 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
316 #if QT_VERSION>=0x030000
324 RS_DIALOGFACTORY->requestPreviousMenu();
325 #if QT_VERSION>=0x030000
336 void RS_ActionDefault::commandEvent(RS_CommandEvent* e) {
337 QString c = e->getCommand().toLower();
339 // if the current action can't deal with the command,
340 // it might be intended to launch a new command
341 //if (!e.isAccepted()) {
342 // command for new action:
343 //RS2::ActionType type = RS_COMMANDS->cmdToAction(c);
344 //if (type!=RS2::ActionNone) {
345 //graphicView->setCurrentAction(type);
353 QStringList RS_ActionDefault::getAvailableCommands() {
357 //cmd += "rectangle";
363 void RS_ActionDefault::updateMouseButtonHints() {
364 switch (getStatus()) {
366 RS_DIALOGFACTORY->updateMouseWidget("", "");
369 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"),
373 RS_DIALOGFACTORY->updateMouseWidget("", "");
380 void RS_ActionDefault::updateMouseCursor() {
381 switch (getStatus()) {
383 graphicView->setMouseCursor(RS2::ArrowCursor);
387 graphicView->setMouseCursor(RS2::SelectCursor);
396 void RS_ActionDefault::updateToolBar() {
397 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
398 switch (getStatus()) {
400 // would switch back to main in edit / measure / .. modes
401 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
405 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);