1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
6 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
7 **
8 **
9 ** This file is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
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 "qc_actiongetent.h"
28 #include <QMouseEvent>
29 #include <QKeyEvent>
30 #include "doc_plugin_interface.h"
31 #include "rs_dialogfactory.h"
32 #include "rs_selection.h"
33 #include "rs_snapper.h"
34 #include "rs_debug.h"
35 // #include <QDebug>
36 
37 
QC_ActionGetEnt(RS_EntityContainer & container,RS_GraphicView & graphicView)38 QC_ActionGetEnt::QC_ActionGetEnt(RS_EntityContainer& container,
39                                  RS_GraphicView& graphicView)
40         :RS_ActionInterface("Get Entity", container, graphicView) {
41     completed = false;
42     message = tr("Select object:");
43     en = nullptr;
44 }
45 
46 
47 
updateMouseButtonHints()48 void QC_ActionGetEnt::updateMouseButtonHints() {
49     if (!completed)
50         RS_DIALOGFACTORY->updateMouseWidget(message, tr("Cancel"));
51     else
52         RS_DIALOGFACTORY->updateMouseWidget();
53 }
54 
55 
updateMouseCursor()56 void QC_ActionGetEnt::updateMouseCursor() {
57     graphicView->setMouseCursor(RS2::SelectCursor);
58 }
59 
setMessage(QString msg)60 void QC_ActionGetEnt::setMessage(QString msg){
61     message = msg;
62 }
63 
trigger()64 void QC_ActionGetEnt::trigger() {
65     if (en) {
66         RS_Selection s(*container, graphicView);
67         s.selectSingle(en);
68         completed = true;
69         updateMouseButtonHints();
70     } else {
71         RS_DEBUG->print("QC_ActionGetEnt::trigger: Entity is NULL\n");
72     }
73 }
74 
mouseReleaseEvent(QMouseEvent * e)75 void QC_ActionGetEnt::mouseReleaseEvent(QMouseEvent* e) {
76     if (e->button()==Qt::RightButton) {
77         completed = true;
78         updateMouseButtonHints();
79         finish();
80     } else {
81         en = catchEntity(e);
82         trigger();
83     }
84 }
85 
keyPressEvent(QKeyEvent * e)86 void QC_ActionGetEnt::keyPressEvent(QKeyEvent* e)
87 {
88     // qDebug() << "QC_ActionGetEnt::keyPressEvent";
89     if (e->key()==Qt::Key_Escape)
90     {
91 		RS_DIALOGFACTORY->updateMouseWidget();
92         completed = true;
93         // qDebug() << "escape QC_ActionGetEnt";
94     }
95 }
96 
97 /**
98  * Add selected entity from 'container' to the selection.
99  */
getSelected(Doc_plugin_interface * d)100 Plugin_Entity *QC_ActionGetEnt::getSelected(Doc_plugin_interface* d) {
101     Plugin_Entity *pe = en ? new Plugin_Entity(en, d) : nullptr;
102     return pe;
103 }
104 
105 // EOF
106