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/10/2010 Created this file. :-)
15 #include "cadtoolbarsnap.h"
17 #include "cadtoolbar.h"
18 #include "qg_actionhandler.h"
21 CadToolBarSnap::CadToolBarSnap(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
22 QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
27 CadToolBarSnap::~CadToolBarSnap()
31 //void CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
32 // if (e->button()==RightButton && cadToolBar!=NULL) {
38 void CadToolBarSnap::contextMenuEvent(QContextMenuEvent * e)
43 void CadToolBarSnap::setCadToolBar(CadToolBar * tb)
49 actionHandler = tb->getActionHandler();
50 actionHandler->setCadToolBarSnap(this);
53 RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
56 void CadToolBarSnap::snapFree()
58 if (actionHandler!=NULL)
61 ui.bFree->setChecked(true);
62 actionHandler->slotSnapFree();
66 void CadToolBarSnap::snapGrid()
68 if (actionHandler!=NULL)
70 actionHandler->slotSnapGrid();
72 ui.bGrid->setChecked(true);
76 void CadToolBarSnap::snapEndpoint() {
77 if (actionHandler!=NULL) {
78 actionHandler->slotSnapEndpoint();
80 ui.bEndpoint->setChecked(true);
84 void CadToolBarSnap::snapOnEntity() {
85 if (actionHandler!=NULL) {
86 actionHandler->slotSnapOnEntity();
88 ui.bOnEntity->setChecked(true);
92 void CadToolBarSnap::snapCenter() {
93 if (actionHandler!=NULL) {
94 actionHandler->slotSnapCenter();
96 ui.bCenter->setChecked(true);
100 void CadToolBarSnap::snapMiddle() {
101 if (actionHandler!=NULL) {
102 actionHandler->slotSnapMiddle();
104 ui.bMiddle->setChecked(true);
108 void CadToolBarSnap::snapDist() {
109 if (actionHandler!=NULL) {
110 actionHandler->slotSnapDist();
112 ui.bDist->setChecked(true);
116 void CadToolBarSnap::snapIntersection() {
117 if (actionHandler!=NULL) {
118 actionHandler->slotSnapIntersection();
120 ui.bIntersection->setChecked(true);
124 void CadToolBarSnap::snapIntersectionManual()
126 if (actionHandler!=NULL)
128 actionHandler->slotSnapIntersectionManual();
130 //bIntersectionManual->setChecked(true);
134 void CadToolBarSnap::restrictNothing()
136 if (actionHandler!=NULL)
138 actionHandler->slotRestrictNothing();
139 disableRestrictions();
140 ui.bResNothing->setChecked(true);
144 void CadToolBarSnap::restrictOrthogonal()
146 if (actionHandler!=NULL)
148 actionHandler->slotRestrictOrthogonal();
149 disableRestrictions();
150 ui.bResOrthogonal->setChecked(true);
154 void CadToolBarSnap::restrictHorizontal()
156 if (actionHandler!=NULL)
158 actionHandler->slotRestrictHorizontal();
159 disableRestrictions();
160 ui.bResHorizontal->setChecked(true);
164 void CadToolBarSnap::restrictVertical()
166 if (actionHandler!=NULL)
168 actionHandler->slotRestrictVertical();
169 disableRestrictions();
170 ui.bResVertical->setChecked(true);
174 void CadToolBarSnap::disableSnaps()
176 if (ui.bFree->isChecked())
177 ui.bFree->setChecked(false);
179 if (ui.bGrid->isChecked())
180 ui.bGrid->setChecked(false);
182 if (ui.bEndpoint->isChecked())
183 ui.bEndpoint->setChecked(false);
185 if (ui.bOnEntity->isChecked())
186 ui.bOnEntity->setChecked(false);
188 if (ui.bCenter->isChecked())
189 ui.bCenter->setChecked(false);
191 if (ui.bMiddle->isChecked())
192 ui.bMiddle->setChecked(false);
194 if (ui.bDist->isChecked())
195 ui.bDist->setChecked(false);
197 if (ui.bIntersection->isChecked())
198 ui.bIntersection->setChecked(false);
200 if (ui.bIntersectionManual->isChecked())
201 ui.bIntersectionManual->setChecked(false);
204 void CadToolBarSnap::disableRestrictions()
206 if (ui.bResNothing->isChecked())
207 ui.bResNothing->setChecked(false);
209 if (ui.bResOrthogonal->isChecked())
210 ui.bResOrthogonal->setChecked(false);
212 if (ui.bResHorizontal->isChecked())
213 ui.bResHorizontal->setChecked(false);
215 if (ui.bResVertical->isChecked())
216 ui.bResVertical->setChecked(false);
219 void CadToolBarSnap::setSnapMode(int sm)
224 ui.bFree->setChecked(true);
226 case RS2::SnapEndpoint:
227 ui.bEndpoint->setChecked(true);
230 ui.bGrid->setChecked(true);
232 case RS2::SnapOnEntity:
233 ui.bOnEntity->setChecked(true);
235 case RS2::SnapCenter:
236 ui.bCenter->setChecked(true);
238 case RS2::SnapMiddle:
239 ui.bMiddle->setChecked(true);
242 ui.bDist->setChecked(true);
244 case RS2::SnapIntersection:
245 ui.bIntersection->setChecked(true);
252 void CadToolBarSnap::setSnapRestriction(int sr)
257 case RS2::RestrictNothing:
258 ui.bResNothing->setChecked(true);
260 case RS2::RestrictOrthogonal:
261 ui.bResOrthogonal->setChecked(true);
263 case RS2::RestrictHorizontal:
264 ui.bResHorizontal->setChecked(true);
266 case RS2::RestrictVertical:
267 ui.bResVertical->setChecked(true);
272 void CadToolBarSnap::setRelativeZero()
274 if (cadToolBar!=NULL && actionHandler!=NULL)
275 actionHandler->slotSetRelativeZero();
278 void CadToolBarSnap::lockRelativeZero(bool on)
280 if (cadToolBar!=NULL && actionHandler!=NULL)
281 actionHandler->slotLockRelativeZero(on);
284 void CadToolBarSnap::setLockRelativeZero(bool on)
286 ui.bLockRelZero->setChecked(on);
289 void CadToolBarSnap::back()
291 if (cadToolBar != NULL)