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_cadtoolbarcircles.h"
29 #include "qg_cadtoolbar.h"
30 #include "qg_actionhandler.h"
31
32 /*
33 * Constructs a QG_CadToolBarCircles as a child of 'parent', with the
34 * name 'name' and widget flags set to 'f'.
35 */
QG_CadToolBarCircles(QG_CadToolBar * parent,Qt::WindowFlags fl)36 QG_CadToolBarCircles::QG_CadToolBarCircles(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_CadToolBarCircles::addSubActions(const std::vector<QAction*>& actions, bool addGroup)
44 {
45 LC_CadToolBarInterface::addSubActions(actions, addGroup);
46 std::vector<QAction**> const buttons= {
47 &bCircle, &bCircleCR, &bCircle2P, &bCircle2PR, &bCircle3P,
48 &bCircleParallel, &bCircleInscribe, &bCircleTan1_2P, &bCircleTan2,
49 &bCircleTan2_1P, &bCircleTan3
50 };
51
52 assert(buttons.size()==actions.size());
53
54 for(size_t i=0; i<buttons.size(); ++i)
55 *buttons[i]=actions[i];
56 }
57
back()58 void QG_CadToolBarCircles::back() {
59 if (cadToolBar) {
60 cadToolBar->back();
61 }
62 }
63 //restore action from checked button
restoreAction()64 void QG_CadToolBarCircles::restoreAction()
65 {
66 if(!(actionHandler && bCircle)) return;
67 if ( bCircle ->isChecked() ) {
68 actionHandler->slotDrawCircle();
69 return;
70 }
71 if ( bCircleCR ->isChecked() ) {
72 actionHandler->slotDrawCircleCR();
73 return;
74 }
75 if ( bCircle2P ->isChecked() ) {
76 actionHandler->slotDrawCircle2P();
77 return;
78 }
79 if ( bCircle2PR ->isChecked() ) {
80 actionHandler->slotDrawCircle2PR();
81 return;
82 }
83 if ( bCircle3P ->isChecked() ) {
84 actionHandler->slotDrawCircle3P();
85 return;
86 }
87 if ( bCircleParallel ->isChecked() ) {
88 actionHandler->slotDrawCircleParallel();
89 return;
90 }
91 if ( bCircleInscribe ->isChecked() ) {
92 actionHandler->slotDrawCircleInscribe();
93 return;
94 }
95 if ( bCircleTan2 ->isChecked() ) {
96 actionHandler->slotDrawCircleTan2();
97 return;
98 }
99 if ( bCircleTan3 ->isChecked() ) {
100 actionHandler->slotDrawCircleTan3();
101 return;
102 }
103 if(bCircleTan2_1P->isChecked()){
104 actionHandler->slotDrawCircleTan2_1P();
105 return;
106 }
107 if(bCircleTan1_2P->isChecked()){
108 actionHandler->slotDrawCircleTan1_2P();
109 return;
110 }
111 //clear all action
112 m_pHidden->setChecked(true);
113 RS_ActionInterface* currentAction =actionHandler->getCurrentAction();
114 if(currentAction ) {
115 currentAction->finish(false); //finish the action, but do not update toolBar
116 }
117 }
118
resetToolBar()119 void QG_CadToolBarCircles::resetToolBar()
120 {
121 m_pHidden->setChecked(true);
122 }
123
on_bBack_clicked()124 void QG_CadToolBarCircles::on_bBack_clicked()
125 {
126 finishCurrentAction(true);
127 cadToolBar->showPreviousToolBar();
128 }
129
showCadToolBar(RS2::ActionType actionType)130 void QG_CadToolBarCircles::showCadToolBar(RS2::ActionType actionType){
131 if(!bCircle) return;
132 switch(actionType){
133 case RS2::ActionDrawCircle:
134 bCircle->setChecked(true);
135 return;
136 case RS2::ActionDrawCircle2P:
137 bCircle2P->setChecked(true);
138 return;
139 case RS2::ActionDrawCircle2PR:
140 bCircle2PR->setChecked(true);
141 return;
142 case RS2::ActionDrawCircle3P:
143 bCircle3P->setChecked(true);
144 return;
145 case RS2::ActionDrawCircleCR:
146 bCircleCR->setChecked(true);
147 return;
148 case RS2::ActionDrawCircleParallel:
149 bCircleParallel->setChecked(true);
150 return;
151 case RS2::ActionDrawCircleInscribe:
152 bCircleInscribe->setChecked(true);
153 return;
154 case RS2::ActionDrawCircleTan2:
155 bCircleTan2->setChecked(true);
156 return;
157 case RS2::ActionDrawCircleTan3:
158 bCircleTan3->setChecked(true);
159 return;
160 case RS2::ActionDrawCircleTan1_2P:
161 bCircleTan1_2P->setChecked(true);
162 return;
163 case RS2::ActionDrawCircleTan2_1P:
164 bCircleTan2_1P->setChecked(true);
165 return;
166 default:
167 m_pHidden->setChecked(true);
168 return;
169 }
170 }
171 //EOF
172