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"
20 CadToolBarSnap::CadToolBarSnap(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
21 QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
26 CadToolBarSnap::~CadToolBarSnap()
30 //void CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
31 // if (e->button()==RightButton && cadToolBar!=NULL) {
37 void CadToolBarSnap::contextMenuEvent(QContextMenuEvent * e)
42 void CadToolBarSnap::setCadToolBar(CadToolBar * tb)
48 actionHandler = tb->getActionHandler();
49 actionHandler->setCadToolBarSnap(this);
52 RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
55 void CadToolBarSnap::snapFree()
57 if (actionHandler!=NULL)
60 ui.bFree->setChecked(true);
61 actionHandler->slotSnapFree();
65 void CadToolBarSnap::snapGrid()
67 if (actionHandler!=NULL)
69 actionHandler->slotSnapGrid();
71 ui.bGrid->setChecked(true);
75 void CadToolBarSnap::snapEndpoint() {
76 if (actionHandler!=NULL) {
77 actionHandler->slotSnapEndpoint();
79 ui.bEndpoint->setChecked(true);
83 void CadToolBarSnap::snapOnEntity() {
84 if (actionHandler!=NULL) {
85 actionHandler->slotSnapOnEntity();
87 ui.bOnEntity->setChecked(true);
91 void CadToolBarSnap::snapCenter() {
92 if (actionHandler!=NULL) {
93 actionHandler->slotSnapCenter();
95 ui.bCenter->setChecked(true);
99 void CadToolBarSnap::snapMiddle() {
100 if (actionHandler!=NULL) {
101 actionHandler->slotSnapMiddle();
103 ui.bMiddle->setChecked(true);
107 void CadToolBarSnap::snapDist() {
108 if (actionHandler!=NULL) {
109 actionHandler->slotSnapDist();
111 ui.bDist->setChecked(true);
115 void CadToolBarSnap::snapIntersection() {
116 if (actionHandler!=NULL) {
117 actionHandler->slotSnapIntersection();
119 ui.bIntersection->setChecked(true);
123 void CadToolBarSnap::snapIntersectionManual()
125 if (actionHandler!=NULL)
127 actionHandler->slotSnapIntersectionManual();
129 //bIntersectionManual->setChecked(true);
133 void CadToolBarSnap::restrictNothing()
135 if (actionHandler!=NULL)
137 actionHandler->slotRestrictNothing();
138 disableRestrictions();
139 ui.bResNothing->setChecked(true);
143 void CadToolBarSnap::restrictOrthogonal()
145 if (actionHandler!=NULL)
147 actionHandler->slotRestrictOrthogonal();
148 disableRestrictions();
149 ui.bResOrthogonal->setChecked(true);
153 void CadToolBarSnap::restrictHorizontal()
155 if (actionHandler!=NULL)
157 actionHandler->slotRestrictHorizontal();
158 disableRestrictions();
159 ui.bResHorizontal->setChecked(true);
163 void CadToolBarSnap::restrictVertical()
165 if (actionHandler!=NULL)
167 actionHandler->slotRestrictVertical();
168 disableRestrictions();
169 ui.bResVertical->setChecked(true);
173 void CadToolBarSnap::disableSnaps()
175 if (ui.bFree->isChecked())
176 ui.bFree->setChecked(false);
178 if (ui.bGrid->isChecked())
179 ui.bGrid->setChecked(false);
181 if (ui.bEndpoint->isChecked())
182 ui.bEndpoint->setChecked(false);
184 if (ui.bOnEntity->isChecked())
185 ui.bOnEntity->setChecked(false);
187 if (ui.bCenter->isChecked())
188 ui.bCenter->setChecked(false);
190 if (ui.bMiddle->isChecked())
191 ui.bMiddle->setChecked(false);
193 if (ui.bDist->isChecked())
194 ui.bDist->setChecked(false);
196 if (ui.bIntersection->isChecked())
197 ui.bIntersection->setChecked(false);
199 if (ui.bIntersectionManual->isChecked())
200 ui.bIntersectionManual->setChecked(false);
203 void CadToolBarSnap::disableRestrictions()
205 if (ui.bResNothing->isChecked())
206 ui.bResNothing->setChecked(false);
208 if (ui.bResOrthogonal->isChecked())
209 ui.bResOrthogonal->setChecked(false);
211 if (ui.bResHorizontal->isChecked())
212 ui.bResHorizontal->setChecked(false);
214 if (ui.bResVertical->isChecked())
215 ui.bResVertical->setChecked(false);
218 void CadToolBarSnap::setSnapMode(int sm)
223 ui.bFree->setChecked(true);
225 case RS2::SnapEndpoint:
226 ui.bEndpoint->setChecked(true);
229 ui.bGrid->setChecked(true);
231 case RS2::SnapOnEntity:
232 ui.bOnEntity->setChecked(true);
234 case RS2::SnapCenter:
235 ui.bCenter->setChecked(true);
237 case RS2::SnapMiddle:
238 ui.bMiddle->setChecked(true);
241 ui.bDist->setChecked(true);
243 case RS2::SnapIntersection:
244 ui.bIntersection->setChecked(true);
251 void CadToolBarSnap::setSnapRestriction(int sr)
256 case RS2::RestrictNothing:
257 ui.bResNothing->setChecked(true);
259 case RS2::RestrictOrthogonal:
260 ui.bResOrthogonal->setChecked(true);
262 case RS2::RestrictHorizontal:
263 ui.bResHorizontal->setChecked(true);
265 case RS2::RestrictVertical:
266 ui.bResVertical->setChecked(true);
271 void CadToolBarSnap::setRelativeZero()
273 if (cadToolBar!=NULL && actionHandler!=NULL)
274 actionHandler->slotSetRelativeZero();
277 void CadToolBarSnap::lockRelativeZero(bool on)
279 if (cadToolBar!=NULL && actionHandler!=NULL)
280 actionHandler->slotLockRelativeZero(on);
283 void CadToolBarSnap::setLockRelativeZero(bool on)
285 ui.bLockRelZero->setChecked(on);
288 void CadToolBarSnap::back()
290 if (cadToolBar != NULL)