1 // rs_actionselectwindow.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "rs_actionselectwindow.h"
18 #include "rs_snapper.h"
19 #include "rs_selection.h"
24 * @param select true: select window. false: deselect window
26 RS_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer& container,
27 RS_GraphicView& graphicView,
29 : RS_PreviewActionInterface("Select Window",
30 container, graphicView) {
32 this->select = select;
35 QAction * RS_ActionSelectWindow::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
39 if (type == RS2::ActionSelectWindow)
41 action = new QAction(tr("Select &Window"), 0);
42 // action = new QAction(tr("Select Window"), tr("Select &Window"),
43 // QKeySequence(), NULL);
44 action->setStatusTip(tr("Selects all Entities in a given Window"));
48 action = new QAction(tr("Deselect &Window"), 0);
49 // action = new QAction(tr("Deselect Window"), tr("Deselect &Window"),
50 // QKeySequence(), NULL);
51 action->setStatusTip(tr("Deselects all Entities in a given Window"));
57 void RS_ActionSelectWindow::init(int status)
59 RS_PreviewActionInterface::init(status);
60 v1 = v2 = Vector(false);
61 snapMode = RS2::SnapFree;
62 snapRes = RS2::RestrictNothing;
67 void RS_ActionSelectWindow::trigger() {
68 RS_PreviewActionInterface::trigger();
70 if (v1.valid && v2.valid) {
71 if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
74 bool cross = (v2.y>v1.y);
76 RS_Selection s(*container, graphicView);
77 s.selectWindow(v1, v2, select, cross);
79 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
88 void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent* e) {
89 if (getStatus()==SetCorner2 && v1.valid) {
93 preview->addEntity(new RS_Line(preview,
94 RS_LineData(Vector(v1.x, v1.y),
95 Vector(v2.x, v1.y))));
96 preview->addEntity(new RS_Line(preview,
97 RS_LineData(Vector(v2.x, v1.y),
98 Vector(v2.x, v2.y))));
99 preview->addEntity(new RS_Line(preview,
100 RS_LineData(Vector(v2.x, v2.y),
101 Vector(v1.x, v2.y))));
102 preview->addEntity(new RS_Line(preview,
103 RS_LineData(Vector(v1.x, v2.y),
104 Vector(v1.x, v1.y))));
111 void RS_ActionSelectWindow::mousePressEvent(QMouseEvent* e) {
112 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
113 switch (getStatus()) {
116 setStatus(SetCorner2);
124 RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f",
130 void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent* e) {
131 RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()");
133 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
134 if (getStatus()==SetCorner2) {
138 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
139 if (getStatus()==SetCorner2) {
149 void RS_ActionSelectWindow::updateMouseButtonHints() {
150 switch (getStatus()) {
152 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel"));
155 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
158 RS_DIALOGFACTORY->updateMouseWidget("", "");
165 void RS_ActionSelectWindow::updateMouseCursor() {
166 graphicView->setMouseCursor(RS2::SelectCursor);
171 void RS_ActionSelectWindow::updateToolBar() {
173 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
174 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
176 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);