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 "cadtoolbar.h"
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"
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)
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));
48 //hm. here maybe? Yesh!
50 ((QToolBar *)parent)->addWidget(this);
53 CadToolBar::~CadToolBar()
58 * @return Pointer to action handler or NULL.
60 QG_ActionHandler * CadToolBar::getActionHandler()
66 * Called from the sub toolbar
68 void CadToolBar::back()
74 * Called from the application.
76 void CadToolBar::forceNext()
78 if (currentTb && currentTb == tbSelect)
79 tbSelect->runNextAction();
82 void CadToolBar::mouseReleaseEvent(QMouseEvent * e)
84 if (e->button() == Qt::RightButton)
91 void CadToolBar::contextMenuEvent(QContextMenuEvent * e)
97 * Creates all tool bars and shows the main toolbar.
99 * @param ah Pointer to action handler which will deal with the actions in this tool bar.
101 void CadToolBar::createSubToolBars(QG_ActionHandler * ah)
104 tbMain = new CadToolBarMain(this);
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);
134 void CadToolBar::showToolBar(int id)
136 QWidget * newTb = NULL;
141 case RS2::ToolBarMain:
144 case RS2::ToolBarPoints:
147 case RS2::ToolBarLines:
150 case RS2::ToolBarArcs:
153 case RS2::ToolBarEllipses:
156 case RS2::ToolBarSplines:
159 case RS2::ToolBarPolylines:
162 case RS2::ToolBarCircles:
165 case RS2::ToolBarInfo:
168 case RS2::ToolBarModify:
171 case RS2::ToolBarDim:
174 case RS2::ToolBarSnap:
177 case RS2::ToolBarSelect:
182 if (currentTb == newTb)
194 void CadToolBar::showToolBarMain()
196 showToolBar(RS2::ToolBarMain);
199 void CadToolBar::showToolBarPoints()
201 showToolBar(RS2::ToolBarPoints);
204 void CadToolBar::showToolBarLines()
206 showToolBar(RS2::ToolBarLines);
209 void CadToolBar::showToolBarArcs()
211 showToolBar(RS2::ToolBarArcs);
214 void CadToolBar::showToolBarEllipses()
216 showToolBar(RS2::ToolBarEllipses);
219 void CadToolBar::showToolBarSplines()
221 showToolBar(RS2::ToolBarSplines);
224 void CadToolBar::showToolBarPolylines()
226 showToolBar(RS2::ToolBarPolylines);
229 void CadToolBar::showToolBarCircles()
231 showToolBar(RS2::ToolBarCircles);
234 void CadToolBar::showToolBarInfo()
236 showToolBar(RS2::ToolBarInfo);
239 void CadToolBar::showToolBarModify()
241 showToolBar(RS2::ToolBarModify);
244 void CadToolBar::showToolBarSnap()
246 showToolBar(RS2::ToolBarSnap);
249 void CadToolBar::showToolBarDim()
251 showToolBar(RS2::ToolBarDim);
254 void CadToolBar::showToolBarSelect()
256 showToolBarSelect(NULL, -1);
259 void CadToolBar::showToolBarSelect(ActionInterface * selectAction, int nextAction)
261 tbSelect->setNextAction(nextAction);
262 tbSelect->setSelectAction(selectAction);
263 showToolBar(RS2::ToolBarSelect);
266 QToolButton * CadToolBar::CreateBackButton(QWidget * widget)
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()));
278 QToolButton * CadToolBar::CreateToolButton(QAction * action)
280 QToolButton * button = new QToolButton();
281 button->setDefaultAction(action);
282 button->setIconSize(QSize(18, 18));