1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
14
** This program is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
19
** You should have received a copy of the GNU General Public License
20
** along with this program; if not, write to the Free Software
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
27
#include "rs_actiondefault.h"
29
#include "rs_dialogfactory.h"
30
#include "rs_graphicview.h"
31
#include "rs_commandevent.h"
32
#include "rs_modification.h"
33
#include "rs_selection.h"
34
#include "rs_overlaybox.h"
41
RS_ActionDefault::RS_ActionDefault(RS_EntityContainer& container,
42
RS_GraphicView& graphicView)
43
: RS_PreviewActionInterface("Default",
44
container, graphicView),
47
restrBak(RS2::RestrictNothing)
50
RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault");
51
RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault: OK");
56
RS_ActionDefault::~RS_ActionDefault() {
61
QAction* RS_ActionDefault::createGUIAction(RS2::ActionType /*type*/,
62
QObject* /*parent*/) {
68
void RS_ActionDefault::init(int status) {
69
RS_DEBUG->print("RS_ActionDefault::init");
74
RS_PreviewActionInterface::init(status);
75
v1 = v2 = RS_Vector(false);
77
// snapMode.restriction = RS2::RestrictNothing;
78
// restrBak = RS2::RestrictNothing;
79
// RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
81
RS_DEBUG->print("RS_ActionDefault::init: OK");
86
void RS_ActionDefault::trigger() {
87
RS_PreviewActionInterface::trigger();
91
void RS_ActionDefault::keyPressEvent(QKeyEvent* e) {
92
// std::cout<<"RS_ActionDefault::keyPressEvent(): begin"<<std::endl;
95
restrBak = snapMode.restriction;
96
setSnapRestriction(RS2::RestrictOrthogonal);
98
//cleanup default action, issue#285
100
// std::cout<<"RS_ActionDefault::keyPressEvent(): Qt::Key_Escape"<<std::endl;
111
void RS_ActionDefault::keyReleaseEvent(QKeyEvent* e) {
112
if (e->key()==Qt::Key_Shift) {
113
setSnapRestriction(restrBak);
119
void RS_ActionDefault::mouseMoveEvent(QMouseEvent* e) {
121
RS_Vector mouse = graphicView->toGraph(RS_Vector(e->x(), e->y()));
122
RS_Vector relMouse = mouse - graphicView->getRelativeZero();
124
RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse);
126
switch (getStatus()) {
131
//v2 = graphicView->toGraph(e->x(), e->y());
134
if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
135
// look for reference points to drag:
137
RS_Vector ref = container->getNearestSelectedRef(v1, &dist);
138
if (ref.valid==true && graphicView->toGuiDX(dist)<8) {
139
RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
140
"moving reference point");
141
setStatus(MovingRef);
143
graphicView->moveRelativeZero(v1);
146
// test for an entity to drag:
147
RS_Entity* en = catchEntity(v1);
148
if (en!=NULL && en->isSelected()) {
149
RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: "
152
RS_Vector vp= en->getNearestRef(v1);
155
//graphicView->moveRelativeZero(v1);
158
// no entity found. start area selection:
160
setStatus(SetCorner2);
170
preview->addSelectionFrom(*container);
171
preview->moveRef(v1, v2-v1);
179
preview->addSelectionFrom(*container);
180
preview->move(v2-v1);
190
RS_OverlayBox* ob=new RS_OverlayBox(preview, RS_OverlayBoxData(v1, v2));
191
preview->addEntity(ob);
203
void RS_ActionDefault::mousePressEvent(QMouseEvent* e) {
204
if (e->button()==Qt::LeftButton) {
205
switch (getStatus()) {
207
v1 = graphicView->toGraph(e->x(), e->y());
214
RS_Modification m(*container, graphicView);
217
data.useCurrentLayer = false;
218
data.useCurrentAttributes = false;
222
RS_DIALOGFACTORY->updateSelectionWidget(
223
container->countSelected(),container->totalSelectedLength());
224
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
232
RS_Modification m(*container, graphicView);
237
//container->moveSelectedRef(v1, v2-v2);
239
RS_DIALOGFACTORY->updateSelectionWidget(
240
container->countSelected(),container->totalSelectedLength());
241
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
248
} else if (e->button()==Qt::RightButton) {
257
void RS_ActionDefault::mouseReleaseEvent(QMouseEvent* e) {
258
RS_DEBUG->print("RS_ActionDefault::mouseReleaseEvent()");
260
if (e->button()==Qt::LeftButton) {
261
v2 = graphicView->toGraph(e->x(), e->y());
262
switch (getStatus()) {
264
// select single entity:
265
RS_Entity* en = catchEntity(e);
270
RS_Selection s(*container, graphicView);
273
RS_DIALOGFACTORY->updateSelectionWidget(
274
container->countSelected(),container->totalSelectedLength());
280
setStatus(SetCorner2);
287
v2 = graphicView->toGraph(e->x(), e->y());
290
//if (graphicView->toGuiDX(v1.distanceTo(v2))>20) {
293
bool cross = (v1.x>v2.x);
294
RS_Selection s(*container, graphicView);
295
s.selectWindow(v1, v2, true, cross);
297
RS_DIALOGFACTORY->updateSelectionWidget(
298
container->countSelected(),container->totalSelectedLength());
311
} else if (e->button()==Qt::RightButton) {
318
void RS_ActionDefault::commandEvent(RS_CommandEvent* e) {
319
QString c = e->getCommand().toLower();
321
// if the current action can't deal with the command,
322
// it might be intended to launch a new command
323
//if (!e.isAccepted()) {
324
// command for new action:
325
//RS2::ActionType type = RS_COMMANDS->cmdToAction(c);
326
//if (type!=RS2::ActionNone) {
327
//graphicView->setCurrentAction(type);
335
QStringList RS_ActionDefault::getAvailableCommands() {
339
//cmd += "rectangle";
345
void RS_ActionDefault::updateMouseButtonHints() {
346
switch (getStatus()) {
348
RS_DIALOGFACTORY->updateMouseWidget("", "");
351
RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"),
355
RS_DIALOGFACTORY->updateMouseWidget("", "");
360
void RS_ActionDefault::updateMouseCursor() {
361
switch (getStatus()) {
363
graphicView->setMouseCursor(RS2::ArrowCursor);
367
graphicView->setMouseCursor(RS2::SelectCursor);
376
//void RS_ActionDefault::updateToolBar() {
377
// //not needed any more
379
// //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
380
// switch (getStatus()) {
382
// // would switch back to main in edit / measure / .. modes
383
// //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
387
// RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);