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