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