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_cadtoolbarmodify.h"
29 #include "qg_cadtoolbar.h"
30 #include "qg_actionhandler.h"
31 
32 /*
33  *  Constructs a QG_CadToolBarModify as a child of 'parent', with the
34  *  name 'name' and widget flags set to 'f'.
35  */
QG_CadToolBarModify(QG_CadToolBar * parent,Qt::WindowFlags fl)36 QG_CadToolBarModify::QG_CadToolBarModify(QG_CadToolBar* parent, Qt::WindowFlags fl)
37 	:LC_CadToolBarInterface(parent, fl)
38 {
39 	initToolBars();
40 }
41 
addSubActions(const std::vector<QAction * > & actions,bool addGroup)42 void QG_CadToolBarModify::addSubActions(const std::vector<QAction*>& actions, bool addGroup)
43 {
44 	LC_CadToolBarInterface::addSubActions(actions, addGroup);
45 	std::vector<QAction**> const buttons={
46 		&bMove, &bRotate, &bScale, &bMirror, &bMoveRotate, &bRotate2,
47 		&bRevertDirection, &bTrim, &bTrim2, &bTrimAmount, &bOffset, &bBevel,
48 		&bRound, &bCut, &bStretch, &bEntity, &bAttributes, &bDelete,
49 		&bDeleteQuick, &bExplodeText, &bExplode
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 
58 
59 //restore action from checked
restoreAction()60 void QG_CadToolBarModify::restoreAction() {
61 	if(!(actionHandler&&bMove)) return;
62 	if ( bMove ->isChecked() ) {
63         actionHandler->slotModifyMove();
64         return;
65     }
66     if ( bRotate ->isChecked() ) {
67         actionHandler->slotModifyRotate();
68         return;
69     }
70     if ( bScale ->isChecked() ) {
71         actionHandler->slotModifyScale();
72         return;
73     }
74     if ( bMirror ->isChecked() ) {
75         actionHandler->slotModifyMirror();
76         return;
77     }
78     if ( bMoveRotate ->isChecked() ) {
79         actionHandler->slotModifyMoveRotate();
80         return;
81     }
82     if ( bRotate2 ->isChecked() ) {
83         actionHandler->slotModifyRotate2();
84         return;
85     }
86     if ( bTrim ->isChecked() ) {
87         actionHandler->slotModifyTrim();
88         return;
89     }
90     if ( bTrim2 ->isChecked() ) {
91         actionHandler->slotModifyTrim2();
92         return;
93     }
94     if ( bTrimAmount ->isChecked() ) {
95         actionHandler->slotModifyTrimAmount();
96         return;
97     }
98     if ( bBevel ->isChecked() ) {
99         actionHandler->slotModifyBevel();
100         return;
101     }
102     if ( bRound ->isChecked() ) {
103         actionHandler->slotModifyRound();
104         return;
105     }
106     if ( bCut ->isChecked() ) {
107         actionHandler->slotModifyCut();
108         return;
109     }
110     if ( bStretch ->isChecked() ) {
111         actionHandler->slotModifyStretch();
112         return;
113     }
114     if ( bEntity ->isChecked() ) {
115         actionHandler->slotModifyEntity();
116         return;
117     }
118     if ( bAttributes ->isChecked() ) {
119         actionHandler->slotModifyAttributes();
120         return;
121     }
122     if ( bDelete ->isChecked() ) {
123         actionHandler->slotModifyDelete();
124         return;
125     }
126     if ( bExplode ->isChecked() ) {
127         actionHandler->slotBlocksExplode();
128         return;
129     }
130     if ( bExplodeText ->isChecked() ) {
131         actionHandler->slotModifyExplodeText();
132         return;
133 	}
134     if ( bOffset ->isChecked() ) {
135         actionHandler->slotModifyOffset();
136         return;
137     }
138     if ( bRevertDirection ->isChecked() ) {
139         actionHandler->slotModifyRevertDirection();
140         return;
141     }
142 	m_pHidden->setChecked(true);
143     //clear all action
144     RS_ActionInterface* currentAction =actionHandler->getCurrentAction();
145 	if(currentAction ) {
146         currentAction->finish(false); //finish the action, but do not update toolBar
147     }
148 }
149 
resetToolBar()150 void QG_CadToolBarModify::resetToolBar()
151 {
152 	m_pHidden->setChecked(true);
153 }
154 
on_bBack_clicked()155 void QG_CadToolBarModify::on_bBack_clicked()
156 {
157 	finishCurrentAction(true);
158    cadToolBar->showToolBar(RS2::ToolBarMain);
159 }
160 
showCadToolBar(RS2::ActionType actionType)161 void QG_CadToolBarModify::showCadToolBar(RS2::ActionType actionType) {
162 	if(!bAttributes) return;
163     switch(actionType){
164     case RS2::ActionModifyAttributes:
165         bAttributes->setChecked(true);
166         return;
167     case RS2::ActionModifyDelete:
168         bDelete->setChecked(true);
169         return;
170 //    case RS2::ActionModifyDeleteQuick:
171 //    case RS2::ActionModifyDeleteFree:
172     case RS2::ActionModifyMove:
173         bMove->setChecked(true);
174         return;
175 //    case RS2::ActionModifyMoveNoSelect:
176     case RS2::ActionModifyRotate:
177         bRotate->setChecked(true);
178         return;
179 //    case RS2::ActionModifyRotateNoSelect:
180     case RS2::ActionModifyScale:
181         bScale->setChecked(true);
182         return;
183 //    case RS2::ActionModifyScaleNoSelect:
184     case RS2::ActionModifyMirror:
185         bMirror->setChecked(true);
186         return;
187 //    case RS2::ActionModifyMirrorNoSelect:
188     case RS2::ActionModifyMoveRotate:
189         bMoveRotate->setChecked(true);
190         return;
191 //    case RS2::ActionModifyMoveRotateNoSelect:
192     case RS2::ActionModifyRotate2:
193         bRotate2->setChecked(true);
194         return;
195 //    case RS2::ActionModifyRotate2NoSelect:
196     case RS2::ActionModifyEntity:
197         bEntity->setChecked(true);
198         return;
199     case RS2::ActionModifyTrim:
200         bTrim->setChecked(true);
201         return;
202     case RS2::ActionModifyTrim2:
203         bTrim2->setChecked(true);
204         return;
205     case RS2::ActionModifyTrimAmount:
206         bTrimAmount->setChecked(true);
207         return;
208     case RS2::ActionModifyCut:
209         bCut->setChecked(true);
210         return;
211     case RS2::ActionModifyStretch:
212         bStretch->setChecked(true);
213         return;
214     case RS2::ActionModifyBevel:
215         bBevel->setChecked(true);
216         return;
217     case RS2::ActionModifyRound:
218         bRound->setChecked(true);
219         return;
220     case RS2::ActionModifyOffset:
221         bOffset->setChecked(true);
222         return;
223     case RS2::ActionModifyRevertDirection:
224         bRevertDirection->setChecked(true);
225         return;
226 //    case RS2::ActionModifyExplodeText:
227 //        bEntityText->setChecked(true);
228         //    case RS2::ActionModifyOffsetNoSelect:
229     default:
230 		m_pHidden->setChecked(true);
231         return;
232     }
233 }
234