~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/plugins/intern/qc_actiongetpoint.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 "qc_actiongetpoint.h"
 
28
 
 
29
#include "rs_snapper.h"
 
30
#include "rs_dialogfactory.h"
 
31
#include "rs_graphicview.h"
 
32
 
 
33
 
 
34
 
 
35
QC_ActionGetPoint::QC_ActionGetPoint(RS_EntityContainer& container,
 
36
        RS_GraphicView& graphicView)
 
37
        :RS_PreviewActionInterface("Get Point",
 
38
                           container, graphicView) {
 
39
    completed = false;
 
40
    mesage = tr("Specify a point");
 
41
    setTargetPoint = false;
 
42
}
 
43
 
 
44
 
 
45
void QC_ActionGetPoint::trigger() {
 
46
 
 
47
    RS_DEBUG->print("QC_ActionGetPoint::trigger()");
 
48
    completed = true;
 
49
    updateMouseButtonHints();
 
50
}
 
51
 
 
52
 
 
53
void QC_ActionGetPoint::mouseMoveEvent(QMouseEvent* e) {
 
54
    RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent begin");
 
55
 
 
56
        RS_Vector mouse = snapPoint(e);
 
57
        if(setTargetPoint){
 
58
            if (referencePoint.valid) {
 
59
                targetPoint = mouse;
 
60
                deletePreview();
 
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");
 
66
                drawPreview();
 
67
                preview->addSelectionFrom(*container);
 
68
            }
 
69
        } else {
 
70
            targetPoint = mouse;
 
71
        }
 
72
 
 
73
    RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent end");
 
74
}
 
75
 
 
76
 
 
77
 
 
78
void QC_ActionGetPoint::mouseReleaseEvent(QMouseEvent* e) {
 
79
    if (e->button()==Qt::LeftButton) {
 
80
        RS_CoordinateEvent ce(snapPoint(e));
 
81
        coordinateEvent(&ce);
 
82
    } else if (e->button()==Qt::RightButton) {
 
83
        init(getStatus()-1);
 
84
    }
 
85
}
 
86
 
 
87
void QC_ActionGetPoint::coordinateEvent(RS_CoordinateEvent* e) {
 
88
 
 
89
    if (e==NULL) {
 
90
        return;
 
91
    }
 
92
 
 
93
    RS_Vector pos = e->getCoordinate();
 
94
 
 
95
        targetPoint = pos;
 
96
        graphicView->moveRelativeZero(targetPoint);
 
97
        trigger();
 
98
}
 
99
 
 
100
 
 
101
void QC_ActionGetPoint::updateMouseButtonHints() {
 
102
    if (!completed)
 
103
        RS_DIALOGFACTORY->updateMouseWidget(mesage, tr("Cancel"));
 
104
    else
 
105
        RS_DIALOGFACTORY->updateMouseWidget("", "");
 
106
}
 
107
 
 
108
 
 
109
void QC_ActionGetPoint::updateMouseCursor() {
 
110
    graphicView->setMouseCursor(RS2::CadCursor);
 
111
}
 
112
 
 
113
 
 
114
void QC_ActionGetPoint::setBasepoint(QPointF* basepoint){
 
115
    referencePoint.x = basepoint->x();
 
116
    referencePoint.y = basepoint->y();
 
117
    setTargetPoint = true;
 
118
}
 
119
 
 
120
 
 
121
void QC_ActionGetPoint::setMesage(QString msg){
 
122
    mesage = msg;
 
123
}
 
124
 
 
125
 
 
126
void QC_ActionGetPoint::getPoint(QPointF *point) {
 
127
    if (completed) {
 
128
        point->setX(targetPoint.x);
 
129
        point->setY(targetPoint.y);
 
130
    } else {
 
131
        point->setX(0.0);
 
132
        point->setY(0.0);
 
133
    }
 
134
}
 
135
 
 
136
// EOF