3 // Originally part of QCad Community Edition by Andrew Mustun
4 // Extensively rewritten and refactored by James L. Hammons
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -----------------------------------------------------------
11 // JLH 05/10/2010 Created this file. :-)
14 #include "cadtoolbarsnap.h"
16 #include "cadtoolbar.h"
17 #include "qg_actionhandler.h"
19 CadToolBarSnap::CadToolBarSnap(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
20 QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
25 CadToolBarSnap::~CadToolBarSnap()
29 //void CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
30 // if (e->button()==RightButton && cadToolBar!=NULL) {
36 void CadToolBarSnap::contextMenuEvent(QContextMenuEvent * e)
41 void CadToolBarSnap::setCadToolBar(CadToolBar * tb)
47 actionHandler = tb->getActionHandler();
48 actionHandler->setCadToolBarSnap(this);
51 RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
54 void CadToolBarSnap::snapFree()
56 if (actionHandler!=NULL)
59 ui.bFree->setChecked(true);
60 actionHandler->slotSnapFree();
64 void CadToolBarSnap::snapGrid()
66 if (actionHandler!=NULL)
68 actionHandler->slotSnapGrid();
70 ui.bGrid->setChecked(true);
74 void CadToolBarSnap::snapEndpoint() {
75 if (actionHandler!=NULL) {
76 actionHandler->slotSnapEndpoint();
78 ui.bEndpoint->setChecked(true);
82 void CadToolBarSnap::snapOnEntity() {
83 if (actionHandler!=NULL) {
84 actionHandler->slotSnapOnEntity();
86 ui.bOnEntity->setChecked(true);
90 void CadToolBarSnap::snapCenter() {
91 if (actionHandler!=NULL) {
92 actionHandler->slotSnapCenter();
94 ui.bCenter->setChecked(true);
98 void CadToolBarSnap::snapMiddle() {
99 if (actionHandler!=NULL) {
100 actionHandler->slotSnapMiddle();
102 ui.bMiddle->setChecked(true);
106 void CadToolBarSnap::snapDist() {
107 if (actionHandler!=NULL) {
108 actionHandler->slotSnapDist();
110 ui.bDist->setChecked(true);
114 void CadToolBarSnap::snapIntersection() {
115 if (actionHandler!=NULL) {
116 actionHandler->slotSnapIntersection();
118 ui.bIntersection->setChecked(true);
122 void CadToolBarSnap::snapIntersectionManual()
124 if (actionHandler!=NULL)
126 actionHandler->slotSnapIntersectionManual();
128 //bIntersectionManual->setChecked(true);
132 void CadToolBarSnap::restrictNothing()
134 if (actionHandler!=NULL)
136 actionHandler->slotRestrictNothing();
137 disableRestrictions();
138 ui.bResNothing->setChecked(true);
142 void CadToolBarSnap::restrictOrthogonal()
144 if (actionHandler!=NULL)
146 actionHandler->slotRestrictOrthogonal();
147 disableRestrictions();
148 ui.bResOrthogonal->setChecked(true);
152 void CadToolBarSnap::restrictHorizontal()
154 if (actionHandler!=NULL)
156 actionHandler->slotRestrictHorizontal();
157 disableRestrictions();
158 ui.bResHorizontal->setChecked(true);
162 void CadToolBarSnap::restrictVertical()
164 if (actionHandler!=NULL)
166 actionHandler->slotRestrictVertical();
167 disableRestrictions();
168 ui.bResVertical->setChecked(true);
172 void CadToolBarSnap::disableSnaps()
174 if (ui.bFree->isChecked())
175 ui.bFree->setChecked(false);
177 if (ui.bGrid->isChecked())
178 ui.bGrid->setChecked(false);
180 if (ui.bEndpoint->isChecked())
181 ui.bEndpoint->setChecked(false);
183 if (ui.bOnEntity->isChecked())
184 ui.bOnEntity->setChecked(false);
186 if (ui.bCenter->isChecked())
187 ui.bCenter->setChecked(false);
189 if (ui.bMiddle->isChecked())
190 ui.bMiddle->setChecked(false);
192 if (ui.bDist->isChecked())
193 ui.bDist->setChecked(false);
195 if (ui.bIntersection->isChecked())
196 ui.bIntersection->setChecked(false);
198 if (ui.bIntersectionManual->isChecked())
199 ui.bIntersectionManual->setChecked(false);
202 void CadToolBarSnap::disableRestrictions()
204 if (ui.bResNothing->isChecked())
205 ui.bResNothing->setChecked(false);
207 if (ui.bResOrthogonal->isChecked())
208 ui.bResOrthogonal->setChecked(false);
210 if (ui.bResHorizontal->isChecked())
211 ui.bResHorizontal->setChecked(false);
213 if (ui.bResVertical->isChecked())
214 ui.bResVertical->setChecked(false);
217 void CadToolBarSnap::setSnapMode(int sm)
222 ui.bFree->setChecked(true);
224 case RS2::SnapEndpoint:
225 ui.bEndpoint->setChecked(true);
228 ui.bGrid->setChecked(true);
230 case RS2::SnapOnEntity:
231 ui.bOnEntity->setChecked(true);
233 case RS2::SnapCenter:
234 ui.bCenter->setChecked(true);
236 case RS2::SnapMiddle:
237 ui.bMiddle->setChecked(true);
240 ui.bDist->setChecked(true);
242 case RS2::SnapIntersection:
243 ui.bIntersection->setChecked(true);
250 void CadToolBarSnap::setSnapRestriction(int sr)
255 case RS2::RestrictNothing:
256 ui.bResNothing->setChecked(true);
258 case RS2::RestrictOrthogonal:
259 ui.bResOrthogonal->setChecked(true);
261 case RS2::RestrictHorizontal:
262 ui.bResHorizontal->setChecked(true);
264 case RS2::RestrictVertical:
265 ui.bResVertical->setChecked(true);
270 void CadToolBarSnap::setRelativeZero()
272 if (cadToolBar!=NULL && actionHandler!=NULL)
273 actionHandler->slotSetRelativeZero();
276 void CadToolBarSnap::lockRelativeZero(bool on)
278 if (cadToolBar!=NULL && actionHandler!=NULL)
279 actionHandler->slotLockRelativeZero(on);
282 void CadToolBarSnap::setLockRelativeZero(bool on)
284 ui.bLockRelZero->setChecked(on);
287 void CadToolBarSnap::back()
289 if (cadToolBar != NULL)