]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifydeletequick.cpp
Initial import
[architektonas] / src / actions / rs_actionmodifydeletequick.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifydeletequick.cpp 1144 2004-08-18 17:07:54Z 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_actionmodifydeletequick.h"
28
29 #include "rs_actionselectsingle.h"
30 #include "rs_snapper.h"
31 #include "rs_point.h"
32
33 RS_ActionModifyDeleteQuick::RS_ActionModifyDeleteQuick(
34         RS_EntityContainer& container, RS_GraphicView& graphicView):
35         RS_ActionInterface("Quick Delete Entities", container, graphicView)
36 {
37     en = NULL;
38 }
39
40 QAction * RS_ActionModifyDeleteQuick::createGUIAction(RS2::ActionType /*type*/, QObject * parent)
41 {
42         QAction * action = new QAction(tr("&Delete selected"), parent);
43 #ifdef __APPLE__
44         action->setShortcut(Qt::Key_Backspace);
45 #else
46         action->setShortcut(Qt::Key_Delete);
47 #endif
48 //      QAction* action = new QAction(tr("Delete selected"),
49 //                                              tr("&Delete selected"),
50 //                                                      s, parent);
51         action->setStatusTip(tr("Delete selected entities"));
52         return action;
53 }
54
55 /**
56  * Deletes all entities that were selected.
57  */
58 void RS_ActionModifyDeleteQuick::trigger()
59 {
60     RS_DEBUG->print("RS_ActionModifyDeleteQuick::trigger()");
61
62     if (en!=NULL)
63         {
64         RS_DEBUG->print("Entity found");
65         RS_EntityContainer* parent = en->getParent();
66         if (parent!=NULL) {
67             en->setSelected(false);
68             graphicView->deleteEntity(en);
69             en->changeUndoState();
70
71             if (document) {
72                 document->startUndoCycle();
73                 document->addUndoable(en);
74                 document->endUndoCycle();
75             }
76         }
77
78         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
79     } else {
80         RS_DEBUG->print("RS_ActionModifyDeleteQuick::mousePressEvent:"
81                         " Entity is NULL\n");
82     }
83 }
84
85
86
87 void RS_ActionModifyDeleteQuick::mouseReleaseEvent(QMouseEvent* e) {
88     if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
89         init(getStatus()-1);
90     } else {
91         en = catchEntity(e);
92         trigger();
93     }
94 }
95
96
97
98 void RS_ActionModifyDeleteQuick::updateMouseButtonHints() {
99     switch (getStatus()) {
100     case 0:
101         RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entity to delete"),
102                                        tr("Cancel"));
103         break;
104     default:
105         RS_DIALOGFACTORY->updateMouseWidget("", "");
106         break;
107     }
108 }
109
110
111
112 void RS_ActionModifyDeleteQuick::updateMouseCursor() {
113     graphicView->setMouseCursor(RS2::DelCursor);
114 }
115
116 // EOF