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) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 #include<cassert>
27 #include<QAction>
28 #include "qg_cadtoolbarellipses.h"
29 #include "qg_cadtoolbar.h"
30 #include "qg_actionhandler.h"
31 
32 /*
33  *  Constructs a QG_CadToolBarEllipses as a child of 'parent', with the
34  *  name 'name' and widget flags set to 'f'.
35  */
QG_CadToolBarEllipses(QG_CadToolBar * parent,Qt::WindowFlags fl)36 QG_CadToolBarEllipses::QG_CadToolBarEllipses(QG_CadToolBar* parent, Qt::WindowFlags fl)
37 	:LC_CadToolBarInterface(parent, fl)
38 {
39 	initToolBars();
40 }
41 
42 
addSubActions(const std::vector<QAction * > & actions,bool addGroup)43 void QG_CadToolBarEllipses::addSubActions(const std::vector<QAction*>& actions, bool addGroup)
44 {
45 	LC_CadToolBarInterface::addSubActions(actions, addGroup);
46 	std::vector<QAction**> const buttons={
47 		&bEllipseAxes, &bEllipseArcAxes , &bEllipseFociPoint ,
48 		&bEllipse4Points , &bEllipseCenter3Points , &bEllipseInscribe
49 	};
50 
51 	assert(buttons.size()==actions.size());
52 
53 	for(size_t i=0; i<buttons.size(); ++i)
54 		*buttons[i]=actions[i];
55 }
56 
57 //restore action from checked button
restoreAction()58 void QG_CadToolBarEllipses::restoreAction()
59 {
60 	if(!(actionHandler && bEllipseAxes)) return;
61 	if ( bEllipseAxes ->isChecked() ) {
62         actionHandler->slotDrawEllipseAxis();
63         return;
64     }
65     if ( bEllipseArcAxes ->isChecked() ) {
66         actionHandler->slotDrawEllipseArcAxis();
67         return;
68     }
69     if ( bEllipseFociPoint ->isChecked() ) {
70         actionHandler->slotDrawEllipseFociPoint();
71         return;
72     }
73     if ( bEllipse4Points ->isChecked() ) {
74         actionHandler->slotDrawEllipse4Points();
75         return;
76     }
77     if ( bEllipseCenter3Points ->isChecked() ) {
78         actionHandler->slotDrawEllipseCenter3Points();
79         return;
80     }
81     if ( bEllipseInscribe ->isChecked() ) {
82         actionHandler->slotDrawEllipseInscribe();
83         return;
84     }
85     //clear all action
86 	m_pHidden->setChecked(true);
87     RS_ActionInterface* currentAction =actionHandler->getCurrentAction();
88 	if(currentAction ) {
89         currentAction->finish(false); //finish the action, but do not update toolBar
90     }
91 }
92 
resetToolBar()93 void QG_CadToolBarEllipses::resetToolBar()
94 {
95 	m_pHidden->setChecked(true);
96 }
on_bBack_clicked()97 void QG_CadToolBarEllipses::on_bBack_clicked()
98 {
99 	finishCurrentAction(true);
100 	cadToolBar->showPreviousToolBar();
101 }
102 
103 
showCadToolBar(RS2::ActionType actionType)104 void QG_CadToolBarEllipses::showCadToolBar(RS2::ActionType actionType) {
105 	if(!bEllipseAxes) return;
106     switch(actionType){
107     case RS2::ActionDrawEllipseAxis:
108         bEllipseAxes ->setChecked(true);
109         return;
110     case RS2::ActionDrawEllipseArcAxis:
111         bEllipseArcAxes ->setChecked(true);
112         return;
113     case RS2::ActionDrawEllipseFociPoint:
114         bEllipseFociPoint ->setChecked(true);
115         return;
116     case RS2::ActionDrawEllipse4Points:
117         bEllipse4Points ->setChecked(true);
118         return;
119     case RS2::ActionDrawEllipseCenter3Points:
120         bEllipseCenter3Points ->setChecked(true);
121         return;
122     case RS2::ActionDrawEllipseInscribe:
123         bEllipseInscribe ->setChecked(true);
124         return;
125         default:
126 		m_pHidden->setChecked(true);
127         return;
128     }
129 }
130