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<cmath>
27 #include "qg_dlgrotate.h"
28 
29 #include "rs_settings.h"
30 #include "rs_math.h"
31 #include "rs_modification.h"
32 
33 /*
34  *  Constructs a QG_DlgRotate as a child of 'parent', with the
35  *  name 'name' and widget flags set to 'f'.
36  *
37  *  The dialog will by default be modeless, unless you set 'modal' to
38  *  true to construct a modal dialog.
39  */
QG_DlgRotate(QWidget * parent,bool modal,Qt::WindowFlags fl)40 QG_DlgRotate::QG_DlgRotate(QWidget* parent, bool modal, Qt::WindowFlags fl)
41     : QDialog(parent, fl)
42 {
43     setModal(modal);
44     setupUi(this);
45 
46     init();
47 }
48 
49 /*
50  *  Destroys the object and frees any allocated resources
51  */
~QG_DlgRotate()52 QG_DlgRotate::~QG_DlgRotate()
53 {
54     destroy();
55     // no need to delete child widgets, Qt does it all for us
56 }
57 
58 /*
59  *  Sets the strings of the subwidgets using the current
60  *  language.
61  */
languageChange()62 void QG_DlgRotate::languageChange()
63 {
64     retranslateUi(this);
65 }
66 
init()67 void QG_DlgRotate::init() {
68     RS_SETTINGS->beginGroup("/Modify");
69     copies = RS_SETTINGS->readEntry("/RotateCopies", "10");
70     numberMode = RS_SETTINGS->readNumEntry("/RotateMode", 0);
71     angle = RS_SETTINGS->readEntry("/RotateAngle", "90.0");
72     useCurrentLayer =
73         (bool)RS_SETTINGS->readNumEntry("/RotateUseCurrentLayer", 0);
74     useCurrentAttributes =
75         (bool)RS_SETTINGS->readNumEntry("/RotateUseCurrentAttributes", 0);
76     RS_SETTINGS->endGroup();
77 
78     switch (numberMode) {
79     case 0:
80         rbMove->setChecked(true);
81         break;
82     case 1:
83         rbCopy->setChecked(true);
84         break;
85     case 2:
86         rbMultiCopy->setChecked(true);
87         break;
88     default:
89         break;
90     }
91     leNumber->setText(copies);
92     leAngle->setText(angle);
93     cbCurrentAttributes->setChecked(useCurrentAttributes);
94     cbCurrentLayer->setChecked(useCurrentLayer);
95 }
96 
destroy()97 void QG_DlgRotate::destroy() {
98     RS_SETTINGS->beginGroup("/Modify");
99     RS_SETTINGS->writeEntry("/RotateCopies", leNumber->text());
100     if (rbMove->isChecked()) {
101         numberMode = 0;
102     } else if (rbCopy->isChecked()) {
103         numberMode = 1;
104     } else {
105         numberMode = 2;
106     }
107     RS_SETTINGS->writeEntry("/RotateMode", numberMode);
108     RS_SETTINGS->writeEntry("/RotateAngle", leAngle->text());
109     RS_SETTINGS->writeEntry("/RotateUseCurrentLayer",
110                             (int)cbCurrentLayer->isChecked());
111     RS_SETTINGS->writeEntry("/RotateUseCurrentAttributes",
112                             (int)cbCurrentAttributes->isChecked());
113     RS_SETTINGS->endGroup();
114 }
115 
setData(RS_RotateData * d)116 void QG_DlgRotate::setData(RS_RotateData* d) {
117     data = d;
118     if( fabs(data->angle) > RS_TOLERANCE ) {
119         angle=QString::number(RS_Math::rad2deg(data->angle));
120     }
121     leAngle->setText(angle);
122 
123 }
124 
updateData()125 void QG_DlgRotate::updateData() {
126     if (rbMove->isChecked()) {
127         data->number = 0;
128     } else if (rbCopy->isChecked()) {
129         data->number = 1;
130     } else {
131         data->number = leNumber->text().toInt();
132     }
133     data->angle = RS_Math::deg2rad(RS_Math::eval(leAngle->text()));
134     data->useCurrentAttributes = cbCurrentAttributes->isChecked();
135     data->useCurrentLayer = cbCurrentLayer->isChecked();
136 }
137 
138