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 "qg_dimlinearoptions.h"
27 
28 #include "rs_settings.h"
29 #include "rs_math.h"
30 #include "rs_debug.h"
31 
32 #include "ui_qg_dimlinearoptions.h"
33 #include "rs_actiondimlinear.h"
34 
35 /*
36  *  Constructs a QG_DimLinearOptions as a child of 'parent', with the
37  *  name 'name' and widget flags set to 'f'.
38  */
QG_DimLinearOptions(QWidget * parent,Qt::WindowFlags fl)39 QG_DimLinearOptions::QG_DimLinearOptions(QWidget* parent, Qt::WindowFlags fl)
40     : QWidget(parent, fl)
41 	, ui(new Ui::Ui_DimLinearOptions{})
42 {
43 	ui->setupUi(this);
44 }
45 
46 /*
47  *  Destroys the object and frees any allocated resources
48  */
~QG_DimLinearOptions()49 QG_DimLinearOptions::~QG_DimLinearOptions()
50 {
51 	saveSettings();
52 }
53 
54 /*
55  *  Sets the strings of the subwidgets using the current
56  *  language.
57  */
languageChange()58 void QG_DimLinearOptions::languageChange()
59 {
60 	ui->retranslateUi(this);
61 }
62 
saveSettings()63 void QG_DimLinearOptions::saveSettings() {
64     RS_SETTINGS->beginGroup("/Dimension");
65 	RS_SETTINGS->writeEntry("/Angle", ui->leAngle->text());
66     RS_SETTINGS->endGroup();
67 }
68 
setAction(RS_ActionInterface * a,bool update)69 void QG_DimLinearOptions::setAction(RS_ActionInterface* a, bool update) {
70     if (a && a->rtti()==RS2::ActionDimLinear) {
71 		action = static_cast<RS_ActionDimLinear*>(a);
72 
73         QString sa;
74         if (!update) {
75             sa = QString("%1").arg(RS_Math::rad2deg(action->getAngle()));
76         } else {
77             RS_SETTINGS->beginGroup("/Dimension");
78             sa = RS_SETTINGS->readEntry("/Angle", "0.0");
79             RS_SETTINGS->endGroup();
80         }
81 		ui->leAngle->setText(sa);
82     } else {
83         RS_DEBUG->print(RS_Debug::D_ERROR,
84                         "QG_DimLinearOptions::setAction: wrong action type");
85 		action = nullptr;
86     }
87 }
88 
updateAngle(const QString & a)89 void QG_DimLinearOptions::updateAngle(const QString & a) {
90     if (action) {
91         action->setAngle(RS_Math::deg2rad(RS_Math::eval(a)));
92     }
93 }
94 
setHor()95 void QG_DimLinearOptions::setHor() {
96 	ui->leAngle->setText("0");
97 }
98 
setVer()99 void QG_DimLinearOptions::setVer() {
100 	ui->leAngle->setText("90");
101 }
102