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"
18 #include "cadtoolbar.h"
19 #include "qg_actionhandler.h"
22 CadToolBarSnap::CadToolBarSnap(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23 QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
28 CadToolBarSnap::~CadToolBarSnap()
32 //void CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
33 // if (e->button()==RightButton && cadToolBar!=NULL) {
39 void CadToolBarSnap::contextMenuEvent(QContextMenuEvent * e)
44 void CadToolBarSnap::setCadToolBar(CadToolBar * tb)
50 actionHandler = tb->getActionHandler();
51 actionHandler->setCadToolBarSnap(this);
54 RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
57 void CadToolBarSnap::snapFree()
59 if (actionHandler!=NULL)
62 ui.bFree->setChecked(true);
63 actionHandler->slotSnapFree();
67 void CadToolBarSnap::snapGrid()
69 if (actionHandler!=NULL)
71 actionHandler->slotSnapGrid();
73 ui.bGrid->setChecked(true);
77 void CadToolBarSnap::snapEndpoint() {
78 if (actionHandler!=NULL) {
79 actionHandler->slotSnapEndpoint();
81 ui.bEndpoint->setChecked(true);
85 void CadToolBarSnap::snapOnEntity() {
86 if (actionHandler!=NULL) {
87 actionHandler->slotSnapOnEntity();
89 ui.bOnEntity->setChecked(true);
93 void CadToolBarSnap::snapCenter() {
94 if (actionHandler!=NULL) {
95 actionHandler->slotSnapCenter();
97 ui.bCenter->setChecked(true);
101 void CadToolBarSnap::snapMiddle() {
102 if (actionHandler!=NULL) {
103 actionHandler->slotSnapMiddle();
105 ui.bMiddle->setChecked(true);
109 void CadToolBarSnap::snapDist() {
110 if (actionHandler!=NULL) {
111 actionHandler->slotSnapDist();
113 ui.bDist->setChecked(true);
117 void CadToolBarSnap::snapIntersection() {
118 if (actionHandler!=NULL) {
119 actionHandler->slotSnapIntersection();
121 ui.bIntersection->setChecked(true);
125 void CadToolBarSnap::snapIntersectionManual()
127 if (actionHandler!=NULL)
129 actionHandler->slotSnapIntersectionManual();
131 //bIntersectionManual->setChecked(true);
135 void CadToolBarSnap::restrictNothing()
137 if (actionHandler!=NULL)
139 actionHandler->slotRestrictNothing();
140 disableRestrictions();
141 ui.bResNothing->setChecked(true);
145 void CadToolBarSnap::restrictOrthogonal()
147 if (actionHandler!=NULL)
149 actionHandler->slotRestrictOrthogonal();
150 disableRestrictions();
151 ui.bResOrthogonal->setChecked(true);
155 void CadToolBarSnap::restrictHorizontal()
157 if (actionHandler!=NULL)
159 actionHandler->slotRestrictHorizontal();
160 disableRestrictions();
161 ui.bResHorizontal->setChecked(true);
165 void CadToolBarSnap::restrictVertical()
167 if (actionHandler!=NULL)
169 actionHandler->slotRestrictVertical();
170 disableRestrictions();
171 ui.bResVertical->setChecked(true);
175 void CadToolBarSnap::disableSnaps()
177 if (ui.bFree->isChecked())
178 ui.bFree->setChecked(false);
180 if (ui.bGrid->isChecked())
181 ui.bGrid->setChecked(false);
183 if (ui.bEndpoint->isChecked())
184 ui.bEndpoint->setChecked(false);
186 if (ui.bOnEntity->isChecked())
187 ui.bOnEntity->setChecked(false);
189 if (ui.bCenter->isChecked())
190 ui.bCenter->setChecked(false);
192 if (ui.bMiddle->isChecked())
193 ui.bMiddle->setChecked(false);
195 if (ui.bDist->isChecked())
196 ui.bDist->setChecked(false);
198 if (ui.bIntersection->isChecked())
199 ui.bIntersection->setChecked(false);
201 if (ui.bIntersectionManual->isChecked())
202 ui.bIntersectionManual->setChecked(false);
205 void CadToolBarSnap::disableRestrictions()
207 if (ui.bResNothing->isChecked())
208 ui.bResNothing->setChecked(false);
210 if (ui.bResOrthogonal->isChecked())
211 ui.bResOrthogonal->setChecked(false);
213 if (ui.bResHorizontal->isChecked())
214 ui.bResHorizontal->setChecked(false);
216 if (ui.bResVertical->isChecked())
217 ui.bResVertical->setChecked(false);
220 void CadToolBarSnap::setSnapMode(int sm)
225 ui.bFree->setChecked(true);
227 case RS2::SnapEndpoint:
228 ui.bEndpoint->setChecked(true);
231 ui.bGrid->setChecked(true);
233 case RS2::SnapOnEntity:
234 ui.bOnEntity->setChecked(true);
236 case RS2::SnapCenter:
237 ui.bCenter->setChecked(true);
239 case RS2::SnapMiddle:
240 ui.bMiddle->setChecked(true);
243 ui.bDist->setChecked(true);
245 case RS2::SnapIntersection:
246 ui.bIntersection->setChecked(true);
253 void CadToolBarSnap::setSnapRestriction(int sr)
258 case RS2::RestrictNothing:
259 ui.bResNothing->setChecked(true);
261 case RS2::RestrictOrthogonal:
262 ui.bResOrthogonal->setChecked(true);
264 case RS2::RestrictHorizontal:
265 ui.bResHorizontal->setChecked(true);
267 case RS2::RestrictVertical:
268 ui.bResVertical->setChecked(true);
273 void CadToolBarSnap::setRelativeZero()
275 if (cadToolBar!=NULL && actionHandler!=NULL)
276 actionHandler->slotSetRelativeZero();
279 void CadToolBarSnap::lockRelativeZero(bool on)
281 if (cadToolBar!=NULL && actionHandler!=NULL)
282 actionHandler->slotLockRelativeZero(on);
285 void CadToolBarSnap::setLockRelativeZero(bool on)
287 ui.bLockRelZero->setChecked(on);
290 void CadToolBarSnap::back()
292 if (cadToolBar != NULL)
296 #include "cadtoolbar.h"
297 #include "createqtactions.h"
299 CadToolBarSnap::CadToolBarSnap(CadToolBar * parent, Qt::WindowFlags flags/*= 0*/):
300 QWidget((QWidget *)parent, flags), cadToolBar(parent)
302 QGridLayout * gridLayout = new QGridLayout(this);
303 gridLayout->setSpacing(0);
304 gridLayout->setContentsMargins(0, 0, 0, 0);
306 QAction * actionBack = new QAction(QIcon(":/res/qg_back"), tr("Back"), this);
307 QToolButton * button = new QToolButton(this);
308 button->setDefaultAction(actionBack);
309 QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
310 button->setSizePolicy(policy);
311 gridLayout->addWidget(button, 0, 0, 1, 2);
312 connect(button, SIGNAL(triggered(QAction *)), this, SLOT(back()));
314 gridLayout->addWidget(CreateToolButton(actionSnapFree), 1, 0, 1, 1);
315 gridLayout->addWidget(CreateToolButton(actionSnapGrid), 1, 1, 1, 1);
316 gridLayout->addWidget(CreateToolButton(actionSnapEndpoint), 2, 0, 1, 1);
317 gridLayout->addWidget(CreateToolButton(actionSnapOnEntity), 2, 1, 1, 1);
318 gridLayout->addWidget(CreateToolButton(actionSnapCenter), 3, 0, 1, 1);
319 gridLayout->addWidget(CreateToolButton(actionSnapMiddle), 3, 1, 1, 1);
320 gridLayout->addWidget(CreateToolButton(actionSnapDist), 4, 0, 1, 1);
321 gridLayout->addWidget(CreateToolButton(actionSnapIntersection), 4, 1, 1, 1);
322 gridLayout->addWidget(CreateToolButton(actionSnapIntersectionManual), 5, 0, 1, 1);
324 gridLayout->addWidget(CreateToolButton(actionRestrictNothing), 7, 0, 1, 1);
325 gridLayout->addWidget(CreateToolButton(actionRestrictOrthogonal), 7, 1, 1, 1);
326 gridLayout->addWidget(CreateToolButton(actionRestrictHorizontal), 8, 0, 1, 1);
327 gridLayout->addWidget(CreateToolButton(actionRestrictVertical), 8, 1, 1, 1);
329 gridLayout->addWidget(CreateToolButton(actionSetRelativeZero), 10, 0, 1, 1);
330 gridLayout->addWidget(CreateToolButton(actionLockRelativeZero), 10, 1, 1, 1);
333 CadToolBarSnap::~CadToolBarSnap()
337 void CadToolBarSnap::back()
342 QToolButton * CadToolBarSnap::CreateToolButton(QAction * action)
344 QToolButton * button = new QToolButton(this);
345 button->setDefaultAction(action);
346 button->setIconSize(QSize(18, 18));