1 // rs_actionselectintersected.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_actionselectintersected.h"
18 #include "rs_snapper.h"
19 #include "rs_selection.h"
24 * @param select true: select window. false: deselect window
26 RS_ActionSelectIntersected::RS_ActionSelectIntersected(
27 RS_EntityContainer& container, RS_GraphicView& graphicView, bool select):
28 RS_PreviewActionInterface("Select Intersected", container, graphicView)
30 this->select = select;
33 QAction * RS_ActionSelectIntersected::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
37 if (type == RS2::ActionSelectIntersected)
39 action = new QAction(tr("In&tersected Entities"), 0);
40 // action = new QAction(tr("Select Intersected Entities"), tr("In&tersected Entities"),
41 // QKeySequence(), NULL);
42 action->setStatusTip(tr("Selects all entities intersected by a line"));
46 action = new QAction(tr("Deselect Inte&rsected Entities"), 0);
47 // action = new QAction(tr("Deselect Intersected Entities"),
48 // tr("Deselect Inte&rsected Entities"),
49 // QKeySequence(), NULL);
50 action->setStatusTip(tr("Deselects all entities intersected by a line"));
56 void RS_ActionSelectIntersected::init(int status)
58 RS_PreviewActionInterface::init(status);
60 v1 = v2 = Vector(false);
61 snapMode = RS2::SnapFree;
62 snapRes = RS2::RestrictNothing;
65 void RS_ActionSelectIntersected::trigger()
67 RS_PreviewActionInterface::trigger();
69 if (v1.valid && v2.valid) {
70 if (graphicView->toGuiDX(v1.distanceTo(v2))>10) {
73 RS_Selection s(*container, graphicView);
74 s.selectIntersected(v1, v2, select);
76 if (RS_DIALOGFACTORY!=NULL) {
77 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
85 void RS_ActionSelectIntersected::mouseMoveEvent(QMouseEvent* e)
87 if (getStatus()==SetPoint2 && v1.valid) {
91 preview->addEntity(new RS_Line(preview,
92 RS_LineData(Vector(v1.x, v1.y),
93 Vector(v2.x, v2.y))));
100 void RS_ActionSelectIntersected::mousePressEvent(QMouseEvent* e) {
101 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
102 switch (getStatus()) {
105 setStatus(SetPoint2);
113 RS_DEBUG->print("RS_ActionSelectIntersected::mousePressEvent(): %f %f",
119 void RS_ActionSelectIntersected::mouseReleaseEvent(QMouseEvent* e) {
120 RS_DEBUG->print("RS_ActionSelectIntersected::mouseReleaseEvent()");
121 if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
122 if (getStatus()==SetPoint2) {
127 } else if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
128 if (getStatus()==SetPoint2) {
137 void RS_ActionSelectIntersected::updateMouseButtonHints() {
138 if (RS_DIALOGFACTORY!=NULL) {
139 switch (getStatus()) {
141 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first point of intersection line"), tr("Cancel"));
144 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second point of intersection line"), tr("Back"));
147 RS_DIALOGFACTORY->updateMouseWidget("", "");
155 void RS_ActionSelectIntersected::updateMouseCursor() {
156 graphicView->setMouseCursor(RS2::SelectCursor);
161 void RS_ActionSelectIntersected::updateToolBar() {
162 if (RS_DIALOGFACTORY!=NULL) {
164 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
165 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
167 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);