File size: 2,962 Bytes
a5ffdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
**
** This copyright notice MUST APPEAR in all copies of the script!  
**
**********************************************************************/

#include "qc_actiongetent.h"

#include <QKeyEvent>

#include "doc_plugin_interface.h"
#include "rs_debug.h"
#include "rs_selection.h"

QC_ActionGetEnt::QC_ActionGetEnt(LC_ActionContext* actionContext)
        :RS_ActionInterface("Get Entity", actionContext,RS2::ActionGetEntity) {
    m_completed = false;
    m_message = tr("Select object:");
    m_entity = nullptr;
}

void QC_ActionGetEnt::updateMouseButtonHints() {
    if (!m_completed)
        updateMouseWidget(m_message, tr("Cancel"));
    else
        updateMouseWidget();
}


RS2::CursorType QC_ActionGetEnt::doGetMouseCursor([[maybe_unused]] int status){
    return RS2::SelectCursor;
}

void QC_ActionGetEnt::setMessage(QString msg){
    m_message = msg;
}

void QC_ActionGetEnt::trigger() {
    if (m_entity) {
        RS_Selection s(*m_container, m_viewport);
        s.selectSingle(m_entity);
        m_completed = true;
        updateMouseButtonHints();
    } else {
        RS_DEBUG->print("QC_ActionGetEnt::trigger: Entity is NULL\n");
    }
}

void QC_ActionGetEnt::onMouseLeftButtonRelease([[maybe_unused]]int status, [[maybe_unused]]QMouseEvent * e) {
    m_entity = catchEntity(e);
    trigger();
}
void QC_ActionGetEnt::onMouseRightButtonRelease([[maybe_unused]]int status, [[maybe_unused]]QMouseEvent * e){
    m_completed = true;
    updateMouseButtonHints();
    finish();
}

void QC_ActionGetEnt::keyPressEvent(QKeyEvent *e){
    // qDebug() << "QC_ActionGetEnt::keyPressEvent";
    if (e->key() == Qt::Key_Escape) {
        updateMouseWidget();
        m_completed = true;
        // qDebug() << "escape QC_ActionGetEnt";
    }
}

/**
 * Add selected entity from 'container' to the selection.
 */
Plugin_Entity *QC_ActionGetEnt::getSelected(Doc_plugin_interface* d) {
    Plugin_Entity *pe = m_entity ? new Plugin_Entity(m_entity, d) : nullptr;
    return pe;
}