~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/plugins/intern/qc_actiongetent.cpp

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "doc_plugin_interface.h"
 
28
#include "qc_actiongetent.h"
 
29
#include "rs_dialogfactory.h"
 
30
#include "rs_selection.h"
 
31
#include "rs_snapper.h"
 
32
 
 
33
 
 
34
QC_ActionGetEnt::QC_ActionGetEnt(RS_EntityContainer& container,
 
35
                                 RS_GraphicView& graphicView)
 
36
        :RS_ActionInterface("Get Entity", container, graphicView) {
 
37
    completed = false;
 
38
    mesage = tr("Select object:");
 
39
    en = NULL;
 
40
}
 
41
 
 
42
 
 
43
void QC_ActionGetEnt::updateMouseButtonHints() {
 
44
    if (!completed)
 
45
        RS_DIALOGFACTORY->updateMouseWidget(mesage, tr("Cancel"));
 
46
    else
 
47
        RS_DIALOGFACTORY->updateMouseWidget("", "");
 
48
}
 
49
 
 
50
 
 
51
void QC_ActionGetEnt::updateMouseCursor() {
 
52
    graphicView->setMouseCursor(RS2::SelectCursor);
 
53
}
 
54
 
 
55
void QC_ActionGetEnt::setMesage(QString msg){
 
56
    mesage = msg;
 
57
}
 
58
 
 
59
void QC_ActionGetEnt::trigger() {
 
60
    if (en!=NULL) {
 
61
        RS_Selection s(*container, graphicView);
 
62
        s.selectSingle(en);
 
63
        completed = true;
 
64
        updateMouseButtonHints();
 
65
    } else {
 
66
        RS_DEBUG->print("QC_ActionGetEnt::trigger: Entity is NULL\n");
 
67
    }
 
68
}
 
69
 
 
70
void QC_ActionGetEnt::mouseReleaseEvent(QMouseEvent* e) {
 
71
    if (e->button()==Qt::RightButton) {
 
72
        init(getStatus()-1);
 
73
    } else {
 
74
        en = catchEntity(e);
 
75
        trigger();
 
76
    }
 
77
}
 
78
 
 
79
/**
 
80
 * Add selected entity from 'container' to the selection.
 
81
 */
 
82
Plugin_Entity *QC_ActionGetEnt::getSelected(Doc_plugin_interface* d) {
 
83
    Plugin_Entity *pe = new Plugin_Entity(en, d);
 
84
    return pe;
 
85
}
 
86
 
 
87
// EOF