1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
** packaging of this file.
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 "rs_actionselectwindow.h"
30
#include "rs_dialogfactory.h"
31
#include "rs_graphicview.h"
32
#include "rs_selection.h"
33
#include "rs_overlaybox.h"
39
* @param select true: select window. false: deselect window
41
RS_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer& container,
42
RS_GraphicView& graphicView,
44
: RS_PreviewActionInterface("Select Window",
45
container, graphicView) {
47
this->select = select;
51
QAction* RS_ActionSelectWindow::createGUIAction(RS2::ActionType type, QObject* /*parent*/) {
54
if (type==RS2::ActionSelectWindow) {
55
action = new QAction(tr("Select Window"), NULL);
56
action->setIcon(QIcon(":/extui/selectwindow.png"));
57
//action->zetStatusTip(tr("Selects all Entities in a given Window"));
59
action = new QAction(tr("Deselect Window"), NULL);
60
action->setIcon(QIcon(":/extui/deselectwindow.png"));
61
//action->zetStatusTip(tr("Deselects all Entities in a given Window"));
67
void RS_ActionSelectWindow::init(int status) {
68
RS_PreviewActionInterface::init(status);
69
v1 = v2 = RS_Vector(false);
71
//snapMode.restriction = RS2::RestrictNothing;
76
void RS_ActionSelectWindow::trigger() {
77
RS_PreviewActionInterface::trigger();
79
if (v1.valid && v2.valid) {
80
if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
82
bool cross = (v1.x>v2.x);
84
RS_Selection s(*container, graphicView);
85
s.selectWindow(v1, v2, select, cross);
87
RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected(),container->totalSelectedLength());
96
void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent* e) {
99
if (getStatus()==SetCorner2 && v1.valid) {
102
RS_Pen pen_f(RS_Color(50,50,255,40), RS2::Width00, RS2::SolidLine);
103
RS_OverlayBox* ob=new RS_OverlayBox(preview, RS_OverlayBoxData(v1, v2));
105
preview->addEntity(ob);
107
//RLZ: not needed overlay have contour
108
/* RS_Pen pen(RS_Color(218,105,24), RS2::Width00, RS2::SolidLine);
110
// TODO change to a rs_box sort of entity
111
RS_Line* e=new RS_Line(preview, RS_LineData(RS_Vector(v1.x, v1.y), RS_Vector(v2.x, v1.y)));
113
preview->addEntity(e);
115
e=new RS_Line(preview, RS_LineData(RS_Vector(v2.x, v1.y), RS_Vector(v2.x, v2.y)));
117
preview->addEntity(e);
119
e=new RS_Line(preview, RS_LineData(RS_Vector(v2.x, v2.y), RS_Vector(v1.x, v2.y)));
121
preview->addEntity(e);
123
e=new RS_Line(preview, RS_LineData(RS_Vector(v1.x, v2.y), RS_Vector(v1.x, v1.y)));
125
preview->addEntity(e);*/
133
void RS_ActionSelectWindow::mousePressEvent(QMouseEvent* e) {
134
if (e->button()==Qt::LeftButton) {
135
switch (getStatus()) {
138
setStatus(SetCorner2);
146
RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f",
152
void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent* e) {
153
RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()");
155
if (e->button()==Qt::LeftButton) {
156
if (getStatus()==SetCorner2) {
160
} else if (e->button()==Qt::RightButton) {
161
if (getStatus()==SetCorner2) {
170
void RS_ActionSelectWindow::updateMouseButtonHints() {
171
switch (getStatus()) {
173
RS_DIALOGFACTORY->updateMouseWidget(tr("Click and drag for the selection window"), tr("Cancel"));
176
RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
179
RS_DIALOGFACTORY->updateMouseWidget("", "");
186
void RS_ActionSelectWindow::updateMouseCursor() {
187
graphicView->setMouseCursor(RS2::SelectCursor);
192
void RS_ActionSelectWindow::updateToolBar() {
193
//not needed any more
196
//RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
197
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
199
RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);