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_splineoptions.h"
27 
28 #include "rs_actiondrawspline.h"
29 #include "lc_actiondrawsplinepoints.h"
30 #include "rs_settings.h"
31 #include "ui_qg_splineoptions.h"
32 #include "rs_debug.h"
33 
34 /*
35  *  Constructs a QG_SplineOptions as a child of 'parent', with the
36  *  name 'name' and widget flags set to 'f'.
37  */
QG_SplineOptions(QWidget * parent,Qt::WindowFlags fl)38 QG_SplineOptions::QG_SplineOptions(QWidget* parent, Qt::WindowFlags fl)
39     : QWidget(parent, fl)
40 	, action(nullptr)
41 	, ui(new Ui::Ui_SplineOptions{})
42 {
43 	ui->setupUi(this);
44 }
45 
46 /*
47  *  Destroys the object and frees any allocated resources
48  */
~QG_SplineOptions()49 QG_SplineOptions::~QG_SplineOptions()
50 {
51 	saveSettings();
52 }
53 
54 /*
55  *  Sets the strings of the subwidgets using the current
56  *  language.
57  */
languageChange()58 void QG_SplineOptions::languageChange()
59 {
60 	ui->retranslateUi(this);
61 }
62 
saveSettings()63 void QG_SplineOptions::saveSettings() {
64     RS_SETTINGS->beginGroup("/Draw");
65 	RS_SETTINGS->writeEntry("/SplineDegree", ui->cbDegree->currentText().toInt());
66 	RS_SETTINGS->writeEntry("/SplineClosed", (int)ui->cbClosed->isChecked());
67     RS_SETTINGS->endGroup();
68 }
69 
setAction(RS_ActionInterface * a,bool update)70 void QG_SplineOptions::setAction(RS_ActionInterface* a, bool update)
71 {
72     if (a->rtti()!=RS2::ActionDrawSpline && a->rtti()!=RS2::ActionDrawSplinePoints)
73     {
74         RS_DEBUG->print(RS_Debug::D_ERROR,
75                         "QG_SplineOptions::setAction: wrong action type");
76 		action = nullptr;
77         return;
78     }
79 
80     action = static_cast<RS_ActionDrawSpline*>(a);
81     int degree = 3;
82     bool closed;
83 
84     if (update)
85     {
86         if(a->rtti()==RS2::ActionDrawSpline)
87         {
88             degree = action->getDegree();
89         }
90         closed = action->isClosed();
91     }
92     else
93     {
94         RS_SETTINGS->beginGroup("/Draw");
95         if(a->rtti()==RS2::ActionDrawSpline)
96         {
97             degree = RS_SETTINGS->readNumEntry("/SplineDegree", 3);
98             action->setDegree(degree);
99         }
100         closed = RS_SETTINGS->readNumEntry("/SplineClosed", 0);
101         RS_SETTINGS->endGroup();
102         action->setClosed(closed);
103     }
104     if(a->rtti()==RS2::ActionDrawSpline)
105     {
106 		ui->cbDegree->setCurrentIndex(ui->cbDegree->findText(QString::number(degree)));
107 		ui->lDegree->show();
108 		ui->cbDegree->show();
109     }
110     else
111     {
112 		ui->lDegree->hide();
113 		ui->cbDegree->hide();
114     }
115 	ui->cbClosed->setChecked(closed);
116 }
117 
setClosed(bool c)118 void QG_SplineOptions::setClosed(bool c) {
119     if (action) action->setClosed(c);
120 }
121 
undo()122 void QG_SplineOptions::undo() {
123     if (action) action->undo();
124 }
125 
setDegree(const QString & deg)126 void QG_SplineOptions::setDegree(const QString& deg) {
127     if (action) {
128         action->setDegree(deg.toInt());
129     }
130 }
131