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_cadtoolbarpolylines.h"
29 #include "qg_cadtoolbar.h"
30 #include "qg_actionhandler.h"
31 
32 /*
33  *  Constructs a QG_CadToolBarPolylines as a child of 'parent', with the
34  *  name 'name' and widget flags set to 'f'.
35  */
QG_CadToolBarPolylines(QG_CadToolBar * parent,Qt::WindowFlags fl)36 QG_CadToolBarPolylines::QG_CadToolBarPolylines(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_CadToolBarPolylines::addSubActions(const std::vector<QAction*>& actions, bool addGroup)
44 {
45 	LC_CadToolBarInterface::addSubActions(actions, addGroup);
46 	std::vector<QAction**> const buttons={
47 		&bPolyline, &bPolylineAdd, &bPolylineAppend, &bPolylineDel,
48 		&bPolylineDelBetween, &bPolylineTrim, &bPolylineEquidistant,
49 		&bPolylineSegment
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 //restore action from checked button
restoreAction()59 void QG_CadToolBarPolylines::restoreAction()
60 {
61 	if(!(actionHandler && bPolyline)) return;
62 	if ( bPolyline ->isChecked() ) {
63         actionHandler->slotDrawPolyline();
64         return;
65     }
66     if ( bPolylineAdd ->isChecked() ) {
67         actionHandler->slotPolylineAdd();
68         return;
69     }
70     if ( bPolylineAppend ->isChecked() ) {
71         actionHandler->slotPolylineAppend();
72         return;
73     }
74     if ( bPolylineDel ->isChecked() ) {
75         actionHandler->slotPolylineDel();
76         return;
77     }
78     if ( bPolylineDelBetween ->isChecked() ) {
79         actionHandler->slotPolylineDelBetween();
80         return;
81     }
82     if ( bPolylineTrim ->isChecked() ) {
83         actionHandler->slotPolylineTrim();
84         return;
85     }
86     if ( bPolylineEquidistant ->isChecked() ) {
87         actionHandler->slotPolylineEquidistant();
88         return;
89     }
90     if ( bPolylineSegment ->isChecked() ) {
91         actionHandler->slotPolylineSegment();
92         return;
93     }
94 	m_pHidden->setChecked(true);
95     RS_ActionInterface* currentAction =actionHandler->getCurrentAction();
96 	if(currentAction ) {
97         currentAction->finish(false); //finish the action, but do not update toolBar
98     }
99 }
100 
resetToolBar()101 void QG_CadToolBarPolylines::resetToolBar()
102 {
103 	m_pHidden->setChecked(true);
104 }
105 
on_bBack_clicked()106 void QG_CadToolBarPolylines::on_bBack_clicked()
107 {
108 	finishCurrentAction(true);
109 	cadToolBar->showPreviousToolBar();
110 }
111 
showCadToolBar(RS2::ActionType actionType)112 void QG_CadToolBarPolylines::showCadToolBar(RS2::ActionType actionType){
113 	if(!bPolyline) return;
114     switch(actionType){
115     case RS2::ActionDrawPolyline:
116         bPolyline->setChecked(true);
117         return;
118     case RS2::ActionPolylineAdd:
119         bPolylineAdd->setChecked(true);
120         return;
121     case RS2::ActionPolylineAppend:
122         bPolylineAppend->setChecked(true);
123         return;
124     case RS2::ActionPolylineDel:
125         bPolylineDel->setChecked(true);
126         return;
127     case RS2::ActionPolylineDelBetween:
128         bPolylineDelBetween->setChecked(true);
129         return;
130     case RS2::ActionPolylineTrim:
131         bPolylineTrim->setChecked(true);
132         return;
133     case RS2::ActionPolylineEquidistant:
134         bPolylineEquidistant->setChecked(true);
135         return;
136     case RS2::ActionPolylineSegment:
137         bPolylineSegment->setChecked(true);
138         return;
139         default:
140 		m_pHidden->setChecked(true);
141         return;
142     }
143 }
144 
145 //EOF
146