]> Shamusworld >> Repos - architektonas/blob - forms/cadtoolbarsnap.cpp
Updated the TODO.
[architektonas] / forms / cadtoolbarsnap.cpp
1 // cadtoolbarsnap.cpp
2 //
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
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Created this file. :-)
13 //
14
15 #include "cadtoolbarsnap.h"
16
17 #if 0
18 #include "cadtoolbar.h"
19 #include "qg_actionhandler.h"
20 #include "rs_debug.h"
21
22 CadToolBarSnap::CadToolBarSnap(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL)
24 {
25         ui.setupUi(this);
26 }
27
28 CadToolBarSnap::~CadToolBarSnap()
29 {
30 }
31
32 //void CadToolBarSnap::mousePressEvent(QMouseEvent* e) {
33 //    if (e->button()==RightButton && cadToolBar!=NULL) {
34 //cadToolBar->back();
35 //        e->accept();
36 //    }
37 //}
38
39 void CadToolBarSnap::contextMenuEvent(QContextMenuEvent * e)
40 {
41         e->accept();
42 }
43
44 void CadToolBarSnap::setCadToolBar(CadToolBar * tb)
45 {
46         cadToolBar = tb;
47
48         if (tb!=NULL)
49         {
50                 actionHandler = tb->getActionHandler();
51                 actionHandler->setCadToolBarSnap(this);
52         }
53         else
54                 RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSnap::setCadToolBar(): No valid toolbar set.");
55 }
56
57 void CadToolBarSnap::snapFree()
58 {
59         if (actionHandler!=NULL)
60         {
61                 disableSnaps();
62                 ui.bFree->setChecked(true);
63                 actionHandler->slotSnapFree();
64         }
65 }
66
67 void CadToolBarSnap::snapGrid()
68 {
69         if (actionHandler!=NULL)
70         {
71                 actionHandler->slotSnapGrid();
72                 disableSnaps();
73                 ui.bGrid->setChecked(true);
74         }
75 }
76
77 void CadToolBarSnap::snapEndpoint() {
78         if (actionHandler!=NULL) {
79                 actionHandler->slotSnapEndpoint();
80                 disableSnaps();
81                 ui.bEndpoint->setChecked(true);
82         }
83 }
84
85 void CadToolBarSnap::snapOnEntity() {
86         if (actionHandler!=NULL) {
87                 actionHandler->slotSnapOnEntity();
88                 disableSnaps();
89                 ui.bOnEntity->setChecked(true);
90         }
91 }
92
93 void CadToolBarSnap::snapCenter() {
94         if (actionHandler!=NULL) {
95                 actionHandler->slotSnapCenter();
96                 disableSnaps();
97                 ui.bCenter->setChecked(true);
98         }
99 }
100
101 void CadToolBarSnap::snapMiddle() {
102         if (actionHandler!=NULL) {
103                 actionHandler->slotSnapMiddle();
104                 disableSnaps();
105                 ui.bMiddle->setChecked(true);
106         }
107 }
108
109 void CadToolBarSnap::snapDist() {
110         if (actionHandler!=NULL) {
111                 actionHandler->slotSnapDist();
112                 disableSnaps();
113                 ui.bDist->setChecked(true);
114         }
115 }
116
117 void CadToolBarSnap::snapIntersection() {
118         if (actionHandler!=NULL) {
119                 actionHandler->slotSnapIntersection();
120                 disableSnaps();
121                 ui.bIntersection->setChecked(true);
122         }
123 }
124
125 void CadToolBarSnap::snapIntersectionManual()
126 {
127         if (actionHandler!=NULL)
128         {
129                 actionHandler->slotSnapIntersectionManual();
130                 //disableSnaps();
131                 //bIntersectionManual->setChecked(true);
132         }
133 }
134
135 void CadToolBarSnap::restrictNothing()
136 {
137         if (actionHandler!=NULL)
138         {
139                 actionHandler->slotRestrictNothing();
140                 disableRestrictions();
141                 ui.bResNothing->setChecked(true);
142         }
143 }
144
145 void CadToolBarSnap::restrictOrthogonal()
146 {
147         if (actionHandler!=NULL)
148         {
149                 actionHandler->slotRestrictOrthogonal();
150                 disableRestrictions();
151                 ui.bResOrthogonal->setChecked(true);
152         }
153 }
154
155 void CadToolBarSnap::restrictHorizontal()
156 {
157         if (actionHandler!=NULL)
158         {
159                 actionHandler->slotRestrictHorizontal();
160                 disableRestrictions();
161                 ui.bResHorizontal->setChecked(true);
162         }
163 }
164
165 void CadToolBarSnap::restrictVertical()
166 {
167         if (actionHandler!=NULL)
168         {
169                 actionHandler->slotRestrictVertical();
170                 disableRestrictions();
171                 ui.bResVertical->setChecked(true);
172         }
173 }
174
175 void CadToolBarSnap::disableSnaps()
176 {
177         if (ui.bFree->isChecked())
178                 ui.bFree->setChecked(false);
179
180         if (ui.bGrid->isChecked())
181                 ui.bGrid->setChecked(false);
182
183         if (ui.bEndpoint->isChecked())
184                 ui.bEndpoint->setChecked(false);
185
186         if (ui.bOnEntity->isChecked())
187                 ui.bOnEntity->setChecked(false);
188
189         if (ui.bCenter->isChecked())
190                 ui.bCenter->setChecked(false);
191
192         if (ui.bMiddle->isChecked())
193                 ui.bMiddle->setChecked(false);
194
195         if (ui.bDist->isChecked())
196                 ui.bDist->setChecked(false);
197
198         if (ui.bIntersection->isChecked())
199                 ui.bIntersection->setChecked(false);
200
201         if (ui.bIntersectionManual->isChecked())
202                 ui.bIntersectionManual->setChecked(false);
203 }
204
205 void CadToolBarSnap::disableRestrictions()
206 {
207         if (ui.bResNothing->isChecked())
208                 ui.bResNothing->setChecked(false);
209
210         if (ui.bResOrthogonal->isChecked())
211                 ui.bResOrthogonal->setChecked(false);
212
213         if (ui.bResHorizontal->isChecked())
214                 ui.bResHorizontal->setChecked(false);
215
216         if (ui.bResVertical->isChecked())
217                 ui.bResVertical->setChecked(false);
218 }
219
220 void CadToolBarSnap::setSnapMode(int sm)
221 {
222         switch (sm)
223         {
224         case RS2::SnapFree:
225                 ui.bFree->setChecked(true);
226                 break;
227         case RS2::SnapEndpoint:
228                 ui.bEndpoint->setChecked(true);
229                 break;
230         case RS2::SnapGrid:
231                 ui.bGrid->setChecked(true);
232                 break;
233         case RS2::SnapOnEntity:
234                 ui.bOnEntity->setChecked(true);
235                 break;
236         case RS2::SnapCenter:
237                 ui.bCenter->setChecked(true);
238                 break;
239         case RS2::SnapMiddle:
240                 ui.bMiddle->setChecked(true);
241                 break;
242         case RS2::SnapDist:
243                 ui.bDist->setChecked(true);
244                 break;
245         case RS2::SnapIntersection:
246                 ui.bIntersection->setChecked(true);
247                 break;
248         default:
249                 break;
250         }
251 }
252
253 void CadToolBarSnap::setSnapRestriction(int sr)
254 {
255         switch (sr)
256         {
257         default:
258         case RS2::RestrictNothing:
259                 ui.bResNothing->setChecked(true);
260                 break;
261         case RS2::RestrictOrthogonal:
262                 ui.bResOrthogonal->setChecked(true);
263                 break;
264         case RS2::RestrictHorizontal:
265                 ui.bResHorizontal->setChecked(true);
266                 break;
267         case RS2::RestrictVertical:
268                 ui.bResVertical->setChecked(true);
269                 break;
270         }
271 }
272
273 void CadToolBarSnap::setRelativeZero()
274 {
275         if (cadToolBar!=NULL && actionHandler!=NULL)
276                 actionHandler->slotSetRelativeZero();
277 }
278
279 void CadToolBarSnap::lockRelativeZero(bool on)
280 {
281         if (cadToolBar!=NULL && actionHandler!=NULL)
282                 actionHandler->slotLockRelativeZero(on);
283 }
284
285 void CadToolBarSnap::setLockRelativeZero(bool on)
286 {
287         ui.bLockRelZero->setChecked(on);
288 }
289
290 void CadToolBarSnap::back()
291 {
292         if (cadToolBar != NULL)
293                 cadToolBar->back();
294 }
295 #else
296 #include "cadtoolbar.h"
297 #include "createqtactions.h"
298
299 CadToolBarSnap::CadToolBarSnap(CadToolBar * parent, Qt::WindowFlags flags/*= 0*/):
300         QWidget((QWidget *)parent, flags), cadToolBar(parent)
301 {
302         QGridLayout * gridLayout = new QGridLayout(this);
303         gridLayout->setSpacing(0);
304         gridLayout->setContentsMargins(0, 0, 0, 0);
305
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()));
313
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);
323
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);
328
329         gridLayout->addWidget(CreateToolButton(actionSetRelativeZero), 10, 0, 1, 1);
330         gridLayout->addWidget(CreateToolButton(actionLockRelativeZero), 10, 1, 1, 1);
331 }
332
333 CadToolBarSnap::~CadToolBarSnap()
334 {
335 }
336
337 void CadToolBarSnap::back()
338 {
339         cadToolBar->back();
340 }
341
342 QToolButton * CadToolBarSnap::CreateToolButton(QAction * action)
343 {
344         QToolButton * button = new QToolButton(this);
345         button->setDefaultAction(action);
346         button->setIconSize(QSize(18, 18));
347
348         return button;
349 }
350 #endif