]> Shamusworld >> Repos - architektonas/blob - src/forms/roundoptions.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / roundoptions.cpp
1 // roundoptions.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/10/2010  Created this file. :-)
15 //
16
17 #include "roundoptions.h"
18
19 #include "actionmodifyround.h"
20 #include "debug.h"
21 #include "settings.h"
22
23 RoundOptions::RoundOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
24         QWidget(parent, flags),
25         cbTrim(new QCheckBox(tr("Trim"))),
26         sep1(new QFrame(this)),
27         lRadius(new QLabel(tr("Radius:"))),
28         leRadius(new QLineEdit(this))
29 {
30         QHBoxLayout * layout = new QHBoxLayout(this);
31         layout->setContentsMargins(0, 0, 0, 0);
32
33         sep1->setFrameShape(QFrame::VLine);
34         sep1->setFrameShadow(QFrame::Sunken);
35         leRadius->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
36
37         layout->addWidget(cbTrim);
38         layout->addWidget(sep1);
39         layout->addWidget(lRadius);
40         layout->addWidget(leRadius);
41
42         connect(cbTrim, SIGNAL(toggled(bool)), this, SLOT(updateData()));
43         connect(leRadius, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
44
45         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
46         // nothing will show up on the screen. :-)
47         if (parent)
48                 parent->addWidget(this);
49 }
50
51 RoundOptions::~RoundOptions()
52 {
53         settings.beginGroup("Modify");
54         settings.setValue("RoundRadius", leRadius->text());
55         settings.setValue("RoundTrim", cbTrim->isChecked());
56         settings.endGroup();
57 }
58
59 void RoundOptions::setAction(ActionInterface * a, bool update)
60 {
61         if (a != NULL && a->rtti() == RS2::ActionModifyRound)
62         {
63                 action = (ActionModifyRound *)a;
64
65                 QString sr;
66                 bool st;
67
68                 if (update)
69                 {
70                         sr = QString("%1").arg(action->getRadius());
71                         st = action->isTrimOn();
72                 }
73                 else
74                 {
75                         settings.beginGroup("Modify");
76                         sr = settings.value("RoundRadius", "1.0").toString();
77                         st = settings.value("RoundTrim", true).toBool();
78                         settings.endGroup();
79                 }
80
81                 leRadius->setText(sr);
82                 cbTrim->setChecked(st);
83         }
84         else
85         {
86                 DEBUG->print(Debug::D_ERROR, "LineParallelOptions::setAction: wrong action type");
87                 action = NULL;
88         }
89 }
90
91 void RoundOptions::updateData()
92 {
93         if (action != NULL)
94         {
95                 action->setTrim(cbTrim->isChecked());
96                 action->setRadius(Math::eval(leRadius->text()));
97         }
98 }
99