1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2011 Dongxu Li ( dongxuli2011@gmail.com )
6 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
7 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
8 **
9 **
10 
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License for more details.
20 
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24 
25 ** This copyright notice MUST APPEAR in all copies of the script!
26 **
27 **********************************************************************/
28 
29 #include "qg_modifyoffsetoptions.h"
30 
31 #include "rs_actionmodifyoffset.h"
32 #include "rs_settings.h"
33 #include "ui_qg_modifyoffsetoptions.h"
34 #include "rs_math.h"
35 
36 /*
37  *  Constructs a QG_ModifyOffsetOptions as a child of 'parent', with the
38  *  name 'name' and widget flags set to 'f'.
39  */
QG_ModifyOffsetOptions(QWidget * parent,Qt::WindowFlags fl)40 QG_ModifyOffsetOptions::QG_ModifyOffsetOptions(QWidget* parent, Qt::WindowFlags fl)
41     : QWidget(parent, fl)
42 	, ui(new Ui::Ui_ModifyOffsetOptions{})
43 {
44 	ui->setupUi(this);
45 }
46 
47 /*
48  *  Destroys the object and frees any allocated resources
49  */
~QG_ModifyOffsetOptions()50 QG_ModifyOffsetOptions::~QG_ModifyOffsetOptions()
51 {
52 	saveSettings();
53 }
54 
55 /*
56  *  Sets the strings of the subwidgets using the current
57  *  language.
58  */
languageChange()59 void QG_ModifyOffsetOptions::languageChange()
60 {
61 	ui->retranslateUi(this);
62 }
63 
saveSettings()64 void QG_ModifyOffsetOptions::saveSettings() {
65     RS_SETTINGS->beginGroup("/Draw");
66 	RS_SETTINGS->writeEntry("/ModifyOffsetDistance", ui->leDist->text());
67     RS_SETTINGS->endGroup();
68 }
69 
setDist(double & d,bool initial)70 void QG_ModifyOffsetOptions::setDist(double& d, bool initial) {
71     dist = &d;
72         bool ok;
73     if(initial) {
74         RS_SETTINGS->beginGroup("/Draw");
75         QString r = RS_SETTINGS->readEntry("/ModifyOffsetDistance", "1.0");
76         RS_SETTINGS->endGroup();
77 
78 		ui->leDist->setText(r);
79         *dist=RS_Math::eval(r,&ok);
80 		if (!ok) *dist=1.;
81     } else {
82 		*dist=RS_Math::eval(ui->leDist->text(),&ok);
83 		if (!ok) *dist=1.;
84     }
85 }
86 
updateDist(const QString & d)87 void QG_ModifyOffsetOptions::updateDist(const QString& d) {
88     if (dist) {
89         *dist=RS_Math::eval(d);
90     }
91 }
92