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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/10/2010 Created this file. :-)
17 #include "cadtoolbar.h"
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"
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)
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));
50 //hm. here maybe? Yesh!
52 ((QToolBar *)parent)->addWidget(this);
55 CadToolBar::~CadToolBar()
60 * @return Pointer to action handler or NULL.
62 ActionHandler * CadToolBar::getActionHandler()
68 * Called from the sub toolbar
70 void CadToolBar::back()
76 * Called from the application.
78 void CadToolBar::forceNext()
80 if (currentTb && currentTb == tbSelect)
81 tbSelect->runNextAction();
84 void CadToolBar::mouseReleaseEvent(QMouseEvent * e)
86 if (e->button() == Qt::RightButton)
93 void CadToolBar::contextMenuEvent(QContextMenuEvent * e)
99 * Creates all tool bars and shows the main toolbar.
101 * @param ah Pointer to action handler which will deal with the actions in this tool bar.
103 void CadToolBar::createSubToolBars(ActionHandler * ah)
106 tbMain = new CadToolBarMain(this);
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);
136 void CadToolBar::showToolBar(int id)
138 QWidget * newTb = NULL;
143 case RS2::ToolBarMain:
146 case RS2::ToolBarPoints:
149 case RS2::ToolBarLines:
152 case RS2::ToolBarArcs:
155 case RS2::ToolBarEllipses:
158 case RS2::ToolBarSplines:
161 case RS2::ToolBarPolylines:
164 case RS2::ToolBarCircles:
167 case RS2::ToolBarInfo:
170 case RS2::ToolBarModify:
173 case RS2::ToolBarDim:
176 case RS2::ToolBarSnap:
179 case RS2::ToolBarSelect:
184 if (currentTb == newTb)
196 void CadToolBar::showToolBarMain()
198 showToolBar(RS2::ToolBarMain);
201 void CadToolBar::showToolBarPoints()
203 showToolBar(RS2::ToolBarPoints);
206 void CadToolBar::showToolBarLines()
208 showToolBar(RS2::ToolBarLines);
211 void CadToolBar::showToolBarArcs()
213 showToolBar(RS2::ToolBarArcs);
216 void CadToolBar::showToolBarEllipses()
218 showToolBar(RS2::ToolBarEllipses);
221 void CadToolBar::showToolBarSplines()
223 showToolBar(RS2::ToolBarSplines);
226 void CadToolBar::showToolBarPolylines()
228 showToolBar(RS2::ToolBarPolylines);
231 void CadToolBar::showToolBarCircles()
233 showToolBar(RS2::ToolBarCircles);
236 void CadToolBar::showToolBarInfo()
238 showToolBar(RS2::ToolBarInfo);
241 void CadToolBar::showToolBarModify()
243 showToolBar(RS2::ToolBarModify);
246 void CadToolBar::showToolBarSnap()
248 showToolBar(RS2::ToolBarSnap);
251 void CadToolBar::showToolBarDim()
253 showToolBar(RS2::ToolBarDim);
256 void CadToolBar::showToolBarSelect()
258 showToolBarSelect(NULL, -1);
261 void CadToolBar::showToolBarSelect(ActionInterface * selectAction, int nextAction)
263 tbSelect->setNextAction(nextAction);
264 tbSelect->setSelectAction(selectAction);
265 showToolBar(RS2::ToolBarSelect);
268 QToolButton * CadToolBar::CreateBackButton(QWidget * widget)
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()));
280 QToolButton * CadToolBar::CreateToolButton(QAction * action)
282 QToolButton * button = new QToolButton();
283 button->setDefaultAction(action);
284 button->setIconSize(QSize(18, 18));