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 "rs_actionselectsingle.h"
28 
29 #include <QAction>
30 #include <QMouseEvent>
31 #include "rs_dialogfactory.h"
32 #include "rs_selection.h"
33 #include "rs_debug.h"
34 
35 
36 
RS_ActionSelectSingle(RS_EntityContainer & container,RS_GraphicView & graphicView,RS_ActionInterface * action_select,std::initializer_list<RS2::EntityType> const & entityTypeList)37 RS_ActionSelectSingle::RS_ActionSelectSingle(RS_EntityContainer& container,
38 											 RS_GraphicView& graphicView,
39 											 RS_ActionInterface* action_select,
40 											 std::initializer_list<RS2::EntityType> const& entityTypeList)
41     :RS_ActionInterface("Select Entities", container, graphicView)
42     ,entityTypeList(entityTypeList)
43     ,en(nullptr)
44     ,actionSelect(action_select)
45 {
46     actionType = RS2::ActionSelectSingle;
47 }
48 
49 
trigger()50 void RS_ActionSelectSingle::trigger() {
51 	bool typeMatch{true};
52 	if (en && entityTypeList.size())
53 		typeMatch = std::find(entityTypeList.begin(), entityTypeList.end(), en->rtti())
54 				!= entityTypeList.end();
55 	if (en && typeMatch) {
56         RS_Selection s(*container, graphicView);
57         s.selectSingle(en);
58 
59         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
60     } else {
61         RS_DEBUG->print("RS_ActionSelectSingle::trigger: Entity is NULL\n");
62     }
63 }
64 
65 
keyPressEvent(QKeyEvent * e)66 void RS_ActionSelectSingle::keyPressEvent(QKeyEvent* e)
67 {
68     if (e->key()==Qt::Key_Escape)
69     {
70         finish(false);
71         actionSelect->keyPressEvent(e);
72     }
73 
74     if (container->countSelected() > 0 && e->key()==Qt::Key_Enter)
75     {
76         finish(false);
77         actionSelect->keyPressEvent(e);
78     }
79 }
80 
81 
mouseReleaseEvent(QMouseEvent * e)82 void RS_ActionSelectSingle::mouseReleaseEvent(QMouseEvent* e)
83 {
84     if (e->button()==Qt::RightButton)
85     {
86         finish();
87         if (actionSelect->rtti() == RS2::ActionSelect)
88             actionSelect->finish();
89         else
90             actionSelect->mouseReleaseEvent(e);
91     }
92     else
93     {
94         if (entityTypeList.size()) {
95             en = catchEntity(e, entityTypeList);
96         }else{
97             en = catchEntity(e);
98         }
99         trigger();
100     }
101 }
102 
103 
104 
updateMouseCursor()105 void RS_ActionSelectSingle::updateMouseCursor() {
106     graphicView->setMouseCursor(RS2::SelectCursor);
107 }
108 
109 // EOF
110