]> Shamusworld >> Repos - architektonas/blob - src/forms/beveloptions.cpp
Sanity check stage II: rename classes...
[architektonas] / src / forms / beveloptions.cpp
1 // beveloptions.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 "beveloptions.h"
18
19 #include "rs.h"
20 #include "actioninterface.h"
21 #include "actionmodifybevel.h"
22 #include "rs_debug.h"
23 #include "settings.h"
24
25 BevelOptions::BevelOptions(QToolBar * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
26         QWidget(parent, flags),
27         cbTrim(new QCheckBox(tr("Trim"))),
28         lLength1(new QLabel(tr("Length 1:"))),
29         lLength2(new QLabel(tr("Length 2:"))),
30         leLength1(new QLineEdit(this)),
31         leLength2(new QLineEdit(this)),
32         sep1(new QFrame(this))
33 {
34         QHBoxLayout * layout = new QHBoxLayout(this);
35         layout->setContentsMargins(0, 0, 0, 0);
36
37         leLength1->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
38         leLength2->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Ignored));
39         sep1->setFrameShape(QFrame::VLine);
40         sep1->setFrameShadow(QFrame::Sunken);
41
42         layout->addWidget(cbTrim);
43         layout->addWidget(sep1);
44         layout->addWidget(lLength1);
45         layout->addWidget(leLength1);
46         layout->addWidget(lLength2);
47         layout->addWidget(leLength2);
48
49         connect(cbTrim, SIGNAL(toggled(bool)), this, SLOT(updateData()));
50         connect(leLength1, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
51         connect(leLength2, SIGNAL(textChanged(QString)), this, SLOT(updateData()));
52
53         // We need to add the widget (this thing) to the toolbar passed in. Otherwise,
54         // nothing will show up on the screen. :-)
55         if (parent)
56                 parent->addWidget(this);
57 }
58
59 BevelOptions::~BevelOptions()
60 {
61         settings.beginGroup("Modify");
62         settings.setValue("BevelLength1", leLength1->text());
63         settings.setValue("BevelLength2", leLength2->text());
64         settings.setValue("BevelTrim", cbTrim->isChecked());
65         settings.endGroup();
66 }
67
68 void BevelOptions::setAction(ActionInterface * a, bool update)
69 {
70         if (a != NULL && a->rtti() == RS2::ActionModifyBevel)
71         {
72                 action = (ActionModifyBevel *)a;
73
74                 QString sd1;
75                 QString sd2;
76                 bool st;
77
78                 if (update)
79                 {
80                         sd1 = QString("%1").arg(action->getLength1());
81                         sd2 = QString("%1").arg(action->getLength2());
82                         st = action->isTrimOn();
83                 }
84                 else
85                 {
86                         settings.beginGroup("Modify");
87                         sd1 = settings.value("BevelLength1", "1.0").toString();
88                         sd2 = settings.value("BevelLength2", "1.0").toString();
89                         st = settings.value("BevelTrim", true).toBool();
90                         settings.endGroup();
91                 }
92
93                 leLength1->setText(sd1);
94                 leLength2->setText(sd2);
95                 cbTrim->setChecked(st);
96         }
97         else
98         {
99                 RS_DEBUG->print(RS_Debug::D_ERROR, "BevelOptions::setAction: wrong action type");
100                 action = NULL;
101         }
102 }
103
104 void BevelOptions::updateData()
105 {
106         if (action != NULL)
107         {
108                 action->setTrim(cbTrim->isChecked());
109                 action->setLength1(RS_Math::eval(leLength1->text()));
110                 action->setLength2(RS_Math::eval(leLength2->text()));
111         }
112 }