1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
6
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
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.
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.
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
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
27
#include "qc_actiongetpoint.h"
29
#include "rs_snapper.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
35
QC_ActionGetPoint::QC_ActionGetPoint(RS_EntityContainer& container,
36
RS_GraphicView& graphicView)
37
:RS_PreviewActionInterface("Get Point",
38
container, graphicView) {
40
mesage = tr("Specify a point");
41
setTargetPoint = false;
45
void QC_ActionGetPoint::trigger() {
47
RS_DEBUG->print("QC_ActionGetPoint::trigger()");
49
updateMouseButtonHints();
53
void QC_ActionGetPoint::mouseMoveEvent(QMouseEvent* e) {
54
RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent begin");
56
RS_Vector mouse = snapPoint(e);
58
if (referencePoint.valid) {
61
RS_Line *line =new RS_Line(preview,
62
RS_LineData(referencePoint, mouse));
63
line->setPen(RS_Pen(RS_Color(0,0,0), RS2::Width00, RS2::DotLine ));
64
preview->addEntity(line);
65
RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent: draw preview");
67
preview->addSelectionFrom(*container);
73
RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent end");
78
void QC_ActionGetPoint::mouseReleaseEvent(QMouseEvent* e) {
79
if (e->button()==Qt::LeftButton) {
80
RS_CoordinateEvent ce(snapPoint(e));
82
} else if (e->button()==Qt::RightButton) {
87
void QC_ActionGetPoint::coordinateEvent(RS_CoordinateEvent* e) {
93
RS_Vector pos = e->getCoordinate();
96
graphicView->moveRelativeZero(targetPoint);
101
void QC_ActionGetPoint::updateMouseButtonHints() {
103
RS_DIALOGFACTORY->updateMouseWidget(mesage, tr("Cancel"));
105
RS_DIALOGFACTORY->updateMouseWidget("", "");
109
void QC_ActionGetPoint::updateMouseCursor() {
110
graphicView->setMouseCursor(RS2::CadCursor);
114
void QC_ActionGetPoint::setBasepoint(QPointF* basepoint){
115
referencePoint.x = basepoint->x();
116
referencePoint.y = basepoint->y();
117
setTargetPoint = true;
121
void QC_ActionGetPoint::setMesage(QString msg){
126
void QC_ActionGetPoint::getPoint(QPointF *point) {
128
point->setX(targetPoint.x);
129
point->setY(targetPoint.y);