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