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
27 #include<cassert>
28 #include<QAction>
29 #include "qg_cadtoolbarinfo.h"
30 #include "qg_cadtoolbar.h"
31 #include "qg_actionhandler.h"
32
33 /*
34 * Constructs a QG_CadToolBarInfo as a child of 'parent', with the
35 * name 'name' and widget flags set to 'f'.
36 */
QG_CadToolBarInfo(QG_CadToolBar * parent,Qt::WindowFlags fl)37 QG_CadToolBarInfo::QG_CadToolBarInfo(QG_CadToolBar* parent, Qt::WindowFlags fl)
38 :LC_CadToolBarInterface(parent, fl)
39 {
40 initToolBars();
41 }
42
addSubActions(const std::vector<QAction * > & actions,bool addGroup)43 void QG_CadToolBarInfo::addSubActions(const std::vector<QAction*>& actions, bool addGroup)
44 {
45 LC_CadToolBarInterface::addSubActions(actions, addGroup);
46 std::vector<QAction**> const buttons={
47 &bDist, &bDist2, &bAngle, &bTotalLength, &bArea
48 };
49
50 assert(buttons.size()==actions.size());
51
52 for(size_t i=0; i<buttons.size(); ++i)
53 *buttons[i]=actions[i];
54 }
55
56 //restore action from checked button
restoreAction()57 void QG_CadToolBarInfo::restoreAction()
58 {
59 if(!(actionHandler && bDist)) return;
60 //clear all action
61 if ( bDist ->isChecked() ) {
62 actionHandler->slotInfoDist();
63 return;
64 }
65 if ( bDist2 ->isChecked() ) {
66 actionHandler->slotInfoDist2();
67 return;
68 }
69 if ( bAngle ->isChecked() ) {
70 actionHandler->slotInfoAngle();
71 return;
72 }
73 if ( bTotalLength ->isChecked() ) {
74 actionHandler->slotInfoTotalLength();
75 return;
76 }
77 if ( bArea ->isChecked() ) {
78 actionHandler->slotInfoArea();
79 return;
80 }
81 //default to measure point to point distance
82 //bDist->setChecked(true);
83 //actionHandler->slotInfoDist();
84 m_pHidden->setChecked(true);
85 RS_ActionInterface* currentAction =actionHandler->getCurrentAction();
86 if(currentAction ) {
87 currentAction->finish(false); //finish the action, but do not update toolBar
88 }
89 }
resetToolBar()90 void QG_CadToolBarInfo::resetToolBar()
91 {
92 m_pHidden->setChecked(true);
93 }
94
on_bBack_clicked()95 void QG_CadToolBarInfo::on_bBack_clicked()
96 {
97 finishCurrentAction(true);
98 cadToolBar->showPreviousToolBar();
99 }
100
showCadToolBar(RS2::ActionType actionType)101 void QG_CadToolBarInfo:: showCadToolBar(RS2::ActionType actionType){
102 if(!bDist) return;
103 switch(actionType){
104 // case RS2::ActionInfoInside:
105 case RS2::ActionInfoDist:
106 bDist->setChecked(true);
107 return;
108 case RS2::ActionInfoDist2:
109 bDist2->setChecked(true);
110 return;
111 case RS2::ActionInfoAngle:
112 bAngle->setChecked(true);
113 return;
114 case RS2::ActionInfoTotalLength:
115 bTotalLength->setChecked(true);
116 return;
117 // case RS2::ActionInfoTotalLengthNoSelect:
118 case RS2::ActionInfoArea:
119 bArea->setChecked(true);
120 return;
121 default:
122 m_pHidden->setChecked(true);
123 }
124 }
125
126 //EOF
127