1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
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.
13 **
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.
18 **
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
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26
27 #include <QMouseEvent>
28 #include "rs_actionselect.h"
29
30 #include "rs_dialogfactory.h"
31 #include "rs_graphicview.h"
32 #include "rs_actionselectsingle.h"
33
34
RS_ActionSelect(QG_ActionHandler * a_handler,RS_EntityContainer & container,RS_GraphicView & graphicView,RS2::ActionType nextAction,std::initializer_list<RS2::EntityType> const & entityTypeList)35 RS_ActionSelect::RS_ActionSelect(QG_ActionHandler* a_handler,
36 RS_EntityContainer& container,
37 RS_GraphicView& graphicView,
38 RS2::ActionType nextAction,
39 std::initializer_list<RS2::EntityType> const& entityTypeList)
40 :RS_ActionInterface("Select Entities", container, graphicView)
41 ,entityTypeList(entityTypeList)
42 ,nextAction(nextAction)
43 ,action_handler(a_handler)
44 {
45 actionType=RS2::ActionSelect;
46 }
47
48
49
init(int status)50 void RS_ActionSelect::init(int status) {
51 RS_ActionInterface::init(status);
52 if(status >= 0 ) {
53 graphicView->setCurrentAction(
54 new RS_ActionSelectSingle(*container, *graphicView, this, entityTypeList));
55 }
56 deleteSnapper();
57
58 }
59
resume()60 void RS_ActionSelect::resume(){
61 RS_ActionInterface::resume();
62 deleteSnapper();
63 }
64
mouseReleaseEvent(QMouseEvent * e)65 void RS_ActionSelect::mouseReleaseEvent(QMouseEvent* e) {
66 if (e->button()==Qt::RightButton) {
67 init(getStatus()-1);
68 }
69 }
70
71
countSelected()72 int RS_ActionSelect::countSelected() {
73 int ret=container->countSelected();
74 if (ret==0) {
75 RS_DIALOGFACTORY->commandMessage(tr("No entity selected!"));
76 }
77 return ret;
78 }
79
updateMouseButtonHints()80 void RS_ActionSelect::updateMouseButtonHints() {
81 switch(nextAction) {
82 case RS2::ActionModifyAttributesNoSelect:
83 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to modify attributes"), tr("Cancel"));
84 break;
85 case RS2::ActionOrderNoSelect:
86 RS_DIALOGFACTORY->updateMouseWidget(tr("Select entities to order"), tr("Cancel"));
87 break;
88 case RS2::ActionModifyDeleteNoSelect:
89 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to delete"), tr("Cancel"));
90 break;
91 case RS2::ActionModifyDeleteQuick:
92 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to delete immediately"), tr("Cancel"));
93 break;
94 case RS2::ActionModifyMoveNoSelect:
95 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to move"), tr("Cancel"));
96 break;
97 case RS2::ActionEditCopyNoSelect:
98 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to copy"), tr("Cancel"));
99 break;
100 case RS2::ActionEditCutNoSelect:
101 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to cut"), tr("Cancel"));
102 break;
103 case RS2::ActionModifyRevertDirectionNoSelect:
104 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to revert direction"), tr("Cancel"));
105 break;
106 case RS2::ActionModifyRotateNoSelect:
107 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to rotate"), tr("Cancel"));
108 break;
109 case RS2::ActionModifyScaleNoSelect:
110 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to scale"), tr("Cancel"));
111 break;
112 case RS2::ActionModifyMirrorNoSelect:
113 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to mirror"), tr("Cancel"));
114 break;
115 case RS2::ActionModifyMoveRotateNoSelect:
116 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to move and rotate"), tr("Cancel"));
117 break;
118 case RS2::ActionModifyOffsetNoSelect:
119 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to create offset"), tr("Cancel"));
120 break;
121 case RS2::ActionModifyRotate2NoSelect:
122 RS_DIALOGFACTORY->updateMouseWidget(tr("Select for two axis rotation"), tr("Cancel"));
123 break;
124 case RS2::ActionModifyExplodeTextNoSelect:
125 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to explode text"), tr("Cancel"));
126 break;
127 case RS2::ActionBlocksExplodeNoSelect:
128 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to explode block"), tr("Cancel"));
129 break;
130 case RS2::ActionBlocksCreateNoSelect:
131 RS_DIALOGFACTORY->updateMouseWidget(tr("Select to create block"), tr("Cancel"));
132 break;
133
134 default:
135 RS_DIALOGFACTORY->updateMouseWidget(tr(""), tr(""));
136 }
137 }
138
139
updateMouseCursor()140 void RS_ActionSelect::updateMouseCursor() {
141 if(graphicView){
142 if(isFinished()){
143 graphicView->setMouseCursor(RS2::ArrowCursor);
144 }else{
145 graphicView->setMouseCursor(RS2::SelectCursor);
146 }
147 }
148 }
149
keyPressEvent(QKeyEvent * e)150 void RS_ActionSelect::keyPressEvent(QKeyEvent* e)
151 {
152 if (e->key()==Qt::Key_Enter && countSelected() > 0)
153 {
154 finish();
155 action_handler->setCurrentAction(nextAction);
156 }
157 }
158
159 // EOF
160