]> Shamusworld >> Repos - architektonas/blob - src/forms/circleoptions.cpp
Start of bringing back missing forms/dialogs
[architektonas] / src / forms / circleoptions.cpp
1 // circleoptions.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/08/2010  Created this file. :-)
13 //
14
15 #include "circleoptions.h"
16
17 #include "rs.h"
18 #include "rs_actioninterface.h"
19 #include "rs_actiondrawcirclecr.h"
20 #include "settings.h"
21
22 CircleOptions::CircleOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags)
24 {
25         QHBoxLayout * layout = new QHBoxLayout(this);
26         layout->setContentsMargins(0, 0, 0, 0);
27
28         lRadius = new QLabel(tr("Radius:"));
29         leRadius = new QLineEdit(this);
30         leRadius->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
31
32         layout->addWidget(lRadius);
33         layout->addWidget(leRadius);
34
35         connect(leRadius, SIGNAL(textChanged(QString)), this, SLOT(updateRadius(QString)));
36
37         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
38         // nothing will show up on the screen. :-)
39         if (parent)
40                 parent->addWidget(this);
41 }
42
43 CircleOptions::~CircleOptions()
44 {
45         settings.beginGroup("Draw");
46         settings.setValue("CircleRadius", leRadius->text());
47         settings.endGroup();
48 }
49
50 void CircleOptions::setAction(RS_ActionInterface * a, bool update)
51 {
52         if (a != NULL && a->rtti() == RS2::ActionDrawCircleCR)
53         {
54                 action = (RS_ActionDrawCircleCR *)a;
55
56                 QString sr;
57
58                 if (update)
59                         sr = QString("%1").arg(action->getRadius());
60                 else
61                 {
62                         settings.beginGroup("Draw");
63                         sr = settings.value("CircleRadius", "1.0").toString();
64                         settings.endGroup();
65                         action->setRadius(sr.toDouble());
66                 }
67
68                 leRadius->setText(sr);
69         }
70         else
71         {
72                 RS_DEBUG->print(RS_Debug::D_ERROR,
73                         "CircleOptions::setAction: wrong action type");
74                 action = NULL;
75         }
76 }
77
78 void CircleOptions::updateRadius(const QString & r)
79 {
80         if (action != NULL)
81                 action->setRadius(RS_Math::eval(r));
82 }