1 /****************************************************************************
2 **
3 Construct option widget for equidistant points on entity
4
5 Copyright (C) 2011 Dongxu Li (dongxuli2011@gmail.com)
6 Copyright (C) 2011 R. van Twisk (librecad@rvt.dds.nl)
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 **********************************************************************/
22
23 #include "qg_snapmiddleoptions.h"
24
25 #include <QVariant>
26 #include "ui_qg_snapmiddleoptions.h"
27
28 /*
29 * Constructs a QG_SnapMiddleOptions as a child of 'parent'
30 * and widget flags set to 'f'.
31 *@i, number equidistant points, minimum 1, maximum 99
32 *
33 *@Author: Dongxu Li
34 */
QG_SnapMiddleOptions(int & i,QWidget * parent,Qt::WindowFlags fl)35 QG_SnapMiddleOptions::QG_SnapMiddleOptions(int& i, QWidget* parent, Qt::WindowFlags fl)
36 : QWidget(parent, fl)
37 , middlePoints(&i)
38 , ui(new Ui::Ui_SnapMiddleOptions{})
39 {
40 ui->setupUi(this);
41 }
42
43 /*
44 * Destroys the object and frees any allocated resources
45 */
~QG_SnapMiddleOptions()46 QG_SnapMiddleOptions::~QG_SnapMiddleOptions()
47 {
48 saveSettings();
49 }
50
51 /*
52 * Sets the strings of the subwidgets using the current
53 * language.
54 */
languageChange()55 void QG_SnapMiddleOptions::languageChange()
56 {
57 ui->retranslateUi(this);
58 }
59
saveSettings()60 void QG_SnapMiddleOptions::saveSettings() {
61 RS_SETTINGS->beginGroup("/Snap");
62 RS_SETTINGS->writeEntry("/MiddlePoints", *middlePoints);
63 RS_SETTINGS->endGroup();
64 }
65
setMiddlePoints(int & i,bool initial)66 void QG_SnapMiddleOptions::setMiddlePoints( int& i, bool initial) {
67 middlePoints = &i;
68 if (initial) {
69 RS_SETTINGS->beginGroup("/Snap");
70 *middlePoints=RS_SETTINGS->readNumEntry("/MiddlePoints", 1);
71 if( !(*middlePoints>=1 && *middlePoints<=99)) {
72 *middlePoints=1;
73 RS_SETTINGS->writeEntry("/MiddlePoints", 1);
74 }
75 ui->sbMiddlePoints->setValue(*middlePoints);
76 RS_SETTINGS->endGroup();
77 } else {
78 *middlePoints=ui->sbMiddlePoints->value();
79 }
80
81 }
82
updateMiddlePoints()83 void QG_SnapMiddleOptions::updateMiddlePoints() {
84 if (middlePoints) {
85 *middlePoints = ui->sbMiddlePoints->value();
86 }
87 }
88
on_sbMiddlePoints_valueChanged(int i)89 void QG_SnapMiddleOptions::on_sbMiddlePoints_valueChanged(int i)
90 {
91 if (middlePoints) {
92 *middlePoints = i;/*
93 RS_SETTINGS->beginGroup("/Snap");
94 RS_SETTINGS->writeEntry("/MiddlePoints", *middlePoints);
95 RS_SETTINGS->endGroup();*/
96 }
97 }
98 //EOF
99