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