]> Shamusworld >> Repos - architektonas/blob - src/forms/snapdistoptions.cpp
7355ace52ba8e84d632d8c4ed337f10b98b21997
[architektonas] / src / forms / snapdistoptions.cpp
1 // snapdistoptions.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/10/2010  Created this file. :-)
13 //
14
15 #include "snapdistoptions.h"
16
17 //#include "rs_actionmodifytrimamount.h"
18 //#include "rs_actioninterface.h"
19 //#include "rs_debug.h"
20 #include "rs_math.h"
21 #include "settings.h"
22
23 SnapDistOptions::SnapDistOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24         QWidget(parent, flags),
25         lDist(new QLabel(tr("Distance:"))),
26         leDist(new QLineEdit(this))
27 {
28         QHBoxLayout * layout = new QHBoxLayout(this);
29         layout->setContentsMargins(0, 0, 0, 0);
30
31         leDist->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
32
33         layout->addWidget(lDist);
34         layout->addWidget(leDist);
35
36         connect(leDist, SIGNAL(textChanged(QString)), this, SLOT(updateDist(QString)));
37
38         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
39         // nothing will show up on the screen. :-)
40         if (parent)
41                 parent->addWidget(this);
42 }
43
44 SnapDistOptions::~SnapDistOptions()
45 {
46         settings.beginGroup("Snap");
47         settings.setValue("Distance", leDist->text());
48         settings.endGroup();
49 }
50
51 void SnapDistOptions::setDist(double * d)
52 {
53         dist = d;
54
55         settings.beginGroup("Snap");
56         QString r = settings.value("Distance", "1.0").toString();
57         settings.endGroup();
58
59         leDist->setText(r);
60 }
61
62 void SnapDistOptions::updateDist(const QString & d)
63 {
64         if (dist != NULL)
65                 *dist = RS_Math::eval(d, 1.0);
66 }
67