]> Shamusworld >> Repos - architektonas/blob - src/forms/circleoptions.cpp
348e3fe7569e96f6a2999a32991a2dbfd420f6a3
[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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/08/2010  Created this file. :-)
15 //
16
17 #include "circleoptions.h"
18
19 #include "rs.h"
20 #include "actioninterface.h"
21 #include "actiondrawcirclecr.h"
22 #include "settings.h"
23
24 CircleOptions::CircleOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
25         QWidget(parent, flags)
26 {
27         QHBoxLayout * layout = new QHBoxLayout(this);
28         layout->setContentsMargins(0, 0, 0, 0);
29
30         lRadius = new QLabel(tr("Radius:"));
31         leRadius = new QLineEdit(this);
32         leRadius->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
33
34         layout->addWidget(lRadius);
35         layout->addWidget(leRadius);
36
37         connect(leRadius, SIGNAL(textChanged(QString)), this, SLOT(updateRadius(QString)));
38
39         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
40         // nothing will show up on the screen. :-)
41         if (parent)
42                 parent->addWidget(this);
43 }
44
45 CircleOptions::~CircleOptions()
46 {
47         settings.beginGroup("Draw");
48         settings.setValue("CircleRadius", leRadius->text());
49         settings.endGroup();
50 }
51
52 void CircleOptions::setAction(ActionInterface * a, bool update)
53 {
54         if (a != NULL && a->rtti() == RS2::ActionDrawCircleCR)
55         {
56                 action = (ActionDrawCircleCR *)a;
57
58                 QString sr;
59
60                 if (update)
61                         sr = QString("%1").arg(action->getRadius());
62                 else
63                 {
64                         settings.beginGroup("Draw");
65                         sr = settings.value("CircleRadius", "1.0").toString();
66                         settings.endGroup();
67                         action->setRadius(sr.toDouble());
68                 }
69
70                 leRadius->setText(sr);
71         }
72         else
73         {
74                 RS_DEBUG->print(RS_Debug::D_ERROR,
75                         "CircleOptions::setAction: wrong action type");
76                 action = NULL;
77         }
78 }
79
80 void CircleOptions::updateRadius(const QString & r)
81 {
82         if (action != NULL)
83                 action->setRadius(RS_Math::eval(r));
84 }