]> Shamusworld >> Repos - architektonas/blob - src/forms/cadtoolbar.cpp
d988c7ca3895c764d8e72fb2d2c3bb8ab778c931
[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         currentTb = tbMain;
106
107         tbPoints = new CadToolBarPoints(this);
108         tbLines = new CadToolBarLines(this);
109         tbArcs = new CadToolBarArcs(this);
110         tbCircles = new CadToolBarCircles(this);
111         tbEllipses = new CadToolBarEllipses(this);
112         tbSplines = new CadToolBarSplines(this);
113         tbPolylines = new CadToolBarPolylines(this);
114         tbDim = new CadToolBarDim(this);
115         tbInfo = new CadToolBarInfo(this);
116         tbModify = new CadToolBarModify(this);
117         tbSnap = new CadToolBarSnap(this);
118         tbSelect = new CadToolBarSelect(this);
119
120         tbPoints->hide();
121         tbLines->hide();
122         tbArcs->hide();
123         tbCircles->hide();
124         tbEllipses->hide();
125         tbSplines->hide();
126         tbPolylines->hide();
127         tbDim->hide();
128         tbInfo->hide();
129         tbModify->hide();
130         tbSnap->hide();
131         tbSelect->hide();
132 }
133
134 void CadToolBar::showToolBar(int id)
135 {
136         QWidget * newTb = NULL;
137
138         switch (id)
139         {
140         default:
141         case RS2::ToolBarMain:
142                 newTb = tbMain;
143                 break;
144         case RS2::ToolBarPoints:
145                 newTb = tbPoints;
146                 break;
147         case RS2::ToolBarLines:
148                 newTb = tbLines;
149                 break;
150         case RS2::ToolBarArcs:
151                 newTb = tbArcs;
152                 break;
153         case RS2::ToolBarEllipses:
154                 newTb = tbEllipses;
155                 break;
156         case RS2::ToolBarSplines:
157                 newTb = tbSplines;
158                 break;
159         case RS2::ToolBarPolylines:
160                 newTb = tbPolylines;
161                 break;
162         case RS2::ToolBarCircles:
163                 newTb = tbCircles;
164                 break;
165         case RS2::ToolBarInfo:
166                 newTb = tbInfo;
167                 break;
168         case RS2::ToolBarModify:
169                 newTb = tbModify;
170                 break;
171         case RS2::ToolBarDim:
172                 newTb = tbDim;
173                 break;
174         case RS2::ToolBarSnap:
175                 newTb = tbSnap;
176                 break;
177         case RS2::ToolBarSelect:
178                 newTb = tbSelect;
179                 break;
180         }
181
182         if (currentTb == newTb)
183                 return;
184
185         if (currentTb)
186                 currentTb->hide();
187
188         currentTb = newTb;
189
190         if (currentTb)
191                 currentTb->show();
192 }
193
194 void CadToolBar::showToolBarMain()
195 {
196         showToolBar(RS2::ToolBarMain);
197 }
198
199 void CadToolBar::showToolBarPoints()
200 {
201         showToolBar(RS2::ToolBarPoints);
202 }
203
204 void CadToolBar::showToolBarLines()
205 {
206         showToolBar(RS2::ToolBarLines);
207 }
208
209 void CadToolBar::showToolBarArcs()
210 {
211         showToolBar(RS2::ToolBarArcs);
212 }
213
214 void CadToolBar::showToolBarEllipses()
215 {
216         showToolBar(RS2::ToolBarEllipses);
217 }
218
219 void CadToolBar::showToolBarSplines()
220 {
221         showToolBar(RS2::ToolBarSplines);
222 }
223
224 void CadToolBar::showToolBarPolylines()
225 {
226         showToolBar(RS2::ToolBarPolylines);
227 }
228
229 void CadToolBar::showToolBarCircles()
230 {
231         showToolBar(RS2::ToolBarCircles);
232 }
233
234 void CadToolBar::showToolBarInfo()
235 {
236         showToolBar(RS2::ToolBarInfo);
237 }
238
239 void CadToolBar::showToolBarModify()
240 {
241         showToolBar(RS2::ToolBarModify);
242 }
243
244 void CadToolBar::showToolBarSnap()
245 {
246         showToolBar(RS2::ToolBarSnap);
247 }
248
249 void CadToolBar::showToolBarDim()
250 {
251         showToolBar(RS2::ToolBarDim);
252 }
253
254 void CadToolBar::showToolBarSelect()
255 {
256         showToolBarSelect(NULL, -1);
257 }
258
259 void CadToolBar::showToolBarSelect(ActionInterface * selectAction, int nextAction)
260 {
261         tbSelect->setNextAction(nextAction);
262         tbSelect->setSelectAction(selectAction);
263         showToolBar(RS2::ToolBarSelect);
264 }
265
266 QToolButton * CadToolBar::CreateBackButton(QWidget * widget)
267 {
268         QAction * actionBack = new QAction(QIcon(":/res/qg_back"), tr("Back"), widget);
269         QToolButton * button = new QToolButton(widget);
270         button->setDefaultAction(actionBack);
271         QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
272         button->setSizePolicy(policy);
273         connect(button, SIGNAL(triggered(QAction *)), this, SLOT(back()));
274
275         return button;
276 }
277
278 QToolButton * CadToolBar::CreateToolButton(QAction * action)
279 {
280         QToolButton * button = new QToolButton();
281         button->setDefaultAction(action);
282         button->setIconSize(QSize(18, 18));
283
284         return button;
285 }