]> Shamusworld >> Repos - architektonas/blob - src/forms/cadtoolbar.cpp
Refactored CAD tool bars to use predefined actions.
[architektonas] / src / forms / cadtoolbar.cpp
1 // cadtoolbar.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 "cadtoolbar.h"
16
17 #include "cadtoolbararcs.h"
18 #include "cadtoolbarcircles.h"
19 #include "cadtoolbardim.h"
20 #include "cadtoolbarellipses.h"
21 #include "cadtoolbarinfo.h"
22 #include "cadtoolbarlines.h"
23 #include "cadtoolbarmain.h"
24 #include "cadtoolbarmodify.h"
25 #include "cadtoolbarpoints.h"
26 #include "cadtoolbarpolylines.h"
27 #include "cadtoolbarselect.h"
28 #include "cadtoolbarsnap.h"
29 #include "cadtoolbarsplines.h"
30 #include "rs.h"
31
32 CadToolBar::CadToolBar(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
33         QWidget(parent, flags), actionHandler(NULL), currentTb(NULL), tbSplines(NULL),
34         tbInfo(NULL),tbMain(NULL), tbDim(NULL), tbLines(NULL), tbPoints(NULL),
35         tbEllipses(NULL), tbArcs(NULL), tbModify(NULL), tbCircles(NULL), tbSnap(NULL),
36         tbSelect(NULL), tbPolylines(NULL)
37 {
38 //hmm.
39 #if 1
40         resize(86, 336);
41 //      QSizePolicy policy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
42 //      policy.setHorizontalStretch(0);
43 //      policy.setVerticalStretch(0);
44 //      policy.setHeightForWidth(sizePolicy().hasHeightForWidth());
45 //      setSizePolicy(policy);
46         setMinimumSize(QSize(56, 336));
47 #endif
48 //hm. here maybe? Yesh!
49         if (parent)
50                 ((QToolBar *)parent)->addWidget(this);
51 }
52
53 CadToolBar::~CadToolBar()
54 {
55 }
56
57 /**
58  * @return Pointer to action handler or NULL.
59  */
60 QG_ActionHandler * CadToolBar::getActionHandler()
61 {
62         return actionHandler;
63 }
64
65 /**
66  * Called from the sub toolbar
67  */
68 void CadToolBar::back()
69 {
70         emit(signalBack());
71 }
72
73 /**
74  * Called from the application.
75  */
76 void CadToolBar::forceNext()
77 {
78         if (currentTb && currentTb == tbSelect)
79                 tbSelect->runNextAction();
80 }
81
82 void CadToolBar::mouseReleaseEvent(QMouseEvent * e)
83 {
84         if (e->button() == Qt::RightButton)
85         {
86                 back();
87                 e->accept();
88         }
89 }
90
91 void CadToolBar::contextMenuEvent(QContextMenuEvent * e)
92 {
93     e->accept();
94 }
95
96 /**
97  * Creates all tool bars and shows the main toolbar.
98  *
99  * @param ah Pointer to action handler which will deal with the actions in this tool bar.
100  */
101 void CadToolBar::createSubToolBars(QG_ActionHandler * ah)
102 {
103         actionHandler = ah;
104         tbMain = new CadToolBarMain(this);
105         tbMain->setCadToolBar(this);
106         currentTb = tbMain;
107
108         tbPoints = new CadToolBarPoints(this);
109         tbPoints->hide();
110
111         tbLines = new CadToolBarLines(this);
112         tbLines->hide();
113
114         tbArcs = new CadToolBarArcs(this);
115         tbArcs->hide();
116
117         tbCircles = new CadToolBarCircles(this);
118         tbCircles->hide();
119
120         tbEllipses = new CadToolBarEllipses(this);
121         tbEllipses->hide();
122
123         tbSplines = new CadToolBarSplines(this);
124         tbSplines->hide();
125
126         tbPolylines = new CadToolBarPolylines(this);
127         tbPolylines->hide();
128
129         tbDim = new CadToolBarDim(this);
130         tbDim->hide();
131
132         tbInfo = new CadToolBarInfo(this);
133         tbInfo->hide();
134
135         tbModify = new CadToolBarModify(this);
136         tbModify->hide();
137
138         tbSnap = new CadToolBarSnap(this);
139         tbSnap->hide();
140
141         tbSelect = new CadToolBarSelect(this);
142         tbSelect->hide();
143 }
144
145 void CadToolBar::showToolBar(int id)
146 {
147         QWidget * newTb = NULL;
148
149         switch (id)
150         {
151         default:
152         case RS2::ToolBarMain:
153                 newTb = tbMain;
154                 break;
155         case RS2::ToolBarPoints:
156                 newTb = tbPoints;
157                 break;
158         case RS2::ToolBarLines:
159                 newTb = tbLines;
160                 break;
161         case RS2::ToolBarArcs:
162                 newTb = tbArcs;
163                 break;
164         case RS2::ToolBarEllipses:
165                 newTb = tbEllipses;
166                 break;
167         case RS2::ToolBarSplines:
168                 newTb = tbSplines;
169                 break;
170         case RS2::ToolBarPolylines:
171                 newTb = tbPolylines;
172                 break;
173         case RS2::ToolBarCircles:
174                 newTb = tbCircles;
175                 break;
176         case RS2::ToolBarInfo:
177                 newTb = tbInfo;
178                 break;
179         case RS2::ToolBarModify:
180                 newTb = tbModify;
181                 break;
182         case RS2::ToolBarDim:
183                 newTb = tbDim;
184                 break;
185         case RS2::ToolBarSnap:
186                 newTb = tbSnap;
187                 break;
188         case RS2::ToolBarSelect:
189                 newTb = tbSelect;
190                 break;
191         }
192
193         if (currentTb == newTb)
194                 return;
195
196         if (currentTb)
197                 currentTb->hide();
198
199         currentTb = newTb;
200
201         if (currentTb)
202                 currentTb->show();
203 }
204
205 void CadToolBar::showToolBarMain()
206 {
207         showToolBar(RS2::ToolBarMain);
208 }
209
210 void CadToolBar::showToolBarPoints()
211 {
212         showToolBar(RS2::ToolBarPoints);
213 }
214
215 void CadToolBar::showToolBarLines()
216 {
217         showToolBar(RS2::ToolBarLines);
218 }
219
220 void CadToolBar::showToolBarArcs()
221 {
222         showToolBar(RS2::ToolBarArcs);
223 }
224
225 void CadToolBar::showToolBarEllipses()
226 {
227         showToolBar(RS2::ToolBarEllipses);
228 }
229
230 void CadToolBar::showToolBarSplines()
231 {
232         showToolBar(RS2::ToolBarSplines);
233 }
234
235 void CadToolBar::showToolBarPolylines()
236 {
237 //#ifdef RS_PROF
238         showToolBar(RS2::ToolBarPolylines);
239 //#endif
240 }
241
242 void CadToolBar::showToolBarCircles()
243 {
244         showToolBar(RS2::ToolBarCircles);
245 }
246
247 void CadToolBar::showToolBarInfo()
248 {
249         showToolBar(RS2::ToolBarInfo);
250 }
251
252 void CadToolBar::showToolBarModify()
253 {
254         showToolBar(RS2::ToolBarModify);
255 }
256
257 void CadToolBar::showToolBarSnap()
258 {
259         showToolBar(RS2::ToolBarSnap);
260 }
261
262 void CadToolBar::showToolBarDim()
263 {
264         showToolBar(RS2::ToolBarDim);
265 }
266
267 void CadToolBar::showToolBarSelect()
268 {
269         showToolBarSelect(NULL, -1);
270 }
271
272 void CadToolBar::showToolBarSelect(RS_ActionInterface * selectAction, int nextAction)
273 {
274         tbSelect->setNextAction(nextAction);
275         tbSelect->setSelectAction(selectAction);
276         showToolBar(RS2::ToolBarSelect);
277 }