1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2014 Dongxu Li (dongxuli2011@gmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 **********************************************************************/
22 #include<cassert>
23 #include<QAction>
24 #include "qg_cadtoolbarsplines.h"
25 #include "qg_cadtoolbar.h"
26 #include "qg_actionhandler.h"
27 
28 /*
29  *  Constructs a QG_CadToolBarSplines as a child of 'parent', with the
30  *  name 'name' and widget flags set to 'f'.
31  */
QG_CadToolBarSplines(QG_CadToolBar * parent,Qt::WindowFlags fl)32 QG_CadToolBarSplines::QG_CadToolBarSplines(QG_CadToolBar* parent, Qt::WindowFlags fl)
33 	:LC_CadToolBarInterface(parent, fl)
34 {
35 	initToolBars();
36 }
37 
addSubActions(const std::vector<QAction * > & actions,bool addGroup)38 void QG_CadToolBarSplines::addSubActions(const std::vector<QAction*>& actions, bool addGroup)
39 {
40 	LC_CadToolBarInterface::addSubActions(actions, addGroup);
41 	std::vector<QAction**> const buttons={&bSpline, &bSplineInt};
42 	assert(buttons.size()==actions.size());
43 
44 	for(size_t i=0; i<buttons.size(); ++i)
45 		*buttons[i]=actions[i];
46 
47 }
48 
49 //restore action from checked button
restoreAction()50 void QG_CadToolBarSplines::restoreAction()
51 {
52 	if(!(actionHandler&&bSpline)) return;
53     if ( bSpline ->isChecked() ) {
54         actionHandler->slotDrawSpline();
55         return;
56     }
57     if(bSplineInt->isChecked()){
58         actionHandler->slotDrawSplinePoints();
59         return;
60     }
61 	m_pHidden->setChecked(true);
62     RS_ActionInterface* currentAction =actionHandler->getCurrentAction();
63 	if(currentAction ) {
64         currentAction->finish(false); //finish the action, but do not update toolBar
65     }
66 }
67 
resetToolBar()68 void QG_CadToolBarSplines::resetToolBar()
69 {
70 	m_pHidden->setChecked(true);
71 }
72 
73 
showCadToolBar(RS2::ActionType actionType)74 void QG_CadToolBarSplines::showCadToolBar(RS2::ActionType actionType) {
75 	if(!bSpline) return;
76     switch(actionType){
77     case RS2::ActionDrawSpline:
78         bSpline->setChecked(true);
79         return;
80     case RS2::ActionDrawSplinePoints:
81         bSplineInt->setChecked(true);
82         return;
83     default:
84 		m_pHidden->setChecked(true);
85         return;
86     }
87 }
88 
on_bBack_clicked()89 void QG_CadToolBarSplines::on_bBack_clicked()
90 {
91 	finishCurrentAction(true);
92    LC_CadToolBarInterface::back();
93 }
94