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