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"
17 #include "rs_dialogfactory.h"
18 #include "rs_selection.h"
19 #include "rs_preview.h"
24 * @param select true: select window. false: deselect window
26 RS_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer & container,
27 GraphicView & graphicView, bool select):
28 RS_PreviewActionInterface("Select Window", container, graphicView)
30 this->select = select;
33 RS_ActionSelectWindow::~RS_ActionSelectWindow()
37 /*virtual*/ RS2::ActionType RS_ActionSelectWindow::rtti()
39 return RS2::ActionSelectWindow;
42 void RS_ActionSelectWindow::init(int status)
44 RS_PreviewActionInterface::init(status);
45 v1 = v2 = Vector(false);
46 snapMode = RS2::SnapFree;
47 snapRes = RS2::RestrictNothing;
50 void RS_ActionSelectWindow::trigger()
52 RS_PreviewActionInterface::trigger();
54 if (v1.valid && v2.valid)
56 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
60 bool cross = (v2.y > v1.y);
62 RS_Selection s(*container, graphicView);
63 s.selectWindow(v1, v2, select, cross);
65 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
72 void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent * e)
74 if (getStatus() == SetCorner2 && v1.valid)
79 preview->addEntity(new RS_Line(preview,
80 RS_LineData(Vector(v1.x, v1.y),
81 Vector(v2.x, v1.y))));
82 preview->addEntity(new RS_Line(preview,
83 RS_LineData(Vector(v2.x, v1.y),
84 Vector(v2.x, v2.y))));
85 preview->addEntity(new RS_Line(preview,
86 RS_LineData(Vector(v2.x, v2.y),
87 Vector(v1.x, v2.y))));
88 preview->addEntity(new RS_Line(preview,
89 RS_LineData(Vector(v1.x, v2.y),
90 Vector(v1.x, v1.y))));
95 void RS_ActionSelectWindow::mousePressEvent(QMouseEvent * e)
97 if (e->button() == Qt::LeftButton)
103 setStatus(SetCorner2);
111 RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f",
115 void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent * e)
117 RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()");
119 if (e->button() == Qt::LeftButton)
121 if (getStatus() == SetCorner2)
127 else if (e->button() == Qt::RightButton)
129 if (getStatus() == SetCorner2)
132 init(getStatus() - 1);
136 void RS_ActionSelectWindow::updateMouseButtonHints()
141 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel"));
145 RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back"));
149 RS_DIALOGFACTORY->updateMouseWidget("", "");
154 void RS_ActionSelectWindow::updateMouseCursor()
156 graphicView->setMouseCursor(RS2::SelectCursor);
159 void RS_ActionSelectWindow::updateToolBar()
162 //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
163 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
165 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);